public void CanWatchBattle_WhenPlayerIsTribesmateFromOwningTribe_ShouldReturnErrorOk( IPlayer player, IStronghold stronghold, IFixture fixture) { player.IsInTribe.Returns(true); player.Tribesman.Tribe.Id.Returns <uint>(123); stronghold.StrongholdState = StrongholdState.Occupied; stronghold.BelongsTo(player.Tribesman.Tribe).Returns(true); fixture.Register(() => new BattleLocation(BattleLocationType.Stronghold, 100)); var gameObjectLocator = fixture.Freeze <IGameObjectLocator>(); IStronghold outStronghold; gameObjectLocator.TryGetObjects(100, out outStronghold).Returns(args => { args[1] = stronghold; return(true); }); var battleManager = fixture.Create <StrongholdMainBattleManager>(); IEnumerable <string> errorParams; battleManager.CanWatchBattle(player, out errorParams).Should().Be(Error.Ok); }
public static void AddStrongholdProfileToPacket(Session session, IStronghold stronghold, Packet packet) { if (!session.Player.IsInTribe || !stronghold.BelongsTo(session.Player.Tribesman.Tribe)) { packet.AddByte(0); packet.AddUInt32(stronghold.PrimaryPosition.X); packet.AddUInt32(stronghold.PrimaryPosition.Y); } else { packet.AddByte(1); packet.AddUInt32(stronghold.ObjectId); packet.AddString(stronghold.Name); packet.AddByte(stronghold.Lvl); packet.AddFloat((float)stronghold.Gate); packet.AddInt32(stronghold.GateMax); packet.AddFloat((float)stronghold.VictoryPointRate); packet.AddUInt32(UnixDateTime.DateTimeToUnix(stronghold.DateOccupied.ToUniversalTime())); packet.AddUInt32(stronghold.PrimaryPosition.X); packet.AddUInt32(stronghold.PrimaryPosition.Y); AddToPacket(stronghold.State, packet); packet.AddUInt16(stronghold.Troops.Size); foreach (var troop in stronghold.Troops) { packet.AddUInt32(troop.City.Owner.PlayerId); packet.AddUInt32(troop.City.Id); packet.AddString(troop.City.Owner.Name); packet.AddString(troop.City.Name); packet.AddUInt16(troop.TroopId); //Actual formation and unit counts packet.AddByte(troop.FormationCount); foreach (var formation in troop) { packet.AddByte((byte)formation.Type); packet.AddByte((byte)formation.Count); foreach (var kvp in formation) { packet.AddUInt16(kvp.Key); packet.AddUInt16(kvp.Value); } } } } }