public override void TakeDamage(decimal dmg, out Resource returning, out int attackPoints) { attackPoints = 0; ushort dead = 0; if (dmg >= leftOverHp) { dmg -= leftOverHp; leftOverHp = stats.MaxHp; dead++; } dead += (ushort)(dmg / stats.MaxHp); leftOverHp -= dmg % stats.MaxHp; if (dead > 0) { if (dead > count) { dead = count; } count -= dead; attackPoints = formula.GetUnitKilledAttackPoint(type, lvl, dead); // Remove dead units from troop stub TroopStub.BeginUpdate(); TroopStub[formation].Remove(type, dead); TroopStub.EndUpdate(); } returning = null; }
public void TestStarveToZeroBypassProtection(TroopStub stub) { stub.AddFormation(FormationType.Normal); stub.AddUnit(FormationType.Normal, 0, 1); stub.Starve(5, true); Assert.False(stub[FormationType.Normal].ContainsKey(0)); }
public void TestStarveToZero(TroopStub stub) { stub.AddFormation(FormationType.Normal); stub.AddUnit(FormationType.Normal, 0, 1); stub.Starve(); Assert.Equal(stub[FormationType.Normal][0], 1); }
public void TestStarveSingleUnit(TroopStub stub) { stub.AddFormation(FormationType.Normal); stub.AddUnit(FormationType.Normal, 0, 10); stub.Starve(); Assert.Equal(stub[FormationType.Normal][0], 9); }
public void TestUnitListsNoUnitsInStub(TroopStub stub) { stub.AddFormation(FormationType.Normal); stub.AddFormation(FormationType.Attack); var units = stub.ToUnitList(); units.Count.Should().Be(0); }
public void TestStarveMultiFormation(TroopStub stub) { stub.AddFormation(FormationType.Normal); stub.AddFormation(FormationType.Attack); stub.AddUnit(FormationType.Normal, 0, 10); stub.AddUnit(FormationType.Attack, 0, 100); stub.Starve(); Assert.Equal(stub[FormationType.Normal][0], 9); Assert.Equal(stub[FormationType.Attack][0], 95); }
public void TestUnitListConflictingTypes(TroopStub stub) { stub.AddFormation(FormationType.Normal); stub.AddFormation(FormationType.Attack); stub.AddUnit(FormationType.Normal, 1, 4); stub.AddUnit(FormationType.Attack, 1, 5); var units = stub.ToUnitList(); Assert.True(units.Count == 1); Assert.True(units[0].Type == 1); Assert.True(units[0].Count == 9); }
public void TestUnitListSpecificFormations(TroopStub stub) { stub.AddFormation(FormationType.Normal); stub.AddFormation(FormationType.Attack); stub.AddUnit(FormationType.Normal, 1, 4); stub.AddUnit(FormationType.Attack, 1, 5); stub.AddUnit(FormationType.Attack, 2, 10); var units = stub.ToUnitList(FormationType.Attack); Assert.True(units.Count == 2); Assert.True(units[0].Type == 1); Assert.True(units[0].Count == 5); Assert.True(units[1].Type == 2); Assert.True(units[1].Count == 10); }
public void TestMoveFromBattleToNormal(TroopStub stub) { Global.Current = Substitute.For <IGlobal>(); Global.Current.FireEvents.Returns(false); stub.AddFormation(FormationType.Normal); stub.AddFormation(FormationType.Garrison); stub.AddFormation(FormationType.InBattle); stub.AddUnit(FormationType.Normal, 101, 10); var fixture = FixtureHelper.Create(); var procedure = fixture.Create <CityBattleProcedure>(); procedure.MoveUnitFormation(stub, FormationType.Normal, FormationType.InBattle); procedure.MoveUnitFormation(stub, FormationType.InBattle, FormationType.Normal); Assert.True(stub[FormationType.Normal].Type == FormationType.Normal); Assert.True(stub[FormationType.InBattle].Type == FormationType.InBattle); }
public override void TakeDamage(decimal dmg, out Resource returning, out int attackPoints) { attackPoints = 0; returning = null; ushort dead = 0; if (dmg >= LeftOverHp) { dmg -= LeftOverHp; LeftOverHp = stats.MaxHp; dead++; } dead += (ushort)(dmg / stats.MaxHp); LeftOverHp -= dmg % stats.MaxHp; if (dead > 0) { if (dead > count) { dead = count; } // Find out how many points the defender should get attackPoints = formula.GetUnitKilledAttackPoint(type, lvl, dead); // Remove troops that died from the count count -= dead; // Remove dead troops from the troop stub TroopStub.BeginUpdate(); TroopStub[formation].Remove(type, dead); TroopStub.EndUpdate(); // Figure out how much loot we have to return to the city int totalCarry = Stats.Carry * Count; returning = new Resource( loot.Crop > totalCarry / Config.battle_loot_resource_crop_ratio ? loot.Crop - totalCarry / Config.battle_loot_resource_crop_ratio : 0, loot.Gold > totalCarry / Config.battle_loot_resource_gold_ratio ? loot.Gold - totalCarry / Config.battle_loot_resource_gold_ratio : 0, loot.Iron > totalCarry / Config.battle_loot_resource_iron_ratio ? loot.Iron - totalCarry / Config.battle_loot_resource_iron_ratio : 0, loot.Wood > totalCarry / Config.battle_loot_resource_wood_ratio ? loot.Wood - totalCarry / Config.battle_loot_resource_wood_ratio : 0, loot.Labor > totalCarry / Config.battle_loot_resource_labor_ratio ? loot.Wood - totalCarry / Config.battle_loot_resource_labor_ratio : 0); // Remove it from our loot loot.Subtract(returning); // Since the loot is stored at the troop stub as well, we need to remove it from there too troopObject.BeginUpdate(); troopObject.Stats.Loot.Subtract(returning); troopObject.EndUpdate(); } }
public Group() { player = new Player(playerId, DateTime.MinValue, SystemClock.Now, "player " + playerId, string.Empty, PlayerRights.Basic); playerId++; BaseBattleStats baseBattleStats = new BaseBattleStats(type: 2000, lvl: 1, weapon: WeaponType.Sword, wpnClass: WeaponClass.Elemental, armor: ArmorType.Building3, armrClass: ArmorClass.Stone, maxHp: 500, atk: 0, splash: 0, range: 0, stealth: 0, speed: 0, groupSize: 1, carry: 0, normalizedCost: 0); StructureBaseStats structureBaseStats = new StructureBaseStats(name: "MainBuilding", spriteClass: "", type: 2000, lvl: 1, radius: 0, cost: null, baseBattleStats: baseBattleStats, maxLabor: 0, buildTime: 0, workerId: 0); StructureStats structurestats = new StructureStats(structureBaseStats); var main = new Structure(structurestats); city = Ioc.Kernel.Get <ICityFactory>() .CreateCity(id: cityId, owner: player, name: "city " + cityId, resource: Formula.Current.GetInitialCityResources(), radius: Formula.Current.GetInitialCityRadius(), ap: 0); main.ObjectId = 1; city.Add(main.ObjectId, main, false); player.Add(city); cityId++; AttackStub = new TroopStub(0, city); AttackStub.AddFormation(FormationType.Normal); obj = new TroopObject(AttackStub); using (Concurrency.Current.Lock(city)) { city.Troops.Add(AttackStub); city.Add(obj); } TroopObject = new TroopObject(AttackStub) { X = city.X, Y = city.Y }; TroopObject.BeginUpdate(); TroopObject.Stats = new TroopStats(Formula.Current.GetTroopRadius(AttackStub, null), Formula.Current.GetTroopSpeed(AttackStub)); TroopObject.EndUpdate(); city.Add(TroopObject); }
public void MoveFromBattleToNormal(CityBattleProcedure cityBattleProcedure, IGlobal global, TroopStub stub) { Global.Current = global; Global.Current.FireEvents.Returns(false); stub.AddFormation(FormationType.Normal); stub.AddFormation(FormationType.Garrison); stub.AddFormation(FormationType.InBattle); stub.AddUnit(FormationType.Normal, 101, 10); cityBattleProcedure.MoveUnitFormation(stub, FormationType.Normal, FormationType.InBattle); cityBattleProcedure.MoveUnitFormation(stub, FormationType.InBattle, FormationType.Normal); Assert.True(stub[FormationType.Normal].Type == FormationType.Normal); Assert.True(stub[FormationType.InBattle].Type == FormationType.InBattle); }