- //! zinc
- library NaturesQuarry requires TimerUtils, Core, DamageSystem {
- struct Boulder {
- static thistype tempBoulder;
- static boolexpr FILTER;
- unit u;
- unit dummy;
- real damage = 0;
- real distance = 0;
- real size = 0;
- group hitunits;
- effect effect;
- static method Knock() {
- unit t = GetEnumUnit();
- real x = GetUnitX(thistype.tempBoulder.dummy);
- real y = GetUnitY(thistype.tempBoulder.dummy);
- SetUnitX(t, x);
- SetUnitY(t, y);
- t = null;
- }
- static method Update() {
- timer t = GetExpiredTimer();
- thistype d = GetTimerData(t);
- real x = PolarProjectionX( GetUnitX(d.dummy), 14, GetUnitFacing(d.dummy)*bj_DEGTORAD );
- real y = PolarProjectionY( GetUnitY(d.dummy), 14, GetUnitFacing(d.dummy)*bj_DEGTORAD );
- if (IsTerrainWalkable(x,y)){
- SetUnitX(d.dummy, x);
- SetUnitY(d.dummy, y);
- } else {
- d.distance = d.distance-20;
- }
- DestroyEffect( AddSpecialEffect("Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl", x, y) );
- if ( d.size < 2 ) { d.size = d.size+0.125; SetUnitScale(d.dummy,d.size,d.size,d.size); }
- thistype.tempBoulder = d;
- GroupEnumUnitsInRange( tempGroup, x, y, 125, thistype.FILTER );
- ForGroup( d.hitunits, function thistype.Knock );
- d.distance = d.distance - 14;
- if (d.distance < 0) {
- d.destroy();
- ReleaseTimer(t);
- }
- }
- static method create (unit u, real x, real y) -> thistype {
- timer t = NewTimer();
- thistype d = thistype.allocate();
- d.u = u;
- d.dummy = CreateUnit( Player(15), 'h000', GetUnitX(u), GetUnitY(u), AngleBetweenPointsXY(GetUnitX(u), GetUnitY(u), x, y)*bj_RADTODEG );
- d.damage = 40+GetUnitStat(u, SPELL_POWER)*0.75+GetHeroLevel(u)*5+GetHeroStr(u,true);
- d.hitunits = CreateGroup();
- d.distance = 800;
- d.size = 0;
- d.effect = AddSpecialEffectTarget("Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl", d.dummy, "origin");
- SetUnitScale(d.dummy,0,0,0);
- SetTimerData(t,d);
- TimerStart(t,0.035,true,function thistype.Update);
- return d;
- }
- static method FilterFunc() -> boolean {
- unit t = GetFilterUnit();
- if ( GetWidgetLife(t) > 0.405 && IsUnitEnemy(t, GetOwningPlayer( thistype.tempBoulder.u )) && !IsUnitInGroup(t, thistype.tempBoulder.hitunits) && !IsUnitType(t, UNIT_TYPE_MECHANICAL))
- {
- UnitDamage(thistype.tempBoulder.u, t, MAGIC, thistype.tempBoulder.damage);
- GroupAddUnit(thistype.tempBoulder.hitunits, t);
- }
- t = null;
- return FALSE;
- }
- static method onInit() {
- thistype.FILTER = Condition( function thistype.FilterFunc );
- }
- method onDestroy() {
- DestroyEffect(this.effect);
- KillUnit( this.dummy );
- DestroyGroup( this.hitunits );
- }
- }
- function Conditions() -> boolean {
- return GetSpellAbilityId() == 'A04C';
- }
- function Actions() {
- real x = GetSpellTargetX();
- real y = GetSpellTargetY();
- Boulder.create( GetTriggerUnit(), x, y );
- }
- function onInit(){
- trigger t = CreateTrigger();
- TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT);
- TriggerAddCondition(t, Condition(function Conditions));
- TriggerAddAction(t, function Actions);
- }
- }
- //! endzinc
