2010-02-27 11:15:06 +00:00
|
|
|
/*-- Sword --*/
|
|
|
|
|
2010-03-02 16:24:51 +00:00
|
|
|
#include Library_MeleeWeapon
|
2010-02-27 11:15:06 +00:00
|
|
|
|
2012-04-10 21:31:46 +00:00
|
|
|
static const Sword_Standard_StrikingLength = 15; // in frames
|
|
|
|
|
2012-04-03 17:20:41 +00:00
|
|
|
func Hit()
|
2010-02-27 11:15:06 +00:00
|
|
|
{
|
2012-04-03 17:20:41 +00:00
|
|
|
Sound("LightMetalHit?");
|
2010-02-27 11:15:06 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 17:31:47 +00:00
|
|
|
public func Initialize()
|
|
|
|
{
|
|
|
|
PlayAnimation("Base", 5, Anim_Const(0), Anim_Const(1000));
|
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2010-02-27 11:15:06 +00:00
|
|
|
public func GetCarryMode() { return CARRY_HandBack; }
|
|
|
|
public func GetCarryBone() { return "main"; }
|
2010-10-09 13:08:31 +00:00
|
|
|
public func GetCarrySpecial(clonk) { return carry_bone; }
|
2012-11-11 19:39:08 +00:00
|
|
|
public func GetCarryTransform(clonk, sec, back)
|
2011-06-08 08:49:11 +00:00
|
|
|
{
|
2012-11-11 19:39:08 +00:00
|
|
|
if(back) return Trans_Mul(Trans_Rotate(180,0,0,1), Trans_Rotate(90,0,1,0), Trans_Translate(0,-7000,0));
|
2011-06-08 08:49:11 +00:00
|
|
|
return Trans_Rotate(90, 0, 1, 0);
|
|
|
|
}
|
2010-02-27 11:15:06 +00:00
|
|
|
|
2010-09-12 20:59:02 +00:00
|
|
|
local magic_number;
|
2010-10-09 13:08:31 +00:00
|
|
|
local carry_bone;
|
2011-01-03 20:20:01 +00:00
|
|
|
public func ControlUse(object clonk, int x, int y)
|
2010-02-27 11:15:06 +00:00
|
|
|
{
|
2010-11-25 18:03:19 +00:00
|
|
|
// cooldown?
|
2010-02-27 11:15:06 +00:00
|
|
|
if(!CanStrikeWithWeapon(clonk)) return true;
|
2010-11-25 18:03:19 +00:00
|
|
|
|
|
|
|
// if the clonk doesn't have an action where he can use it's hands do nothing
|
|
|
|
if(!clonk->HasHandAction())
|
|
|
|
return true;
|
|
|
|
|
2010-03-06 09:08:51 +00:00
|
|
|
var slow=GetEffect("SwordStrikeSlow", clonk);
|
2010-07-19 21:37:39 +00:00
|
|
|
|
|
|
|
var arm = "R";
|
2010-10-09 13:08:31 +00:00
|
|
|
carry_bone = "pos_hand2";
|
2012-04-10 03:17:57 +00:00
|
|
|
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 1)
|
2010-10-09 13:08:31 +00:00
|
|
|
{
|
|
|
|
arm = "L";
|
|
|
|
carry_bone = "pos_hand1";
|
|
|
|
}
|
2010-07-19 23:06:27 +00:00
|
|
|
var rand = Random(2)+1;
|
2010-09-11 10:20:22 +00:00
|
|
|
var animation = Format("SwordSlash%d.%s", rand, arm);
|
2010-07-19 23:06:27 +00:00
|
|
|
var animation_sword = Format("Strike%d", rand);
|
2011-06-04 23:08:54 +00:00
|
|
|
var downwards_stab = false;
|
2010-02-27 11:15:06 +00:00
|
|
|
|
|
|
|
// figure out the kind of attack to use
|
2012-04-10 21:31:46 +00:00
|
|
|
var length = Sword_Standard_StrikingLength;
|
2010-09-12 20:59:02 +00:00
|
|
|
if(clonk->IsWalking())
|
2010-02-27 11:15:06 +00:00
|
|
|
{
|
2012-04-10 03:10:21 +00:00
|
|
|
if(!GetEffect("SwordStrikeStop", clonk))
|
|
|
|
AddEffect("SwordStrikeStop", clonk, 2, length, this);
|
2010-09-12 20:59:02 +00:00
|
|
|
} else
|
2010-02-27 11:15:06 +00:00
|
|
|
if(clonk->IsJumping())
|
|
|
|
{
|
2011-06-08 08:49:11 +00:00
|
|
|
rand = 1;
|
|
|
|
if(clonk->GetYDir() < -5) rand = 2;
|
|
|
|
animation = Format("SwordJump%d.%s",rand,arm);
|
2010-03-06 09:08:51 +00:00
|
|
|
|
2011-06-04 23:08:54 +00:00
|
|
|
if(!slow && !GetEffect("DelayTranslateVelocity", clonk))
|
2010-03-06 09:08:51 +00:00
|
|
|
{
|
2012-04-10 21:31:46 +00:00
|
|
|
// check whether the player aims below the Clonk
|
2010-03-22 15:14:23 +00:00
|
|
|
var a=Angle(0, 0, x,y);
|
2012-10-13 11:45:36 +00:00
|
|
|
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
|
2010-07-31 20:48:37 +00:00
|
|
|
{
|
2012-10-13 11:45:36 +00:00
|
|
|
clonk->SetXDir(x_dir);
|
2010-07-31 20:48:37 +00:00
|
|
|
clonk->SetYDir(-Cos(a, 60));
|
|
|
|
AddEffect("DelayTranslateVelocity", clonk, 2, 3, nil, Library_MeleeWeapon);
|
2011-06-04 23:08:54 +00:00
|
|
|
|
|
|
|
// modified animation
|
|
|
|
length = 50;
|
|
|
|
animation = Format("SwordSlash1.%s", arm);
|
|
|
|
downwards_stab = true;
|
2012-10-13 11:45:36 +00:00
|
|
|
|
2011-06-04 23:08:54 +00:00
|
|
|
if(GetEffect("Fall", clonk)) RemoveEffect("Fall", clonk);
|
2012-10-13 11:45:36 +00:00
|
|
|
|
|
|
|
// visual effect
|
|
|
|
AddEffect("VisualJumpStrike", clonk, 1, 2, nil, Sword);
|
2010-07-31 20:48:37 +00:00
|
|
|
}
|
2010-03-06 09:08:51 +00:00
|
|
|
}
|
2010-02-27 11:15:06 +00:00
|
|
|
}
|
2010-07-31 20:48:37 +00:00
|
|
|
//else return true;*/
|
2010-07-20 21:15:09 +00:00
|
|
|
if(!clonk->IsWalking() && !clonk->IsJumping()) return true;
|
2010-02-27 11:15:06 +00:00
|
|
|
|
2011-06-04 23:08:54 +00:00
|
|
|
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));
|
|
|
|
}
|
2010-10-09 13:08:31 +00:00
|
|
|
clonk->UpdateAttach();
|
2010-09-12 20:59:02 +00:00
|
|
|
|
2012-04-10 21:31:46 +00:00
|
|
|
// this means that the sword can only hit an object every X frames
|
|
|
|
// change it to something that changes every strike if you want the sword to be able to hit the same enemy with different
|
|
|
|
// strikes regardless of the time in between
|
|
|
|
magic_number = ObjectNumber();
|
2010-02-27 11:15:06 +00:00
|
|
|
StartWeaponHitCheckEffect(clonk, length, 1);
|
2010-09-20 13:34:39 +00:00
|
|
|
|
2011-10-12 21:09:22 +00:00
|
|
|
this->Sound("WeaponSwing?", false, nil, nil, nil);
|
2010-02-27 11:15:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-13 11:45:36 +00:00
|
|
|
func FxVisualJumpStrikeStart(target, effect, temp)
|
|
|
|
{
|
|
|
|
if(temp) return;
|
|
|
|
effect.x_add = 20;
|
|
|
|
if(target->GetXDir() < 0) effect.x_add *= -1;
|
|
|
|
effect.visual = CreateObject(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)
|
|
|
|
{
|
2012-10-14 12:06:23 +00:00
|
|
|
if(!target->~IsJumping())
|
2012-10-13 11:45:36 +00:00
|
|
|
{
|
|
|
|
effect.visual->FadeOut();
|
2012-10-14 12:47:14 +00:00
|
|
|
effect.visual = nil;
|
2012-10-13 11:45:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
effect.visual->Point(nil, {x = target->GetX() + effect.x_add, y = target->GetY() + 10});
|
|
|
|
}
|
|
|
|
|
2012-10-14 12:47:14 +00:00
|
|
|
func FxVisualJumpStrikeStop(target, effect, reason, temp)
|
|
|
|
{
|
|
|
|
if(temp) return;
|
|
|
|
if(!effect.visual) return;
|
|
|
|
effect.visual->FadeOut();
|
|
|
|
}
|
|
|
|
|
2010-03-06 09:08:51 +00:00
|
|
|
func OnWeaponHitCheckStop(clonk)
|
2010-02-27 11:15:06 +00:00
|
|
|
{
|
2010-10-09 13:08:31 +00:00
|
|
|
carry_bone = nil;
|
|
|
|
clonk->UpdateAttach();
|
2010-03-06 09:08:51 +00:00
|
|
|
if(GetEffect("SwordStrikeSpeedUp", clonk))
|
|
|
|
RemoveEffect("SwordStrikeSpeedUp", clonk);
|
2012-04-10 21:31:46 +00:00
|
|
|
|
2011-06-04 23:08:54 +00:00
|
|
|
if(clonk->IsJumping())
|
|
|
|
{
|
|
|
|
if(!GetEffect("Fall", clonk))
|
|
|
|
AddEffect("Fall",clonk,1,1,clonk);
|
|
|
|
}
|
2012-04-10 21:31:46 +00:00
|
|
|
|
|
|
|
if(GetEffect("SwordStrikeStop", clonk))
|
|
|
|
RemoveEffect("SwordStrikeStop", clonk);
|
|
|
|
|
2010-02-27 11:15:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-10 21:31:46 +00:00
|
|
|
// called when the strike expired before end of length (aborted)
|
2010-02-27 11:15:06 +00:00
|
|
|
func WeaponStrikeExpired()
|
|
|
|
{
|
2012-04-10 21:31:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func SwordDamage(int shield)
|
|
|
|
{
|
|
|
|
return ((100-shield)*9*1000 / 100);
|
2010-02-27 11:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func CheckStrike(iTime)
|
|
|
|
{
|
2010-03-07 15:44:17 +00:00
|
|
|
//if(iTime < 20) return;
|
2010-10-14 15:58:09 +00:00
|
|
|
var offset_x=7;
|
2010-07-31 20:48:37 +00:00
|
|
|
var offset_y=0;
|
2010-07-20 21:15:09 +00:00
|
|
|
if(Contained()->GetDir() == DIR_Left) offset_x*=-1;
|
2010-07-31 20:48:37 +00:00
|
|
|
|
|
|
|
if(!(Contained()->GetContact(-1) & CNAT_Bottom))
|
|
|
|
offset_y=10;
|
|
|
|
|
2010-10-14 15:58:09 +00:00
|
|
|
var width=10;
|
2010-02-27 11:15:06 +00:00
|
|
|
var height=20;
|
|
|
|
var angle=0;
|
|
|
|
|
2010-03-06 09:08:51 +00:00
|
|
|
var doBash=Abs(Contained()->GetXDir()) > 5 || Abs(Contained()->GetYDir()) > 5;
|
|
|
|
if(!doBash) 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())));
|
|
|
|
}
|
2010-02-27 11:15:06 +00:00
|
|
|
|
2010-10-23 20:20:40 +00:00
|
|
|
for(var obj in FindObjects(Find_AtRect(offset_x - width/2, offset_y - height/2, width, height),
|
|
|
|
Find_NoContainer(),
|
|
|
|
Find_Exclude(Contained()),
|
|
|
|
Find_Layer(GetObjectLayer())))
|
2010-02-27 11:15:06 +00:00
|
|
|
{
|
2010-10-23 20:20:40 +00:00
|
|
|
if (obj->~IsProjectileTarget(this, Contained()) || obj->GetOCF() & OCF_Alive)
|
2010-09-12 20:59:02 +00:00
|
|
|
{
|
2010-10-23 20:20:40 +00:00
|
|
|
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))
|
2010-09-12 20:59:02 +00:00
|
|
|
{
|
2012-04-12 09:48:23 +00:00
|
|
|
AddEffect(effect_name, obj, 1, Sword_Standard_StrikingLength, nil, 0);
|
2010-10-23 20:20:40 +00:00
|
|
|
|
|
|
|
if(GetEffect(sword_name, obj))
|
|
|
|
{
|
|
|
|
//Log("successive hit");
|
|
|
|
first=false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Log("first hit overall");
|
2012-04-12 09:48:23 +00:00
|
|
|
AddEffect(sword_name, obj, 1, 40, nil, 0);
|
2010-10-23 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Reduce damage by shield
|
|
|
|
var shield=ApplyShieldFactor(Contained(), obj, 0); // damage out of scope?
|
|
|
|
if(shield == 100)
|
|
|
|
continue;
|
|
|
|
|
2010-12-15 18:00:04 +00:00
|
|
|
// fixed damage (9)
|
2012-04-10 21:31:46 +00:00
|
|
|
var damage = SwordDamage(shield);
|
2010-10-29 20:38:54 +00:00
|
|
|
ProjectileHit(obj, damage, ProjectileHit_no_query_catch_blow_callback | ProjectileHit_exact_damage | ProjectileHit_no_on_projectile_hit_callback, FX_Call_EngGetPunched);
|
2010-10-23 20:20:40 +00:00
|
|
|
|
|
|
|
// object has not been deleted?
|
|
|
|
if(obj)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Particle effect
|
|
|
|
var x=-1;
|
|
|
|
var p="Slice2";
|
|
|
|
if(Contained()->GetDir() == DIR_Right)
|
|
|
|
{
|
|
|
|
x=1;
|
|
|
|
p="Slice1";
|
|
|
|
}
|
2012-04-10 21:31:46 +00:00
|
|
|
CreateParticle(p, AbsX(obj->GetX())+RandomX(-1,1), AbsY(obj->GetY())+RandomX(-1,1), 0, 0, 100, RGB(255,255,255), obj);
|
2010-10-23 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sound and done. We can only hit one target
|
2011-10-12 21:09:22 +00:00
|
|
|
Sound("WeaponHit?", false);
|
2010-10-23 20:20:40 +00:00
|
|
|
break;
|
2010-09-12 20:59:02 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-27 11:15:06 +00:00
|
|
|
}
|
2010-10-23 20:20:40 +00:00
|
|
|
|
2010-03-06 09:08:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-23 13:35:16 +00:00
|
|
|
func FxSwordStrikeStopStart(pTarget, effect, iTemp)
|
2010-09-12 20:59:02 +00:00
|
|
|
{
|
|
|
|
if(iTemp) return;
|
2012-04-10 03:10:21 +00:00
|
|
|
pTarget->PushActionSpeed("Walk", (pTarget.ActMap.Walk.Speed)/100);
|
2010-09-12 20:59:02 +00:00
|
|
|
}
|
|
|
|
|
2010-12-23 13:35:16 +00:00
|
|
|
func FxSwordStrikeStopStop(pTarget, effect, iCause, iTemp)
|
2010-09-12 20:59:02 +00:00
|
|
|
{
|
|
|
|
if(iTemp) return;
|
2012-04-10 03:10:21 +00:00
|
|
|
pTarget->PopActionSpeed("Walk");
|
2010-09-12 20:59:02 +00:00
|
|
|
}
|
|
|
|
|
2010-12-23 13:35:16 +00:00
|
|
|
func FxSwordStrikeStopTimer(pTarget, effect)
|
2010-09-12 20:59:02 +00:00
|
|
|
{
|
2012-04-10 03:10:21 +00:00
|
|
|
return -1;
|
2010-09-12 20:59:02 +00:00
|
|
|
}
|
2010-03-06 09:08:51 +00:00
|
|
|
|
2010-12-23 13:35:16 +00:00
|
|
|
func FxSwordStrikeSpeedUpStart(pTarget, effect, iTemp)
|
2010-03-06 09:08:51 +00:00
|
|
|
{
|
2010-12-11 20:10:05 +00:00
|
|
|
pTarget->PushActionSpeed("Walk", pTarget.ActMap.Walk.Speed * 3);
|
|
|
|
pTarget.ActMap.Walk.Accel = 210;
|
2010-03-06 09:08:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-23 13:35:16 +00:00
|
|
|
func FxSwordStrikeSpeedUpTimer(pTarget, effect, iEffectTime)
|
2010-03-06 09:08:51 +00:00
|
|
|
{
|
|
|
|
if(!pTarget->GetContact( -1) & CNAT_Bottom)
|
|
|
|
return -1;
|
|
|
|
if(iEffectTime > 35*2) return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-23 13:35:16 +00:00
|
|
|
func FxSwordStrikeSpeedUpStop(pTarget, effect, iCause, iTemp)
|
2010-03-06 09:08:51 +00:00
|
|
|
{
|
2010-12-11 20:10:05 +00:00
|
|
|
pTarget->PopActionSpeed("Walk");
|
2010-03-06 09:08:51 +00:00
|
|
|
if(iTemp) return;
|
|
|
|
if(!pTarget->GetAlive()) return;
|
|
|
|
|
2012-04-12 09:48:23 +00:00
|
|
|
AddEffect("SwordStrikeSlow", pTarget, 1, 5, nil, Sword, effect.Time);
|
2010-03-06 09:08:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-23 13:35:16 +00:00
|
|
|
func FxSwordStrikeSlowStart(pTarget, effect, iTemp, iTime)
|
2010-03-06 09:08:51 +00:00
|
|
|
{
|
2010-12-11 20:10:05 +00:00
|
|
|
pTarget->PushActionSpeed("Walk", pTarget.ActMap.Walk.Speed / 3);
|
2010-03-06 09:08:51 +00:00
|
|
|
if(iTemp) return;
|
2011-07-31 15:59:51 +00:00
|
|
|
effect.starttime = iTime;
|
2010-03-06 09:08:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-23 13:35:16 +00:00
|
|
|
func FxSwordStrikeSlowTimer(pTarget, effect, iEffectTime)
|
2010-03-06 09:08:51 +00:00
|
|
|
{
|
2011-07-31 15:59:51 +00:00
|
|
|
if(iEffectTime > effect.starttime) return -1;
|
2010-03-06 09:08:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-23 13:35:16 +00:00
|
|
|
func FxSwordStrikeSlowStop(pTarget, effect, iCause, iTemp)
|
2010-03-06 09:08:51 +00:00
|
|
|
{
|
2010-12-11 20:10:05 +00:00
|
|
|
pTarget->PopActionSpeed("Walk");
|
2010-02-27 11:15:06 +00:00
|
|
|
}
|
2010-08-23 14:20:38 +00:00
|
|
|
|
2011-10-13 22:03:55 +00:00
|
|
|
public func IsWeapon() { return true; }
|
|
|
|
public func IsArmoryProduct() { return true; }
|
|
|
|
|
2010-08-23 14:20:38 +00:00
|
|
|
func Definition(def) {
|
|
|
|
SetProperty("PictureTransformation",Trans_Rotate(20, 0, 0, 1),def);
|
2010-09-12 20:59:02 +00:00
|
|
|
}
|
2012-03-28 19:14:58 +00:00
|
|
|
|
|
|
|
local Name = "$Name$";
|
|
|
|
local Description = "$Description$";
|
|
|
|
local UsageHelp = "$UsageHelp$";
|
2011-01-02 22:17:47 +00:00
|
|
|
local Collectible = 1;
|
2011-02-20 19:59:50 +00:00
|
|
|
local Rebuy = true;
|