Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //! zinc
- library Entanglement {
- //Entanglement (Arborius) code:
- private constant integer Unique = 'TAAR';
- private constant integer ArboriusCode = 'TITA';
- //Static stats:
- private constant integer Enemy_Info = 'A0KQ';
- private constant integer DamageReduction = 'TAAV';
- private constant integer AttackSpeedBurst = 'TAAT';
- private constant integer BurstAttacks = 2;
- private constant real BurstDuration = 3;
- private constant real BurstRange = 200;
- private constant real EntanglementChance = 0.15;
- private constant real EntanglementDuration = 6;
- //Hashtable
- hashtable Hash = InitHashtable();
- //---------------------------------------------
- private function EntangleExpiration() {
- timer Timer = GetExpiredTimer();
- unit Attacker = LoadUnitHandle(Hash, 0, GetHandleId(Timer));
- UnitRemoveAbility(Attacker, DamageReduction);
- UnitRemoveAbility(Attacker, Enemy_Info);
- FlushChildHashtable(Hash, GetHandleId(Timer));
- Attacker = null;
- Timer = null;
- }
- private function BurstExpiration() {
- timer BurstTimer = GetExpiredTimer();
- unit Arborius = LoadUnitHandle(Hash, 0, GetHandleId(BurstTimer));
- SetUnitAbilityLevel(Arborius, AttackSpeedBurst, 1);
- UnitRemoveAbility(Arborius, AttackSpeedBurst);
- FlushChildHashtable(Hash, GetHandleId(BurstTimer));
- FlushChildHashtable(Hash, GetHandleId(Arborius));
- BJDebugMsg("Removing burst, timer out");
- Arborius = null;
- BurstTimer = null;
- }
- private function onInit() {
- trigger t = CreateTrigger();
- TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DAMAGED);
- TriggerAddCondition(t, function() -> boolean {
- unit Attacker = GetEventDamageSource();
- unit Arborius = GetTriggerUnit();
- real Roll;
- timer Timer = CreateTimer();
- timer BurstTimer = CreateTimer();
- if(GetUnitTypeId(Arborius) == ArboriusCode && GetUnitAbilityLevel(Arborius, Unique) > 0 && IsUnitEnemy(Attacker, GetOwningPlayer(Arborius)) && IsUnitType(Attacker, UNIT_TYPE_STRUCTURE) == true) {
- Roll = GetRandomReal(0, 1);
- if(Roll <= EntanglementChance) {
- BJDebugMsg("Entanglement Activated");
- //Let's check that the unit is not already Entangled:
- if(GetUnitAbilityLevel(Attacker, DamageReduction) == 0) {
- BJDebugMsg("New entangle!");
- UnitAddAbility(Attacker, DamageReduction);
- SetUnitAbilityLevel(Attacker, DamageReduction, GetUnitAbilityLevel(Arborius, Unique));
- UnitAddAbility(Attacker, Enemy_Info);
- UnitAddAbility(Arborius, AttackSpeedBurst);
- if(GetUnitAbilityLevel(Arborius, AttackSpeedBurst) < 7) {
- SetUnitAbilityLevel(Arborius, AttackSpeedBurst, GetUnitAbilityLevel(Arborius, AttackSpeedBurst) + BurstAttacks);
- }
- SaveUnitHandle(Hash, 0, GetHandleId(Timer), Attacker);
- SaveUnitHandle(Hash, 0, GetHandleId(BurstTimer), Arborius);
- SaveTimerHandle(Hash, 0, GetHandleId(Arborius), BurstTimer);
- TimerStart(Timer, EntanglementDuration, false, function EntangleExpiration);
- TimerStart(BurstTimer, BurstDuration, false, function BurstExpiration);
- } else {
- BJDebugMsg("Already entangled, renew!");
- TimerStart(Timer, EntanglementDuration, false, function EntangleExpiration);
- }
- }
- }
- if(GetUnitAbilityLevel(Attacker, AttackSpeedBurst) > 0 && GetUnitTypeId(Attacker) == ArboriusCode && IsUnitEnemy(Attacker, GetOwningPlayer(Arborius)) && BlzGetEventDamageType() == DAMAGE_TYPE_NORMAL){
- BJDebugMsg("Burst attack!");
- DecUnitAbilityLevel(Attacker, AttackSpeedBurst);
- if(GetUnitAbilityLevel(Attacker, AttackSpeedBurst) == 1) {
- UnitRemoveAbility(Attacker, AttackSpeedBurst);
- BurstTimer = LoadTimerHandle(Hash, GetHandleId(Attacker), 0);
- FlushChildHashtable(Hash, GetHandleId(BurstTimer));
- FlushChildHashtable(Hash, GetHandleId(Attacker));
- DestroyTimer(BurstTimer);
- BJDebugMsg("Removing burst, all spent");
- }
- }
- Attacker = null;
- Arborius = null;
- Timer = null;
- BurstTimer = null;
- return false;
- });
- t = null;
- }
- }
- //! endzinc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement