public void Update(long diff) { _timeElapsed += (float)diff / 1000.0f; if (_buffScript.isLoaded()) { try { _buffScript.lua["diff"] = diff; _buffScript.lua.DoString("onUpdate(diff)"); } catch (LuaException e) { Logger.LogCoreError("LUA ERROR : " + e.Message); } } if (_duration != 0.0f) { if (_timeElapsed >= _duration) { try { _buffScript.lua.DoString("onBuffEnd()"); } catch (LuaException e) { Logger.LogCoreError("LUA ERROR : " + e.Message); } _remove = true; } } }
public override void update(long diff) { _timerUpdate += diff; if (_timerUpdate >= UPDATE_TIME) { if (unitScript.isLoaded()) { try { unitScript.lua["diff"] = _timerUpdate; unitScript.lua["me"] = this; unitScript.lua.DoString("onUpdate(diff)"); } catch (LuaScriptException e) { Logger.LogCoreError("LUA ERROR : " + e.Message); } } _timerUpdate = 0; } if (isDead()) { if (targetUnit != null) { setTargetUnit(null); autoAttackTarget = null; isAttacking = false; _game.PacketNotifier.notifySetTarget(this, null); initialAttackDone = false; } return; } if (targetUnit != null) { if (targetUnit.isDead() || !_game.GetMap().TeamHasVisionOn(getTeam(), targetUnit)) { setTargetUnit(null); isAttacking = false; _game.PacketNotifier.notifySetTarget(this, null); initialAttackDone = false; } else if (isAttacking && autoAttackTarget != null) { autoAttackCurrentDelay += diff / 1000.0f; if (autoAttackCurrentDelay >= autoAttackDelay / stats.AttackSpeedMultiplier.Total) { if (!isMelee()) { Projectile p = new Projectile(_game, autoAttackProjId, x, y, 5, this, autoAttackTarget, null, autoAttackProjectileSpeed, 0); _game.GetMap().AddObject(p); _game.PacketNotifier.notifyShowProjectile(p); } else { autoAttackHit(autoAttackTarget); } autoAttackCurrentCooldown = 1.0f / (stats.GetTotalAttackSpeed()); isAttacking = false; } } else if (distanceWith(targetUnit) <= stats.Range.Total) { refreshWaypoints(); nextAutoIsCrit = new Random().Next(0, 100) <= stats.CriticalChance.Total * 100; if (autoAttackCurrentCooldown <= 0) { isAttacking = true; autoAttackCurrentDelay = 0; autoAttackProjId = _game.GetNewNetID(); autoAttackTarget = targetUnit; if (!initialAttackDone) { initialAttackDone = true; _game.PacketNotifier.notifyBeginAutoAttack(this, targetUnit, autoAttackProjId, nextAutoIsCrit); } else { nextAttackFlag = !nextAttackFlag; // The first auto attack frame has occurred _game.PacketNotifier.notifyNextAutoAttack(this, targetUnit, autoAttackProjId, nextAutoIsCrit, nextAttackFlag); } var attackType = isMelee() ? AttackType.ATTACK_TYPE_MELEE : AttackType.ATTACK_TYPE_TARGETED; _game.PacketNotifier.notifyOnAttack(this, targetUnit, attackType); } } else { refreshWaypoints(); } } else if (isAttacking) { if (autoAttackTarget == null || autoAttackTarget.isDead() || !_game.GetMap().TeamHasVisionOn(getTeam(), autoAttackTarget)) { isAttacking = false; initialAttackDone = false; autoAttackTarget = null; } } base.update(diff); if (autoAttackCurrentCooldown > 0) { autoAttackCurrentCooldown -= diff / 1000.0f; } statUpdateTimer += diff; if (statUpdateTimer >= 500) { // update stats (hpregen, manaregen) every 0.5 seconds stats.update(statUpdateTimer); statUpdateTimer = 0; } }