private void GetInfo(Session session, Packet packet) { var reply = new Packet(packet); uint strongholdId; try { strongholdId = packet.GetUInt32(); } catch (Exception) { ReplyError(session, packet, Error.Unexpected); return; } if (session.Player.Tribesman == null) { ReplyError(session, packet, Error.TribeIsNull); return; } IStronghold stronghold; if (!strongholdManager.TryGetStronghold(strongholdId, out stronghold)) { ReplyError(session, packet, Error.StrongholdNotFound); return; } locker.Lock(stronghold).Do(() => { PacketHelper.AddStrongholdProfileToPacket(session, stronghold, reply); session.Write(reply); }); }
private string CmdStrongholdAddTroop(Session session, string[] parms) { bool help = false; string strongholdName = string.Empty; string cityName = string.Empty; try { var p = new OptionSet { { "?|help|h", v => help = true }, { "stronghold=", v => strongholdName = v.TrimMatchingQuotes() }, { "city=", v => cityName = v.TrimMatchingQuotes() }, }; p.Parse(parms); } catch (Exception) { help = true; } if (help || string.IsNullOrEmpty(strongholdName) || string.IsNullOrEmpty(cityName)) { return("StrongholdAddTroop --stronghold=tribe_name --city=city_name"); } uint cityId; if (!world.Cities.FindCityId(cityName, out cityId)) { return("City not found"); } ICity city; if (!world.TryGetObjects(cityId, out city)) { return("City not found"); } IStronghold stronghold; if (!strongholdManager.TryGetStronghold(strongholdName, out stronghold)) { return("Stronghold not found"); } return(locker.Lock(city, stronghold).Do(() => { if (city.DefaultTroop.Upkeep == 0) { return "No troops in the city!"; } ITroopStub stub = city.CreateTroopStub(); stub.BeginUpdate(); stub.AddFormation(FormationType.Defense); foreach (var unit in city.DefaultTroop[FormationType.Normal]) { stub.AddUnit(FormationType.Defense, unit.Key, unit.Value); } stub.Template.LoadStats(TroopBattleGroup.Defense); stub.EndUpdate(); if (!stronghold.Troops.AddStationed(stub)) { return "Error Adding to Station"; } return "OK!"; })); }
public bool TryGetObjects(uint strongholdId, out IStronghold stronghold) { return(strongholds.TryGetStronghold(strongholdId, out stronghold)); }
private void CreateStrongholdAssignment(Session session, Packet packet) { uint cityId; uint strongholdId; AttackMode mode; DateTime time; ISimpleStub simpleStub; string description; bool isAttack; try { mode = (AttackMode)packet.GetByte(); cityId = packet.GetUInt32(); strongholdId = packet.GetUInt32(); time = DateTime.UtcNow.AddSeconds(packet.GetInt32()); isAttack = packet.GetByte() == 1; simpleStub = PacketHelper.ReadStub(packet, isAttack ? FormationType.Attack : FormationType.Defense); description = packet.GetString(); } catch (Exception) { ReplyError(session, packet, Error.Unexpected); return; } IStronghold stronghold; if (!strongholdManager.TryGetStronghold(strongholdId, out stronghold)) { ReplyError(session, packet, Error.StrongholdNotFound); return; } ICity city; if (!cityManager.TryGetCity(cityId, out city)) { ReplyError(session, packet, Error.StrongholdNotFound); return; } // First need to find all the objects that should be locked locker.Lock(city, stronghold).Do(() => { if (city == null || stronghold == null) { ReplyError(session, packet, Error.Unexpected); return; } // Make sure city belongs to player and he is in a tribe if (city.Owner != session.Player || city.Owner.Tribesman == null) { ReplyError(session, packet, Error.Unexpected); return; } // Make sure this player is ranked high enough if (city.Owner.Tribesman == null || !city.Owner.Tribesman.Tribe.HasRight(city.Owner.PlayerId, TribePermission.AssignmentCreate)) { ReplyError(session, packet, Error.TribesmanNotAuthorized); return; } int id; Error ret = session.Player.Tribesman.Tribe.CreateAssignment(city, simpleStub, stronghold.PrimaryPosition.X, stronghold.PrimaryPosition.Y, stronghold, time, mode, description, isAttack, out id); ReplyWithResult(session, packet, ret); }); }