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;
}
@ -60,7 +60,8 @@ public func ControlUseStart(object clonk, int iX, int iY)
// 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;
}
@ -68,7 +69,7 @@ public func ControlUseStart(object clonk, int iX, int iY)
{
//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)
if (tree->IsStanding() && treedist <= 6)
{
using = 1;
@ -88,7 +89,7 @@ public func ControlUseStart(object clonk, int iX, int iY)
AddEffect("IntAxe", clonk, 1, 1, this, nil, tree);
return true;
}
if(! tree->IsStanding())
if (!tree->IsStanding())
{
// Tree has already been felled
using = 1;
@ -119,33 +120,36 @@ 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);
}
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));
@ -154,7 +158,7 @@ public func ControlUse(object clonk, int iX, int iY)
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();
@ -296,15 +301,16 @@ 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(),
@ -313,17 +319,17 @@ 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 */);
AddEffect(effect_name, obj, 1, 60);
if(GetEffect(axe_name, obj))
if (GetEffect(axe_name, obj))
{
first=false;
first = false;
}
else
{
@ -331,12 +337,12 @@ func CheckStrike(iTime)
}
// 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)
@ -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;
}
@ -401,17 +408,17 @@ public func GetCarryTransform(object clonk, bool idle)
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";

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 --*/

View File

@ -30,11 +30,12 @@ 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?");
@ -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,7 +100,7 @@ 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";
@ -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);
@ -130,7 +131,7 @@ func EndUsage(object clonk)
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 (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 (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;
@ -64,42 +64,46 @@ 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
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));
@ -110,7 +114,8 @@ public func ControlUse(object clonk, int x, int y)
animation = Format("SwordSlash1.%s", arm);
downwards_stab = true;
if(GetEffect("Fall", clonk)) RemoveEffect("Fall", clonk);
if (GetEffect("Fall", clonk))
RemoveEffect("Fall", clonk);
// visual effect
AddEffect("VisualJumpStrike", clonk, 1, 2, nil, Sword);
@ -118,15 +123,15 @@ public func ControlUse(object clonk, int x, int y)
}
}
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,18 +216,18 @@ 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
{
@ -224,8 +237,8 @@ func CheckStrike(iTime)
// 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
@ -236,15 +249,13 @@ 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)
else if (!first)
ApplyWeaponBash(obj, damage / 50, Angle(0, 0, angle, -10));
else if (!offset_y)
DoWeaponSlow(obj, 300);
// Particle effect
@ -256,11 +267,11 @@ func CheckStrike(iTime)
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)
@ -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 --*/