Ejemplo n.º 1
0
        public static Order ParseOrder(Person person, Faction faction, string command, string arguments)
        {
            Order order;

            switch (command)
            {
            case "address":
                order = new AddressOrder(arguments);
                break;

            case "attack":
                order = new AttackOrder(arguments);
                break;

            case "avoid":
                order = new AvoidOrder(arguments);
                break;

            case "build":
                order = new BuildOrder(arguments);
                break;

            case "burn":
                order = new BurnOrder(arguments);
                break;

            case "consume":
                order = new ConsumeOrder(person, arguments);
                break;

            case "cure":
                order = new CureOrder(arguments);
                break;

            case "declare":
                order = new DeclareOrder(faction, arguments);
                break;

            case "describe":
                order = new DescribeOrder(arguments);
                break;

            case "drive":
                order = new DriveOrder(arguments);
                break;

            case "enter":
                order = new EnterOrder(arguments);
                break;

            case "equipment":
                order = new EquipmentOrder(arguments);
                break;

            case "evict":
                order = new EvictOrder(arguments);
                break;

            case "give":
                order = new GiveOrder(arguments);
                break;

            case "greedy":
                order = new GreedyOrder(arguments);
                break;

            case "hide":
                order = new HideOrder(arguments);
                break;

            case "install":
                order = new InstallOrder(arguments);
                break;

            case "kick":
                order = new KickOrder();
                break;

            case "leave":
                order = new LeaveOrder();
                break;

            case "move":
                order = new MoveOrder(arguments);
                break;

            case "name":
                order = new NameOrder(arguments);
                break;

            case "option":
                order = new OptionOrder(arguments);
                break;

            case "password":
                order = new PasswordOrder(arguments);
                break;

            case "patrol":
                order = new PatrolOrder();
                break;

            case "produce":
                order = new ProduceOrder(arguments);
                break;

            case "quit":
                order = new QuitOrder(faction, arguments);
                break;

            case "scavenge":
                order = new ScavengeOrder(arguments);
                break;

            case "show":
                order = new ShowOrder(arguments);
                break;

            case "spoils":
                order = new SpoilsOrder(arguments);
                break;

            case "team":
                order = new TeamOrder(arguments);
                break;

            case "trade":
                order = new TradeOrder(arguments);
                break;

            case "uninstall":
                order = new UninstallOrder(arguments);
                break;

            default:
                throw new Exception("Bad order " + command);
            }
            return(order);
        }
Ejemplo n.º 2
0
        private void Init(PersonArrayList attackers, Person defender, Region region)
        {
            Soldiers = new ArrayList();
            ArrayList check_persons = new ArrayList();

            this.region = region;

            // Add attackers and their teams
            foreach (Person attacker in attackers)
            {
                foreach (Person atk in attacker.GetTeamAndLeader())
                {
                    if (check_persons.Contains(atk))
                    {
                        throw new Exception("Soldier already added");
                    }
                    check_persons.Add(atk);

                    Soldiers.Add(new Soldier(this, atk, Side.Attacker));
                    FirstDefender++;
                }
            }

            // Add target person and his team
            if (defender.Leader != null)
            {
                foreach (Person def in defender.Leader.GetTeamAndLeader())
                {
                    if (check_persons.Contains(def))
                    {
                        throw new Exception("Soldier already added");
                    }
                    check_persons.Add(def);

                    Soldiers.Add(new Soldier(this, def, Side.Defender));
                }
            }
            else
            {
                foreach (Person def in defender.GetTeamAndLeader())
                {
                    if (check_persons.Contains(def))
                    {
                        throw new Exception("Soldier already added");
                    }
                    check_persons.Add(def);

                    Soldiers.Add(new Soldier(this, def, Side.Defender));
                }
            }

            // Add region patrol
            foreach (Person patrol in defender.Region.Persons)
            {
                if (patrol.Leader == null && patrol.Patrolling &&
                    patrol.AttitudeTo(defender) == Attitude.Ally &&
                    !defender.GetTeamAndLeader().Contains(patrol))
                {
                    foreach (Person soldier in patrol.GetTeamAndLeader())
                    {
                        if (check_persons.Contains(soldier))
                        {
                            throw new Exception("Soldier already added");
                        }
                        check_persons.Add(soldier);

                        Soldiers.Add(new Soldier(this, soldier, Side.Defender));
                    }
                }
            }

            // Remove from attackers all further ATTACK orders directed on defenders
            for (int i = 0; i < FirstDefender; i++)
            {
                Person p = ((Soldier)Soldiers[i]).Person;
                foreach (Order ord in p.Orders)
                {
                    if (ord.GetType() == typeof(AttackOrder))
                    {
                        AttackOrder aord = (AttackOrder)ord;
                        for (int k = FirstDefender; k < Soldiers.Count; k++)
                        {
                            if (aord.PersonNum == ((Soldier)Soldiers[k]).Person.Num)
                            {
                                aord.PersonNum = -1;
                                break;
                            }
                        }
                    }
                }
            }

            BattleReport.Add(
                String.Format("{0} attacks {1} in {2}!",
                              attackers[0].ToString(Lang.En),
                              defender.ToString(Lang.En),
                              region.ToString(Lang.En)) +
                String.Format("|{2}: {0} и {1} вступили в бой!",
                              attackers[0].ToString(Lang.Ru),
                              defender.ToString(Lang.Ru),
                              region.ToString(Lang.Ru)));

            region.BattleReports.Add(BattleReport);

            BattleReport.Add("");
            BattleReport.Add("Attackers:|Атакующие:");
            for (int i = 0; i < FirstDefender; i++)
            {
                PrintSoldier((Soldier)Soldiers[i]);
            }
            BattleReport.Add("");
            BattleReport.Add("Defenders:|Защитники:");
            for (int i = FirstDefender; i < Soldiers.Count; i++)
            {
                PrintSoldier((Soldier)Soldiers[i]);
            }

            this.Run();

            // Promote skills
            foreach (Soldier s in Soldiers)
            {
                if (!s.Person.Killed && s.Person.Leader == null)
                {
                    s.PromoteSkill();
                }
            }

            BattleReport.Add("");
            if (AttackersOOA == FirstDefender)
            {
                BattleReport.Add(String.Format("{0} wins.|{1} побеждает.",
                                               defender.ToString(Lang.En), defender.ToString(Lang.Ru)));
                CollectSpoils(region, false, Side.Defender);
                DefendersWin = true;
            }
            else if (DefendersOOA == Soldiers.Count - FirstDefender)
            {
                BattleReport.Add(String.Format("{0} wins.|{1} побеждает.",
                                               attackers[0].ToString(Lang.En), attackers[0].ToString(Lang.Ru)));
                CollectSpoils(region, false, Side.Attacker);
                AttackersWin = true;
            }
            else
            {
                BattleReport.Add("The battle is a draw.|Бой закончен вничью.");
                CollectSpoils(region, true, Side.Attacker);
            }
        }