Ejemplo n.º 1
0
 private void AddToNormal(ITroopStub source, ITroopStub target)
 {
     target.BeginUpdate();
     foreach (var unit in source.SelectMany(formation => formation))
     {
         target.AddUnit(FormationType.Normal, unit.Key, unit.Value);
     }
     target.EndUpdate();
 }
Ejemplo n.º 2
0
        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!";
            }));
        }
Ejemplo n.º 3
0
        private string AssignmentJoin(Session session, string[] parms)
        {
            bool   help     = false;
            string cityName = string.Empty;
            int    id       = int.MaxValue;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "city=", v => cityName = v.TrimMatchingQuotes() },
                    { "id=", v => id = int.Parse(v) },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(cityName) || id == int.MaxValue)
            {
                return("AssignementCreate --city=city_name --id=id");
            }

            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!");
            }

            if (city.Owner.Tribesman == null)
            {
                return("Not in tribe");
            }

            ITribe tribe = city.Owner.Tribesman.Tribe;

            return(locker.Lock(city, tribe).Do(() =>
            {
                if (city.DefaultTroop.Upkeep == 0)
                {
                    return "No troops in the city!";
                }

                Assignment assignment = tribe.Assignments.FirstOrDefault(x => x.Id == id);

                if (assignment == null)
                {
                    return "Assignment not found";
                }

                // TODO: Clean this up.. shouldnt really need to do this here
                ITroopStub stub = city.CreateTroopStub();
                FormationType formation = assignment.IsAttack ? FormationType.Attack : FormationType.Defense;
                stub.AddFormation(formation);
                foreach (var unit in city.DefaultTroop[FormationType.Normal])
                {
                    stub.AddUnit(formation, unit.Key, unit.Value);
                }

                Error error = tribe.JoinAssignment(id, city, stub);
                if (error != Error.Ok)
                {
                    return Enum.GetName(typeof(Error), error);
                }

                return string.Format("OK");
            }));
        }