示例#1
0
        public void FillWith(Mobile from, BaseResourceBoard board)
        {
            int need = RequiredBoards - CurrentBoards;

            int toAdd = Math.Min(need, board.Amount);

            CurrentBoards += toAdd;

            board.Amount -= need;

            if (board.Amount <= 0)
            {
                board.Delete();
            }

            if (CurrentBoards < RequiredBoards || CurrentIngots < RequiredIngots)
            {
                from.SendMessage("You have added {0} boards to the plan.", toAdd);
            }
            else
            {
                from.SendMessage("The filled plans have been added to your backpack.");
                from.AddToBackpack(FilledPlans);
                Delete();
            }
        }
        public void UseRepairMaterials(BaseShip ship, Mobile from, DamageType damageType)
        {
            switch (damageType)
            {
            case DamageType.Hull:
            {
                int boardsUsed          = 0;
                int boardsNeeded        = 0;
                int repairAmount        = ship.MaxHitPoints - ship.HitPoints;
                int maximumRepairAmount = (int)((double)ship.MaxHitPoints * BaseShip.HullRepairPercent);

                if (repairAmount > maximumRepairAmount)
                {
                    repairAmount = maximumRepairAmount;
                }

                boardsNeeded = (int)((double)repairAmount * BaseShip.RepairMaterialFactor);

                if (boardsNeeded < 0)
                {
                    boardsNeeded = 1;
                }

                Item[] playerBoards = from.Backpack.FindItemsByType(typeof(BaseResourceBoard));
                Item[] holdBoards   = ship.Hold.FindItemsByType(typeof(BaseResourceBoard));

                foreach (Item item in playerBoards)
                {
                    if (boardsNeeded <= 0)
                    {
                        return;
                    }

                    BaseResourceBoard board = item as BaseResourceBoard;

                    if (board.Amount > boardsNeeded)
                    {
                        board.Amount -= boardsNeeded;
                        boardsNeeded  = 0;
                    }

                    else
                    {
                        boardsNeeded -= board.Amount;
                        board.Delete();
                    }
                }

                foreach (Item item in holdBoards)
                {
                    if (boardsNeeded <= 0)
                    {
                        return;
                    }

                    BaseResourceBoard board = item as BaseResourceBoard;

                    if (board.Amount > boardsNeeded)
                    {
                        board.Amount -= boardsNeeded;
                        boardsNeeded  = 0;
                    }

                    else
                    {
                        boardsNeeded -= board.Amount;
                        board.Delete();
                    }
                }

                break;
            }

            case DamageType.Sails:
            {
                int clothUsed           = 0;
                int clothNeeded         = 0;
                int repairAmount        = ship.MaxSailPoints - ship.SailPoints;
                int maximumRepairAmount = (int)((double)ship.MaxSailPoints * BaseShip.HullRepairPercent);

                if (repairAmount > maximumRepairAmount)
                {
                    repairAmount = maximumRepairAmount;
                }

                clothNeeded = (int)((double)repairAmount * BaseShip.RepairMaterialFactor);

                if (clothNeeded < 0)
                {
                    clothNeeded = 1;
                }

                Item[] playerCloth = from.Backpack.FindItemsByType(typeof(Cloth));
                Item[] holdCloth   = ship.Hold.FindItemsByType(typeof(Cloth));

                foreach (Item item in playerCloth)
                {
                    if (clothNeeded <= 0)
                    {
                        return;
                    }

                    Cloth cloth = item as Cloth;

                    if (cloth.Amount > clothNeeded)
                    {
                        cloth.Amount -= clothNeeded;
                        clothNeeded   = 0;
                    }

                    else
                    {
                        clothNeeded -= cloth.Amount;
                        cloth.Delete();
                    }
                }

                foreach (Item item in holdCloth)
                {
                    if (clothNeeded <= 0)
                    {
                        return;
                    }

                    Cloth cloth = item as Cloth;

                    if (cloth.Amount > clothNeeded)
                    {
                        cloth.Amount -= clothNeeded;
                        clothNeeded   = 0;
                    }

                    else
                    {
                        clothNeeded -= cloth.Amount;
                        cloth.Delete();
                    }
                }

                break;
            }


            case DamageType.Guns:
            {
                int ironIngotsUsed      = 0;
                int ironIngotsNeeded    = 0;
                int repairAmount        = ship.MaxGunPoints - ship.GunPoints;
                int maximumRepairAmount = (int)((double)ship.MaxGunPoints * BaseShip.HullRepairPercent);

                if (repairAmount > maximumRepairAmount)
                {
                    repairAmount = maximumRepairAmount;
                }

                ironIngotsNeeded = (int)((double)repairAmount * BaseShip.RepairMaterialFactor);

                if (ironIngotsNeeded < 0)
                {
                    ironIngotsNeeded = 1;
                }

                Item[] playerIronIngots = from.Backpack.FindItemsByType(typeof(IronIngot));
                Item[] holdIronIngots   = ship.Hold.FindItemsByType(typeof(IronIngot));

                foreach (Item item in playerIronIngots)
                {
                    if (ironIngotsNeeded <= 0)
                    {
                        return;
                    }

                    IronIngot ironIngot = item as IronIngot;

                    if (ironIngot.Amount > ironIngotsNeeded)
                    {
                        ironIngot.Amount -= ironIngotsNeeded;
                        ironIngotsNeeded  = 0;
                    }

                    else
                    {
                        ironIngotsNeeded -= ironIngot.Amount;
                        ironIngot.Delete();
                    }
                }

                foreach (Item item in holdIronIngots)
                {
                    if (ironIngotsNeeded <= 0)
                    {
                        return;
                    }

                    IronIngot ironIngot = item as IronIngot;

                    if (ironIngot.Amount > ironIngotsNeeded)
                    {
                        ironIngot.Amount -= ironIngotsNeeded;
                        ironIngotsNeeded  = 0;
                    }

                    else
                    {
                        ironIngotsNeeded -= ironIngot.Amount;
                        ironIngot.Delete();
                    }
                }

                break;
            }
            }
        }
        public bool CheckRepairMaterials(BaseShip ship, Mobile from, DamageType damageType)
        {
            if (ship == null)
            {
                return(false);
            }

            if (from == null)
            {
                return(false);
            }

            if (damageType == null)
            {
                return(false);
            }

            switch (damageType)
            {
            case DamageType.Hull:
            {
                int totalBoards  = 0;
                int boardsNeeded = (int)((double)ship.MaxHitPoints * BaseShip.HullRepairPercent * BaseShip.RepairMaterialFactor);

                Item[] playerBoards = from.Backpack.FindItemsByType(typeof(BaseResourceBoard));
                Item[] holdBoards   = ship.Hold.FindItemsByType(typeof(BaseResourceBoard));

                foreach (Item item in playerBoards)
                {
                    BaseResourceBoard board = item as BaseResourceBoard;
                    totalBoards += board.Amount;
                }

                foreach (Item item in holdBoards)
                {
                    BaseResourceBoard board = item as BaseResourceBoard;
                    totalBoards += board.Amount;
                }

                if (totalBoards > boardsNeeded)
                {
                    return(true);
                }

                break;
            }

            case DamageType.Sails:
            {
                int totalCloth  = 0;
                int clothNeeded = (int)((double)ship.MaxHitPoints * BaseShip.SailRepairPercent * BaseShip.RepairMaterialFactor);

                Item[] playerCloth = from.Backpack.FindItemsByType(typeof(Cloth));
                Item[] holdCloth   = ship.Hold.FindItemsByType(typeof(Cloth));

                foreach (Item item in playerCloth)
                {
                    Cloth cloth = item as Cloth;
                    totalCloth += cloth.Amount;
                }

                foreach (Item item in holdCloth)
                {
                    Cloth cloth = item as Cloth;
                    totalCloth += cloth.Amount;
                }

                if (totalCloth > clothNeeded)
                {
                    return(true);
                }

                break;
            }

            case DamageType.Guns:
            {
                int totalIronIngots  = 0;
                int ironIngotsNeeded = (int)((double)ship.MaxHitPoints * BaseShip.GunRepairPercent * BaseShip.RepairMaterialFactor);

                Item[] playerIronIngots = from.Backpack.FindItemsByType(typeof(IronIngot));
                Item[] holdIronIngots   = ship.Hold.FindItemsByType(typeof(IronIngot));

                foreach (Item item in playerIronIngots)
                {
                    IronIngot ironIngot = item as IronIngot;
                    totalIronIngots += ironIngot.Amount;
                }

                foreach (Item item in holdIronIngots)
                {
                    IronIngot ironIngot = item as IronIngot;
                    totalIronIngots += ironIngot.Amount;
                }

                if (totalIronIngots > ironIngotsNeeded)
                {
                    return(true);
                }

                break;
            }
            }

            return(false);
        }