Melee Weapons: Code formatted for remaining melee weapons

No actual changes, just added spaces and brackets for improved readability
master
Mark 2018-03-20 21:13:45 +01:00
parent 69d6b2e8d2
commit 21102bb4ef
4 changed files with 300 additions and 266 deletions

View File

@ -21,7 +21,7 @@ local movement_effect;
func Hit(int x, int y)
{
StonyObjectHit(x,y);
StonyObjectHit(x, y);
return 1;
}
@ -57,61 +57,62 @@ public func HoldingEnabled()
public func ControlUseStart(object clonk, int iX, int iY)
{
/* Chopping */
// Find tree that is closest to the clonk's axe when swung
var x_offs = 10;
if(clonk->GetDir() == DIR_Left) {
if (clonk->GetDir() == DIR_Left)
{
x_offs = -x_offs;
}
if (clonk->IsWalking()) for (var tree in FindObjects(Find_AtPoint(x_offs,0), Find_Func("IsTree"), Sort_Distance(x_offs, 0), Find_NoContainer()))
{
//treedist - the x-distance the clonk is from the centre of a tree-trunk
var treedist = Abs(clonk->GetX() + x_offs - tree->GetX());
if(tree->IsStanding() && treedist <= 6)
{
using = 1;
//The clonk cannot hold other items in hand while swinging an axe
clonk->SetHandAction(1);
//Update the axe position in the clonk' hands and disable turning while he chops the tree
clonk->UpdateAttach();
clonk->SetTurnForced(clonk->GetDir());
//Make sure the clonk is holding the axe in the correct position
var hand = "Chop.R";
//treedist - the x-distance the clonk is from the centre of a tree-trunk
var treedist = Abs(clonk->GetX() + x_offs - tree->GetX());
if (tree->IsStanding() && treedist <= 6)
{
using = 1;
//The clonk cannot hold other items in hand while swinging an axe
clonk->SetHandAction(1);
//Update the axe position in the clonk' hands and disable turning while he chops the tree
clonk->UpdateAttach();
clonk->SetTurnForced(clonk->GetDir());
//Make sure the clonk is holding the axe in the correct position
var hand = "Chop.R";
if((clonk->GetDir() == 0) != (clonk.Plane < tree.Plane)) hand = "Chop.L";
swing_anim = clonk->PlayAnimation(hand, CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, clonk->GetAnimationLength(hand), SwingTime, ANIM_Loop), Anim_Const(1000));
//The timed effect for when the axe actually hits the tree
AddEffect("IntAxe", clonk, 1, 1, this, nil, tree);
return true;
}
if(! tree->IsStanding())
{
// Tree has already been felled
using = 1;
//The clonk cannot hold other items in hand while swinging an axe
clonk->SetHandAction(1);
//Refresh hands
clonk->UpdateAttach();
//Make sure the clonk is holding the axe in the correct position
var hand = "Chop.R";
//The timed effect for when the axe actually hits the tree
AddEffect("IntAxe", clonk, 1, 1, this, nil, tree);
return true;
}
if (!tree->IsStanding())
{
// Tree has already been felled
using = 1;
//The clonk cannot hold other items in hand while swinging an axe
clonk->SetHandAction(1);
//Refresh hands
clonk->UpdateAttach();
//Make sure the clonk is holding the axe in the correct position
var hand = "Chop.R";
if(clonk->GetDir() == 0) hand = "Chop.L";
swing_anim = clonk->PlayAnimation(hand, CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, clonk->GetAnimationLength("Chop.R"), SwingTime, ANIM_Loop), Anim_Const(1000));
//clonk cannot turn around to face the screen while chopping
clonk->SetTurnForced(clonk->GetDir());
//The timed effect for when the axe actually hits the tree
AddEffect("IntSplit", clonk, 1, 1, this, nil, tree);
return true;
//clonk cannot turn around to face the screen while chopping
clonk->SetTurnForced(clonk->GetDir());
//The timed effect for when the axe actually hits the tree
AddEffect("IntSplit", clonk, 1, 1, this, nil, tree);
return true;
}
}
}
// Do combat strike if no tree can be found.
return ControlUse(clonk, iX, iY);
}
@ -119,44 +120,47 @@ public func ControlUseStart(object clonk, int iX, int iY)
// Strike with the axe.
public func ControlUse(object clonk, int iX, int iY)
{
if(!CanStrikeWithWeapon(clonk) || !clonk->HasHandAction())
if (!CanStrikeWithWeapon(clonk) || !clonk->HasHandAction())
{
clonk->PauseUse(this, "ReadyToBeUsed", {clonk = clonk});
return true;
}
var rand = Random(2)+1;
var rand = Random(2) + 1;
var arm = "R";
var animation = Format("SwordSlash%d.%s", rand, arm);
carry_bone = "pos_hand2";
if(clonk->IsWalking())
if (clonk->IsWalking())
{
if(!GetEffect("AxeStrikeStop", clonk, 0))
if (!GetEffect("AxeStrikeStop", clonk, 0))
AddEffect("AxeStrikeStop", clonk, 2, StrikingLength, this);
}
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 1)
if (clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 1)
{
arm = "L";
carry_bone = "pos_hand1";
animation = Format("SwordSlash%d.%s", rand, arm);
animation = Format("SwordSlash%d.%s", rand, arm);
}
if(clonk->IsJumping())
if (clonk->IsJumping())
{
rand = 1;
if(clonk->GetYDir() < -5) rand = 2;
animation = Format("SwordJump%d.%s",rand,arm);
if (clonk->GetYDir() < -5)
{
rand = 2;
}
animation = Format("SwordJump%d.%s", rand, arm);
}
PlayWeaponAnimation(clonk, animation, 10, Anim_Linear(0, 0, clonk->GetAnimationLength(animation), StrikingLength, ANIM_Remove), Anim_Const(1000));
clonk->UpdateAttach();
Sound("Objects::Weapons::WeaponSwing?", {pitch = -Random(10)});
magic_number=((magic_number+1)%10) + (ObjectNumber()*10);
magic_number = ((magic_number + 1) % 10) + (ObjectNumber() * 10);
StartWeaponHitCheckEffect(clonk, StrikingLength, 1);
return true;
}
@ -217,13 +221,14 @@ func FxIntAxeTimer(object clonk, effect, int time)
if (!clonk->IsWalking()) return -1;
//This block is executed when the axe hits the tree
if((time + 25) % SwingTime == 1)
if ((time + 25) % SwingTime == 1)
{
Sound("Environment::Tree::Chop?");
//Which direction does the clonk face?
var x = 10;
if(clonk->GetDirection() == COMD_Left) x = x * -1;
if (clonk->GetDirection() == COMD_Left)
x = x * -1;
//Create the woodchip particles
var particles = Particles_WoodChip();
@ -232,7 +237,7 @@ func FxIntAxeTimer(object clonk, effect, int time)
particles = {Prototype = Particles_WoodChip(), Attach = ATTACH_Back};
clonk->CreateParticle("WoodChip", x, 4, PV_Random(-12, 12), PV_Random(-13, -6), PV_Random(36 * 3, 36 * 10), particles, 10);
// Damage tree
effect.tree->DoDamage(this.ChopStrength, FX_Call_DmgChop, clonk->GetOwner());
effect.tree->DoDamage(this.ChopStrength, FX_Call_DmgChop, clonk->GetOwner());
}
//Make sure the clonk does not move
clonk->SetComDir(COMD_Stop);
@ -267,7 +272,7 @@ func FxIntSplitTimer(object clonk, effect, int time)
if ((time + 25) % SwingTime == 1)
{
Sound("Environment::Tree::Chop?");
//Which direction does the clonk face?
var x = 10;
if(clonk->GetDirection() == COMD_Left) x = x * -1;
@ -296,16 +301,17 @@ func FxIntSplitStop(object clonk, effect, int temp)
func CheckStrike(iTime)
{
var offset_x=7;
var offset_y=0;
var offset_x = 7;
var offset_y = 0;
if(Contained()->GetDir() == DIR_Left) offset_x*=-1;
if(!(Contained()->GetContact(-1) & CNAT_Bottom))
offset_y=10;
var width=10;
var height=20;
if (!(Contained()->GetContact(-1) & CNAT_Bottom))
offset_y = 10;
var width = 10;
var height = 20;
for(var obj in FindObjects(Find_AtRect(offset_x - width/2, offset_y - height/2, width, height),
Find_NoContainer(),
Find_Exclude(Contained()),
@ -313,35 +319,35 @@ func CheckStrike(iTime)
{
if (obj->~IsProjectileTarget(this, Contained()))
{
var effect_name=Format("HasBeenHitByAxeEffect%d", magic_number);
var axe_name=Format("HasBeenHitByAxe%d", this->ObjectNumber());
var first=true;
var effect_name = Format("HasBeenHitByAxeEffect%d", magic_number);
var axe_name = Format("HasBeenHitByAxe%d", this->ObjectNumber());
var first = true;
// don't hit objects twice
if(!GetEffect(effect_name, obj))
if (!GetEffect(effect_name, obj))
{
AddEffect(effect_name, obj, 1, 60 /* arbitrary */);
if(GetEffect(axe_name, obj))
AddEffect(effect_name, obj, 1, 60);
if (GetEffect(axe_name, obj))
{
first=false;
first = false;
}
else
{
AddEffect(axe_name, obj, 1, 40);
}
// Reduce damage by shield
var shield=ApplyShieldFactor(Contained(), obj, 0); // damage out of scope?
if(shield == 100)
var shield = ApplyShieldFactor(Contained(), obj, 0); // damage out of scope?
if (shield == 100)
continue;
// fixed damage (3)
var damage = ((100-shield) * this.WeaponStrength * 1000 / 100);
var damage = (100 - shield) * this.WeaponStrength * 1000 / 100;
WeaponDamage(obj, damage, FX_Call_EngGetPunched, true);
if (obj)
DoWeaponSlow(obj, 200);
// sound and done. We can only hit one target
Sound("Objects::Weapons::WeaponHit?", false);
break;
@ -352,7 +358,7 @@ func CheckStrike(iTime)
func WeaponStrikeExpired()
{
if(GetEffect("AxeStrikeStop", Contained()))
if (GetEffect("AxeStrikeStop", Contained()))
RemoveEffect("AxeStrikeStop", Contained());
}
@ -365,12 +371,13 @@ func OnWeaponHitCheckStop(clonk)
func FxAxeStrikeStopStart(pTarget, effect, iTemp)
{
if(iTemp) return;
pTarget->PushActionSpeed("Walk", (pTarget.ActMap.Walk.Speed)/100);
pTarget->PushActionSpeed("Walk", (pTarget.ActMap.Walk.Speed) / 100);
}
func FxAxeStrikeStopStop(pTarget, effect, iCause, iTemp)
{
if(iTemp) return;
return;
pTarget->PopActionSpeed("Walk");
movement_effect = nil;
}
@ -400,18 +407,18 @@ public func GetCarryTransform(object clonk, bool idle)
if (idle) return;
var act = clonk->GetAction();
if(act != "Walk" && act != "Jump")
return Trans_Mul(Trans_Translate(4500,0,0), Trans_Rotate(90,1,0,0), Trans_Rotate(180,0,1,0) );
if (act != "Walk" && act != "Jump")
return Trans_Mul(Trans_Translate(4500, 0, 0), Trans_Rotate(90, 1, 0, 0), Trans_Rotate(180, 0, 1, 0));
return Trans_Rotate(-90, 1, 0, 0);
}
public func GetCarrySpecial(clonk)
{
if(using == 1)
if (using == 1)
{
if(clonk->GetDir() == 1)
if (clonk->GetDir() == 1)
return "pos_hand2";
else
return "pos_hand1";
@ -435,4 +442,4 @@ local WeaponStrength = 6;
// When using the axe to chop a tree.
local SwingTime = 30;
// When using the axe as a weapon (without trees).
local StrikingLength = 20; // in frames
local StrikingLength = 20; // in frames

View File

@ -1,5 +1,6 @@
/**
Club
Simple striking weapon.
*/
@ -24,18 +25,18 @@ func Hit()
func ClubChangeHandAnims(string hand)
{
if(hand == "R")
if (hand == "R")
{
//Changes which (R/L) animation is used
animation_set = {
AimMode = AIM_Weight,
AnimationAim = Format("BatAimArms.R",hand),
AnimationAim2 = Format("BatAim2Arms.R",hand),
AimTime = 35*3,
AimTime = 35 * 3,
AnimationShoot = Format("BatStrikeArms.R",hand),
AnimationShoot2 = Format("BatStrike2Arms.R",hand),
ShootTime = 35/2,
ShootTime2 = (35/2)*6/19, // At 6/19 of the shooting animation
ShootTime = 35 / 2,
ShootTime2 = (35 / 2) * 6 / 19, // At 6/19 of the shooting animation
};
}
else
@ -45,11 +46,11 @@ func ClubChangeHandAnims(string hand)
AimMode = AIM_Weight,
AnimationAim = "BatAimArms.L",
AnimationAim2 = "BatAim2Arms.L",
AimTime = 35*3,
AimTime = 35 * 3,
AnimationShoot = "BatStrikeArms.L",
AnimationShoot2 = "BatStrike2Arms.L",
ShootTime = 35/2,
ShootTime2 = (35/2)*6/19, // At 6/19 of the shooting animation
ShootTime = 35 / 2,
ShootTime2 = (35 / 2)* 6 / 19, // At 6/19 of the shooting animation
};
}
}
@ -92,7 +93,7 @@ public func RejectUse(object clonk)
public func ControlUseStart(object clonk, int x, int y)
{
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 0)
if (clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 0)
ClubChangeHandAnims("R");
else
ClubChangeHandAnims("L");
@ -105,8 +106,8 @@ public func ControlUseStart(object clonk, int x, int y)
public func ControlUseHolding(object clonk, ix, iy)
{
var angle = Angle(0,0,ix,iy);
angle = Normalize(angle,-180);
var angle = Angle(0, 0, ix, iy);
angle = Normalize(angle, -180);
clonk->SetAimPosition(angle);
@ -132,20 +133,20 @@ public func Reset(clonk)
func FxDuringClubShootControlStart(target, effect, temp, p1)
{
if(temp) return;
effect.angle=p1;
if (temp) return;
effect.angle = p1;
}
func FxDuringClubShootControlStop(target, effect, reason, temp)
{
if(temp) return;
if (temp) return;
AddEffect("AfterClubShootControl", target, 1, 15, this);
}
func FxDuringClubShootControlTimer(target, effect, effect_time)
{
if(effect_time > 16) return -1;
if(!this) return -1;
if (effect_time > 16) return -1;
if (!this) return -1;
this->DoStrike(target, effect.angle);
}
@ -153,8 +154,8 @@ func FxDuringClubShootControlTimer(target, effect, effect_time)
func FxDuringClubShootControlQueryCatchBlow(object target, effect, object obj)
{
this->DoStrike(target, effect.angle);
var en=Format("CannotBeHitTwiceBy%d", this->ObjectNumber());
if(GetEffect(en, obj)) return true;
var en = Format("CannotBeHitTwiceBy%d", this->ObjectNumber());
if (GetEffect(en, obj)) return true;
return false;
}
@ -165,8 +166,8 @@ func FxAfterClubShootControlTimer()
func FxAfterClubShootControlQueryCatchBlow(object target, effect, object obj)
{
var en=Format("CannotBeHitTwiceBy%d", this->ObjectNumber());
if(GetEffect(en, obj)) return true;
var en = Format("CannotBeHitTwiceBy%d", this->ObjectNumber());
if (GetEffect(en, obj)) return true;
return false;
}
@ -198,7 +199,7 @@ func DoStrike(clonk, angle)
{
if (obj->Stuck()) continue;
var div = ClubVelocityPrecision();
if(obj->GetContact(-1)) div*=10;
if (obj->GetContact(-1)) div*=10;
// the better you hit, the more power you have
var precision = BoundBy(Distance(obj->GetX(), obj->GetY(), GetX() + x, GetY() + y), 1, 15);
@ -219,7 +220,7 @@ func DoStrike(clonk, angle)
}
AddEffect(already_hit_effect_name, obj, 1, 15, nil);
found=true;
found = true;
break;
}
@ -232,7 +233,7 @@ func DoStrike(clonk, angle)
func ClubDamage()
{
return 5*1000;
return 5 * 1000;
}
func ClubVelocityPrecision()
@ -257,9 +258,9 @@ public func GetCarryMode(object clonk, bool idle, bool nohand)
public func GetCarrySpecial(clonk)
{
if(fAiming)
if (fAiming)
{
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 1)
if (clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 1)
return "pos_hand1";
else
return "pos_hand2";
@ -276,7 +277,7 @@ public func GetCarryTransform(object clonk, bool idle, bool nohand)
func Definition(def)
{
def.PictureTransformation = Trans_Mul(Trans_Translate(-4500, -2000, 2000), Trans_Rotate(45,0,0,1));
def.PictureTransformation = Trans_Mul(Trans_Translate(-4500, -2000, 2000), Trans_Rotate(45, 0, 0, 1));
}
/*-- Properties --*/
@ -287,4 +288,4 @@ local Collectible = true;
local ForceFreeHands = true;
local Components = {Wood = 1, Metal = 1};
local BlastIncinerate = 30;
local MaterialIncinerate = true;
local MaterialIncinerate = true;

View File

@ -30,12 +30,13 @@ func Entrance(object container)
public func HitByWeapon(by, iDamage)
{
var object_angle = Angle(GetX(),GetY(),by->GetX(), by->GetY());
var object_angle = Angle(GetX(), GetY(), by->GetX(), by->GetY());
var shield_angle = iAngle;
// angle difference: 0..180
var angle_diff = Abs(Normalize(shield_angle-object_angle,-180));
if (angle_diff > 45) return 0;
var angle_diff = Abs(Normalize(shield_angle - object_angle, -180));
if (angle_diff > 45)
return 0;
Sound("Objects::Weapons::Shield::MetalHit?");
// bash him hard!
@ -60,7 +61,7 @@ public func RejectUse(object clonk)
public func ControlUseStart(object clonk, int x, int y)
{
StartUsage(clonk);
UpdateShieldAngle(clonk, x,y);
UpdateShieldAngle(clonk, x, y);
return true;
}
@ -72,7 +73,7 @@ public func ControlUseHolding(object clonk, int x, int y)
public func ControlUseCancel(object clonk)
{
EndUsage(clonk);
if(GetEffect("IntShieldSuspend", clonk))
if (GetEffect("IntShieldSuspend", clonk))
RemoveEffect("IntShieldSuspend", clonk);
}
@ -85,7 +86,7 @@ func StartUsage(object clonk)
{
var hand;
// which animation to use? (which hand)
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 0)
if (clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 0)
{
carry_bone = "pos_hand2";
hand = "ShieldArms.R";
@ -99,11 +100,11 @@ func StartUsage(object clonk)
aim_anim = clonk->PlayAnimation(hand, CLONK_ANIM_SLOT_Arms, Anim_Const(clonk->GetAnimationLength(hand)/2), Anim_Const(1000));
var handLR;
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 0)
if (clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 0)
handLR = "R";
else
handLR = "L";
clonk->UpdateAttach();
clonk->ReplaceAction("Stand", [Format("ShieldStandUp.%s",handLR), Format("ShieldStandDown.%s",handLR), 500]);
clonk->ReplaceAction("Walk", [Format("ShieldWalkUp.%s",handLR), Format("ShieldWalkDown.%s",handLR), 500]);
@ -111,7 +112,7 @@ func StartUsage(object clonk)
StartWeaponHitCheckEffect(clonk, -1, 1);
if(!GetEffect("ShieldStopControl", clonk))
if (!GetEffect("ShieldStopControl", clonk))
AddEffect("ShieldStopControl", clonk, 2, 5, this);
clonk->SetTurnType(1, 1);
@ -124,13 +125,13 @@ func EndUsage(object clonk)
iAngle = 0;
clonk->StopAnimation(clonk->GetRootAnimation(10));
clonk->UpdateAttach();
clonk->ReplaceAction("Stand", nil);
clonk->ReplaceAction("Walk", nil);
clonk->ReplaceAction("Run", nil);
clonk->ReplaceAction("Walk", nil);
clonk->ReplaceAction("Run", nil);
AdjustSolidMaskHelper();
if(GetEffect("ShieldStopControl", clonk))
if (GetEffect("ShieldStopControl", clonk))
RemoveEffect("ShieldStopControl", clonk);
clonk->SetTurnForced(-1);
@ -141,16 +142,17 @@ func EndUsage(object clonk)
func UpdateShieldAngle(object clonk, int x, int y)
{
var angle=Normalize(Angle(0,0, x,y),-180);
angle=BoundBy(angle,-150,150);
var angle = Normalize(Angle(0, 0, x, y), -180);
angle = BoundBy(angle, -150, 150);
iAngle = angle;
var weight = 0;
if( Abs(angle) > 90) weight = 1000*( Abs(angle)-60 )/90;
if (Abs(angle) > 90)
weight = 1000 * (Abs(angle) - 60) / 90;
var handLR;
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 0)
if (clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 0)
handLR = "R";
else
handLR = "L";
@ -162,7 +164,7 @@ func UpdateShieldAngle(object clonk, int x, int y)
if(angle > 0) clonk->SetTurnForced(DIR_Right);
else clonk->SetTurnForced(DIR_Left);
clonk->SetAnimationPosition(aim_anim, Anim_Const(Abs(angle) * 11111/1000));
clonk->SetAnimationPosition(aim_anim, Anim_Const(Abs(angle) * 11111 / 1000));
AdjustSolidMaskHelper();
}
@ -170,30 +172,33 @@ func UpdateShieldAngle(object clonk, int x, int y)
// if the shield is held up, it has a solid mask on which other clonks can climb onto
func AdjustSolidMaskHelper()
{
if(aim_anim && Contained() && Abs(iAngle) <= 20)
if (aim_anim && Contained() && Abs(iAngle) <= 20)
{
if(!solid_mask_helper)
if (!solid_mask_helper)
{
solid_mask_helper=CreateObjectAbove(Shield_SolidMask, 0, 0, NO_OWNER);
solid_mask_helper = CreateObjectAbove(Shield_SolidMask, 0, 0, NO_OWNER);
solid_mask_helper->SetAction("Attach", Contained());
}
}
else
{
if(solid_mask_helper) return solid_mask_helper->RemoveObject();
else return;
if (solid_mask_helper)
return solid_mask_helper->RemoveObject();
else
return;
}
var angle=BoundBy(iAngle, -115, 115);
var angle = BoundBy(iAngle, -115, 115);
solid_mask_helper->SetR(angle - 90);
var distance=8;
var y_adjust=-5;
var x_adjust=1;
if(Contained()->GetDir() == DIR_Left) x_adjust=-1;
var x=Sin(angle, distance) + x_adjust;
var y=-Cos(angle, distance) + y_adjust;
var distance = 8;
var y_adjust = -5;
var x_adjust = 1;
if (Contained()->GetDir() == DIR_Left)
x_adjust = -1;
var x = Sin(angle, distance) + x_adjust;
var y = -Cos(angle, distance) + y_adjust;
solid_mask_helper->SetVertexXY(0, -x, -y);
}
@ -212,7 +217,7 @@ func FxShieldStopControlStop(object target, effect, iCause, temp)
func FxShieldStopControlTimer(object target, effect)
{
// suspend usage if not walking
if(!target->IsWalking())
if (!target->IsWalking())
{
target->PauseUse(this);
return -1;
@ -222,31 +227,33 @@ func FxShieldStopControlTimer(object target, effect)
func FxShieldStopControlQueryCatchBlow(object target, effect, object obj)
{
if (obj->GetOCF() & OCF_Alive) return false;
if (obj->GetOCF() & OCF_Alive)
return false;
// angle of shield
var shield_angle = iAngle;
// angle of object
var object_angle;
if(obj->GetXDir() || obj->GetYDir())
object_angle = Angle(obj->GetXDir(), obj->GetYDir(),0,0);
if (obj->GetXDir() || obj->GetYDir())
object_angle = Angle(obj->GetXDir(), obj->GetYDir(), 0, 0);
else
object_angle = Angle(GetX(),GetY(),obj->GetX(), obj->GetY());
object_angle = Angle(GetX(), GetY(), obj->GetX(), obj->GetY());
// angle difference: 0..180
var angle_diff = Abs(Normalize(shield_angle-object_angle,-180));
var angle_diff = Abs(Normalize(shield_angle - object_angle, -180));
// objects hits if the angle difference is greater than 45 degrees
if (angle_diff > 45) return false;
if (angle_diff > 45)
return false;
// projectile bounces off
var sxd=Sin(shield_angle, 15);
var syd=-Cos(shield_angle, 15);
var xd=obj->GetXDir();
var yd=obj->GetYDir();
obj->SetXDir(-xd/3 + sxd);
obj->SetYDir(-yd/3 + syd);
var sxd = Sin(shield_angle, 15);
var syd = -Cos(shield_angle, 15);
var xd = obj->GetXDir();
var yd = obj->GetYDir();
obj->SetXDir(-xd / 3 + sxd);
obj->SetYDir(-yd / 3 + syd);
// dont collect blocked objects
AddEffect("NoCollection", obj, 1, 30);
@ -267,18 +274,22 @@ public func GetCarryMode() { return CARRY_HandBack; }
public func GetCarrySpecial(clonk) { return carry_bone; }
public func GetCarryTransform(clonk, sec, back)
{
if(aim_anim && !sec) return Trans_Mul(Trans_Rotate(180,0,1,0),Trans_Rotate(90,0,1,0));
if(aim_anim && sec) return Trans_Mul(Trans_Rotate(180,0,0,1), Trans_Rotate(90,0,1,1));
if(mTrans != nil) return mTrans;
if(!sec)
if (aim_anim && !sec)
return Trans_Mul(Trans_Rotate(180, 0, 1, 0), Trans_Rotate(90, 0, 1, 0));
if (aim_anim && sec)
return Trans_Mul(Trans_Rotate(180, 0, 0, 1), Trans_Rotate(90, 0, 1, 1));
if (mTrans != nil)
return mTrans;
if (!sec)
{
if(back) return Trans_Mul(Trans_Rotate(-90, 0, 1, 0),Trans_Translate(0,-400,0));
if (back)
return Trans_Mul(Trans_Rotate(-90, 0, 1, 0), Trans_Translate(0, -400, 0));
return nil;
}
if(back) return Trans_Mul(Trans_Mul(Trans_Rotate(90, 0, 1, 0),Trans_Rotate(180, 1, 0, 0)),Trans_Translate(0,-400,1000));
return Trans_Rotate(180,0,0,1);
return Trans_Rotate(180, 0, 0, 1);
}
func Definition(def)
@ -292,3 +303,4 @@ local Name = "$Name$";
local Description = "$Description$";
local Collectible = true;
local Components = {Wood = 1, Metal = 1};

View File

@ -40,16 +40,16 @@ public func OnWeaponHitCheckStop(clonk)
{
carry_bone = nil;
clonk->UpdateAttach();
if(GetEffect("SwordStrikeSpeedUp", clonk))
if (GetEffect("SwordStrikeSpeedUp", clonk))
RemoveEffect("SwordStrikeSpeedUp", clonk);
if(clonk->IsJumping())
if (clonk->IsJumping())
{
if(!GetEffect("Fall", clonk))
AddEffect("Fall",clonk,1,1,clonk);
if (!GetEffect("Fall", clonk))
AddEffect("Fall", clonk, 1, 1, clonk);
}
if(GetEffect("SwordStrikeStop", clonk))
if (GetEffect("SwordStrikeStop", clonk))
RemoveEffect("SwordStrikeStop", clonk);
return;
@ -63,70 +63,75 @@ public func RejectUse(object clonk)
}
public func ControlUse(object clonk, int x, int y)
{
var slow=GetEffect("SwordStrikeSlow", clonk);
{
var slow = GetEffect("SwordStrikeSlow", clonk);
var arm = "R";
carry_bone = "pos_hand2";
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 1)
if (clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 1)
{
arm = "L";
carry_bone = "pos_hand1";
}
var rand = Random(2)+1;
var rand = Random(2) + 1;
var animation = Format("SwordSlash%d.%s", rand, arm);
var animation_sword = Format("Strike%d", rand);
var downwards_stab = false;
// figure out the kind of attack to use
var length = Sword_Standard_StrikingLength;
if(clonk->IsWalking())
if (clonk->IsWalking())
{
if(!GetEffect("SwordStrikeStop", clonk))
if (!GetEffect("SwordStrikeStop", clonk))
movement_effect = AddEffect("SwordStrikeStop", clonk, 2, length, this);
}
else
if(clonk->IsJumping())
else if (clonk->IsJumping())
{
rand = 1;
if(clonk->GetYDir() < -5) rand = 2;
animation = Format("SwordJump%d.%s",rand,arm);
if (clonk->GetYDir() < -5)
{
rand = 2;
}
animation = Format("SwordJump%d.%s", rand, arm);
if(!slow && !GetEffect("DelayTranslateVelocity", clonk))
if (!slow && !GetEffect("DelayTranslateVelocity", clonk))
{
// check whether the player aims below the Clonk
var a=Angle(0, 0, x,y);
var a = Angle(0, 0, x, y);
var x_dir = Sin(a, 60);
if(Inside(a, 35+90, 35+180)) // the player aims downwards
if((BoundBy(x_dir, -1, 1) == BoundBy(clonk->GetXDir(), -1, 1)) || (clonk->GetXDir() == 0)) // the player aims into the direction the Clonk is already jumping
{
clonk->SetXDir(x_dir);
clonk->SetYDir(-Cos(a, 60));
AddEffect("DelayTranslateVelocity", clonk, 2, 3, nil, Library_MeleeWeapon);
// modified animation
length = 50;
animation = Format("SwordSlash1.%s", arm);
downwards_stab = true;
if(GetEffect("Fall", clonk)) RemoveEffect("Fall", clonk);
// visual effect
AddEffect("VisualJumpStrike", clonk, 1, 2, nil, Sword);
}
if (Inside(a, 35 + 90, 35 + 180))
// the player aims downwards
if ((BoundBy(x_dir, -1, 1) == BoundBy(clonk->GetXDir(), -1, 1)) || (clonk->GetXDir() == 0))
// the player aims into the direction the Clonk is already jumping
{
clonk->SetXDir(x_dir);
clonk->SetYDir(-Cos(a, 60));
AddEffect("DelayTranslateVelocity", clonk, 2, 3, nil, Library_MeleeWeapon);
// modified animation
length = 50;
animation = Format("SwordSlash1.%s", arm);
downwards_stab = true;
if (GetEffect("Fall", clonk))
RemoveEffect("Fall", clonk);
// visual effect
AddEffect("VisualJumpStrike", clonk, 1, 2, nil, Sword);
}
}
}
if(!downwards_stab)
if (!downwards_stab)
{
PlayWeaponAnimation(clonk, animation, 10, Anim_Linear(0, 0, clonk->GetAnimationLength(animation), length, ANIM_Remove), Anim_Const(1000));
PlayAnimation(animation_sword, 10, Anim_Linear(0, 0, GetAnimationLength(animation_sword), length, ANIM_Remove), Anim_Const(1000));
}
else
{
PlayWeaponAnimation(clonk, animation, 10, Anim_Linear(0, 0, (clonk->GetAnimationLength(animation)*3)/4, 5, ANIM_Hold), Anim_Const(1000));
PlayAnimation(animation_sword, 10, Anim_Linear(GetAnimationLength(animation_sword)/2, 0, GetAnimationLength(animation_sword), length, ANIM_Remove), Anim_Const(1000));
PlayWeaponAnimation(clonk, animation, 10, Anim_Linear(0, 0, (clonk->GetAnimationLength(animation) * 3) / 4, 5, ANIM_Hold), Anim_Const(1000));
PlayAnimation(animation_sword, 10, Anim_Linear(GetAnimationLength(animation_sword) / 2, 0, GetAnimationLength(animation_sword), length, ANIM_Remove), Anim_Const(1000));
}
clonk->UpdateAttach();
@ -144,14 +149,17 @@ func FxVisualJumpStrikeStart(target, effect, temp)
{
if(temp) return;
effect.x_add = 20;
if(target->GetXDir() < 0) effect.x_add *= -1;
if (target->GetXDir() < 0)
{
effect.x_add *= -1;
}
effect.visual = CreateObjectAbove(Sword_JumpEffect, 0, 0, nil);
effect.visual->Point({x = target->GetX() + effect.x_add, y = target->GetY() + 10}, {x = target->GetX() + effect.x_add, y = target->GetY() + 10});
}
func FxVisualJumpStrikeTimer(target, effect, time)
{
if(!target->~IsJumping())
if (!target->~IsJumping())
{
effect.visual->FadeOut();
effect.visual = nil;
@ -169,31 +177,36 @@ func FxVisualJumpStrikeStop(target, effect, reason, temp)
func SwordDamage(int shield)
{
return ((100-shield)*9*1000 / 100);
return (100 - shield) * 9 * 1000 / 100;
}
func CheckStrike(iTime)
{
//if(iTime < 20) return;
var offset_x=7;
var offset_y=0;
if(Contained()->GetDir() == DIR_Left) offset_x*=-1;
var offset_x = 7;
var offset_y = 0;
if (Contained()->GetDir() == DIR_Left)
offset_x *= -1;
if(!(Contained()->GetContact(-1) & CNAT_Bottom))
offset_y=10;
if (!(Contained()->GetContact(-1) & CNAT_Bottom))
offset_y = 10;
var width=15;
var height=20;
var angle=0;
var width = 15;
var height = 20;
var angle = 0;
var doBash=Abs(Contained()->GetXDir()) > 5 || Abs(Contained()->GetYDir()) > 5;
if(!doBash) doBash=Contained()->GetContact(-1) & CNAT_Bottom;
if(doBash)
var doBash = Abs(Contained()->GetXDir()) > 5 || Abs(Contained()->GetYDir()) > 5;
if (!doBash)
{
if(Contained()->GetDir() == DIR_Left)
angle=-(Max(5, Abs(Contained()->GetXDir())));
else angle=(Max(5, Abs(Contained()->GetXDir())));
doBash = Contained()->GetContact(-1) & CNAT_Bottom;
}
if (doBash)
{
if (Contained()->GetDir() == DIR_Left)
angle = -(Max(5, Abs(Contained()->GetXDir())));
else
angle = (Max(5, Abs(Contained()->GetXDir())));
}
for(var obj in FindObjects(Find_AtRect(offset_x - width/2, offset_y - height/2, width, height),
@ -203,31 +216,31 @@ func CheckStrike(iTime)
{
if (obj->~IsProjectileTarget(this, Contained()))
{
var effect_name=Format("HasBeenHitBySwordEffect%d", magic_number);
var sword_name=Format("HasBeenHitBySword%d", this->ObjectNumber());
var first=true;
var effect_name = Format("HasBeenHitBySwordEffect%d", magic_number);
var sword_name = Format("HasBeenHitBySword%d", this->ObjectNumber());
var first = true;
// don't hit objects twice
if(!GetEffect(effect_name, obj))
if (!GetEffect(effect_name, obj))
{
AddEffect(effect_name, obj, 1, Sword_Standard_StrikingLength);
if(GetEffect(sword_name, obj))
if (GetEffect(sword_name, obj))
{
//Log("successive hit");
first=false;
first = false;
}
else
{
//Log("first hit overall");
AddEffect(sword_name, obj, 1, 40);
}
// Reduce damage by shield
var shield=ApplyShieldFactor(Contained(), obj, 0); // damage out of scope?
if(shield == 100)
var shield = ApplyShieldFactor(Contained(), obj, 0); // damage out of scope?
if (shield == 100)
continue;
// Sound before damage to prevent null pointer access if callbacks delete this
Sound("Objects::Weapons::WeaponHit?", false);
@ -236,16 +249,14 @@ func CheckStrike(iTime)
WeaponDamage(obj, damage, FX_Call_EngGetPunched, true);
// object has not been deleted?
if(obj)
if (obj)
{
if(offset_y)
if (offset_y)
ApplyWeaponBash(obj, 100, 0);
else
if(!first)
ApplyWeaponBash(obj, damage/50, Angle(0, 0, angle, -10));
else
if(!offset_y)
DoWeaponSlow(obj, 300);
else if (!first)
ApplyWeaponBash(obj, damage / 50, Angle(0, 0, angle, -10));
else if (!offset_y)
DoWeaponSlow(obj, 300);
// Particle effect
var particle =
@ -255,12 +266,12 @@ func CheckStrike(iTime)
Attach = ATTACH_Front | ATTACH_MoveRelative,
Phase = PV_Linear(0, 3)
};
if(Contained()->GetDir() == DIR_Left)
if (Contained()->GetDir() == DIR_Left)
{
particle.Phase = PV_Linear(4, 7);
}
obj->CreateParticle("SwordSlice", RandomX(-1,1), RandomX(-1,1), 0, 0, 6, particle);
}
obj->CreateParticle("SwordSlice", RandomX(-1, 1), RandomX(-1, 1), 0, 0, 6, particle);
}
// and done. We can only hit one target
@ -268,20 +279,20 @@ func CheckStrike(iTime)
}
}
}
}
func FxSwordStrikeStopStart(pTarget, effect, iTemp)
{
if(iTemp) return;
pTarget->PushActionSpeed("Walk", (pTarget.ActMap.Walk.Speed)/100);
pTarget->PushActionSpeed("Walk", (pTarget.ActMap.Walk.Speed) / 100);
}
func FxSwordStrikeStopStop(pTarget, effect, iCause, iTemp)
{
if(iTemp) return;
pTarget->PopActionSpeed("Walk");
if (this) movement_effect = nil;
if (this)
movement_effect = nil;
}
func FxSwordStrikeStopTimer(pTarget, effect)
@ -297,9 +308,10 @@ func FxSwordStrikeSpeedUpStart(pTarget, effect, iTemp)
func FxSwordStrikeSpeedUpTimer(pTarget, effect, iEffectTime)
{
if(!pTarget->GetContact( -1) & CNAT_Bottom)
if (!pTarget->GetContact(-1) & CNAT_Bottom)
return -1;
if (iEffectTime > 35 * 2)
return -1;
if(iEffectTime > 35*2) return -1;
}
func FxSwordStrikeSpeedUpStop(pTarget, effect, iCause, iTemp)
@ -320,7 +332,8 @@ func FxSwordStrikeSlowStart(pTarget, effect, iTemp, iTime)
func FxSwordStrikeSlowTimer(pTarget, effect, iEffectTime)
{
if(iEffectTime > effect.starttime) return -1;
if (iEffectTime > effect.starttime)
return -1;
}
func FxSwordStrikeSlowStop(pTarget, effect, iCause, iTemp)
@ -339,7 +352,7 @@ public func GetCarryMode(object clonk, bool idle, bool nohand)
{
if (idle)
return CARRY_Sword;
return CARRY_HandBack;
}
@ -353,8 +366,9 @@ public func GetCarryTransform(clonk, sec, back)
return Trans_Rotate(-90, 1, 0, 0);
}
func Definition(def) {
SetProperty("PictureTransformation",Trans_Rotate(20, 0, 0, 1),def);
func Definition(def)
{
SetProperty("PictureTransformation", Trans_Rotate(20, 0, 0, 1), def);
}
/*-- Properties --*/
@ -362,4 +376,4 @@ func Definition(def) {
local Name = "$Name$";
local Description = "$Description$";
local Collectible = true;
local Components = {Wood = 1, Metal = 1};
local Components = {Wood = 1, Metal = 1};