Exemple #1
0
        public void Damage()
        {
            // Destroy random component
            int total = 0;

            foreach (Item itm in Installed)
            {
                total += itm.Amount;
            }
            if (total == 0)
            {
                return;
            }
            int idx = Constants.Random(total);

            for (int i = 0; i < Installed.Count; i++)
            {
                idx -= Installed[i].Amount;
                if (idx > 0)
                {
                    continue;
                }
                Installed.RemoveItems(Installed[i].Type, 1);
                break;
            }

            // If first components spent, collapse
            if (Installed.Count == 0 ||
                (Type.Materials.Count > 0 && Installed.GetByType(Type.Materials[0].Type) == null))
            {
                Collapse();
            }
        }
Exemple #2
0
        public void TakeItem(Battle btl, Soldier s, ItemList equipment, ItemType it)
        {
            Item itm = equipment.GetByType(it);

            if (itm == null)
            {
                return;
            }

            // Get weapon
            if (itm.Type.IsWeapon && Weapon == null)
            {
                // Check skill
                if (itm.Type.WeaponSkill == null)
                {
                    throw new Exception("Weapon should have WeaponSkill");
                }
                Skill sk = Person.Skills.GetByType(itm.Type.WeaponSkill);
                if (sk == null)
                {
                    return;
                }

                // Check ammo
                if (itm.Type.Ammo != null)
                {
                    Item ammo = s.Person.Items.GetByType(itm.Type.Ammo);
                    if (ammo != null)
                    {
                        Ammo = ammo.Amount;
                    }
                    if (Ammo == 0)
                    {
                        return;
                    }
                }

                // Get the weapon
                Weapon     = itm.Type;
                SkillLevel = sk.Level;
                if (itm.Type.Heavy && btl != null)
                {
                    if (btl.TakenHwpn[itm] == null)
                    {
                        btl.TakenHwpn[itm] = 1;
                    }
                    else
                    {
                        btl.TakenHwpn[itm] = (int)btl.TakenHwpn[itm] + 1;
                    }
                }
            }

            // Get armor
            if (itm.Type.IsArmor && Armor == null)
            {
                Armor = itm.Type;
            }
        }
Exemple #3
0
        private void CollectSpoils(Region r, bool draw, Side winner)
        {
            ArrayList spoil_lists = new ArrayList();

            spoil_lists.Add(Spoils);
            foreach (Soldier s in Soldiers)
            {
                if (s.OutOfAction && !s.FleedAway)
                {
                    if (s.Person.Killed)
                    {
                        // If person killed, add items to Spoils
                        for (int i = s.Person.Items.Count - 1; i >= 0; i--)
                        {
                            Item itm = s.Person.Items[i];
                            if (!itm.Type.NoGive)
                            {
                                s.Person.Items.RemoveAt(i);
                                Spoils.AddItems(itm.Type, itm.Amount);
                            }
                        }
                    }
                    else
                    if (!draw && s.Side != winner)
                    {
                        // If person stunned, allow to marauder givable items from it
                        spoil_lists.Add(s.Person.Items);
                    }
                }

                // If person killed, drop "drops" to Spoils
                if (s.OutOfAction && s.Person.Killed && s.Person.Man.Drops.Count > 0)
                {
                    foreach (Item itm in s.Person.Man.Drops)
                    {
                        Spoils.AddItems(itm.Type, itm.Amount);
                    }
                }
            }

            if (!draw)
            {
                foreach (Soldier s in Soldiers)
                {
                    if (s.OutOfAction)
                    {
                        continue;
                    }
                    int      space = s.Person.GetCapacity(Movement.Walk) - s.Person.GetWeight();
                    ItemList taken = new ItemList();

                    // Get item requested in spoils
                    if (s.Person.Spoils.Count > 0)
                    {
                        foreach (ItemType wanted in s.Person.Spoils)
                        {
                            if (wanted.NoGive)
                            {
                                continue;
                            }

                            for (int i = spoil_lists.Count - 1; i >= 0; i--)
                            {
                                ItemList list = (ItemList)spoil_lists[i];
                                Item     item = list.GetByType(wanted);
                                if (item == null)
                                {
                                    continue;
                                }
                                int amt;
                                if (item.Type.Weight == 0)
                                {
                                    amt = Math.Min(item.Amount, Constants.Random(20));
                                }
                                else
                                {
                                    amt = Math.Min(item.Type.Weight * item.Amount, space) / item.Type.Weight;
                                }
                                if (amt == 0)
                                {
                                    continue;
                                }
                                s.Person.Items.AddItems(item.Type, amt);
                                space -= item.Type.Weight * amt;
                                list.RemoveItems(item.Type, amt);
                                if (list.Count == 0)
                                {
                                    spoil_lists.Remove(list);
                                }
                                taken.AddItems(item.Type, amt);
                            }

                            if (taken.Count > 0)
                            {
                                break;
                            }
                        }
                    }

                    // Get random items from spoils (as much as soldier can carry)
                    if (taken.Count == 0)
                    {
                        int attempt = 0;
                        while (attempt < 2)
                        {
                            if (spoil_lists.Count == 0)
                            {
                                break;
                            }
                            int      list_idx = Constants.Random(spoil_lists.Count);
                            ItemList givable  = new ItemList();
                            foreach (Item itm in (ItemList)spoil_lists[list_idx])
                            {
                                if (!itm.Type.NoGive)
                                {
                                    givable.Add(itm);
                                }
                            }
                            if (givable.Count == 0)
                            {
                                spoil_lists.RemoveAt(list_idx);
                                continue;
                            }
                            int  item_idx = Constants.Random(givable.Count);
                            Item item     = givable[item_idx];
                            int  amt;
                            if (item.Type.Weight == 0)
                            {
                                amt = Math.Min(item.Amount, Constants.Random(20));
                            }
                            else
                            {
                                amt = Math.Min(item.Type.Weight * item.Amount, space) / item.Type.Weight;
                            }
                            if (amt > 0)
                            {
                                s.Person.Items.AddItems(item.Type, amt);
                                space -= item.Type.Weight * amt;
                                ((ItemList)spoil_lists[list_idx]).RemoveItems(item.Type, amt);
                                taken.AddItems(item.Type, amt);
                            }
                            attempt++;
                        }
                    }

                    if (taken.Count > 0)
                    {
                        BattleReport.Add(String.Format("{0} takes {1}|{2} берёт: {3}",
                                                       s.Person.ToString(Lang.En), taken.ToString(Lang.En),
                                                       s.Person.ToString(Lang.Ru), taken.ToString(Lang.Ru)));
                    }
                }
            }

            // Add untaken spoils to Junk
            for (int i = Spoils.Count - 1; i >= 0; i--)
            {
                r.Junk.AddItems(Spoils[i].Type, Spoils[i].Amount);
            }
        }