public override void update(long diff) { //f**k LUA /* if (unitScript.isLoaded()) * { * try * { * unitScript.lua.get<sol::function>("onUpdate").call<void>(diff); * } * catch (sol::error e) * { * CORE_ERROR("%s", e.what()); * } * }*/ if (isDead()) { if (targetUnit != null) { setTargetUnit(null); autoAttackTarget = null; isAttacking = false; PacketNotifier.notifySetTarget(this, null); initialAttackDone = false; } return; } if (targetUnit != null) { if (targetUnit.isDead() || !getMap().teamHasVisionOn(getTeam(), targetUnit)) { setTargetUnit(null); isAttacking = false; PacketNotifier.notifySetTarget(this, null); initialAttackDone = false; } else if (isAttacking && autoAttackTarget != null) { autoAttackCurrentDelay += diff / 1000.0f; if (autoAttackCurrentDelay >= autoAttackDelay / stats.getAttackSpeedMultiplier()) { if (!isMelee()) { Projectile p = new Projectile(map, autoAttackProjId, x, y, 5, this, autoAttackTarget, null, autoAttackProjectileSpeed, 0); map.addObject(p); PacketNotifier.notifyShowProjectile(p); } else { autoAttackHit(autoAttackTarget); } autoAttackCurrentCooldown = 1.0f / (stats.getTotalAttackSpeed()); isAttacking = false; } } else if (distanceWith(targetUnit) <= stats.getRange()) { refreshWaypoints(); nextAutoIsCrit = new Random().Next(0, 100) <= stats.getCritChance() * 100; if (autoAttackCurrentCooldown <= 0) { isAttacking = true; autoAttackCurrentDelay = 0; autoAttackProjId = Game.GetNewNetID(); autoAttackTarget = targetUnit; if (!initialAttackDone) { initialAttackDone = true; PacketNotifier.notifyBeginAutoAttack(this, targetUnit, autoAttackProjId, nextAutoIsCrit); } else { nextAttackFlag = !nextAttackFlag; // The first auto attack frame has occurred PacketNotifier.notifyNextAutoAttack(this, targetUnit, autoAttackProjId, nextAutoIsCrit, nextAttackFlag); } var attackType = isMelee() ? AttackType.ATTACK_TYPE_MELEE : AttackType.ATTACK_TYPE_TARGETED; PacketNotifier.notifyOnAttack(this, targetUnit, attackType); } } else { refreshWaypoints(); } } else if (isAttacking) { if (autoAttackTarget == null || autoAttackTarget.isDead() || !getMap().teamHasVisionOn(getTeam(), autoAttackTarget)) { isAttacking = false; initialAttackDone = false; autoAttackTarget = null; } } base.update(diff); if (autoAttackCurrentCooldown > 0) { autoAttackCurrentCooldown -= diff / 1000.0f; } statUpdateTimer += diff; if (statUpdateTimer >= 500000) { // update stats (hpregen, manaregen) every 0.5 seconds stats.update(statUpdateTimer); statUpdateTimer = 0; } }