public static LaneUnit generateUnit(int type, int team, int number, Player player) { Point spawn = team == 0 ? Const.SPAWNTEAM0 : Const.SPAWNTEAM1; Point target = team == 1 ? Const.TOWERTEAM0 : Const.TOWERTEAM1; LaneUnit unit = new LaneUnit(spawn.x + 50 * type * (team * 2 - 1), spawn.y + number * 50, 1, team, 150, target, player); unit.targetPoint = new Point(unit.targetPoint.x, unit.y); // Move in a straight line if (type == 0) { unit.health = unit.maxHealth = 400; unit.damage = 25; unit.range = 90; unit.goldValue = Const.MELEE_UNIT_GOLD_VALUE; } else { unit.health = unit.maxHealth = 250; unit.damage = 35; unit.range = 300; unit.goldValue = Const.RANGER_UNIT_GOLD_VALUE; } unit.attackTime = 0.2; return(unit); }
internal void fireAttack(Unit unit) { if (!canAttack(unit)) { return; } double attackTravelTime = Math.Min(1.0, attackTime + (isMelee() ? 0 : attackTime * Distance(unit) / range)); if (Const.game.t + attackTravelTime > 1.0) { return; // no attacks cross rounds. } Const.game.events.Add(new DamageEvent(unit, this, attackTravelTime, this.damage)); //Creep aggro. if (this is Hero && unit is Hero) { foreach (Unit u in Const.game.allUnits) { if (u.team != 1 - team) { continue; } if (u is LaneUnit && Distance2(u) < Const.AGGROUNITRANGE2) { LaneUnit peasant = ((LaneUnit)u); if (peasant.aggroTimeLeft < Const.AGGROUNITTIME) { peasant.aggroUnit = this; peasant.aggroTset = Const.game.t; } else if (peasant.aggroTset == Const.game.t && peasant.aggroUnit != null && peasant.aggroUnit.Distance2(unit) > this.Distance2(unit)) { peasant.aggroUnit = this; } peasant.aggroTimeLeft = Const.AGGROUNITTIME; } if (u is Tower && Distance2(u) < Const.AGGROUNITRANGE2) { Tower peasant = ((Tower)u); if (peasant.aggroTimeLeft < Const.AGGROUNITTIME) { peasant.aggroUnit = this; peasant.aggroTset = Const.game.t; } else if (peasant.aggroTset == Const.game.t && peasant.aggroUnit != null && peasant.aggroUnit.Distance2(unit) > this.Distance2(unit)) { peasant.aggroUnit = this; } peasant.aggroTimeLeft = Const.AGGROUNITTIME; } } } }