示例#1
0
        public static float TotalHydrationInStockPile(Stockpile s)
        {
            ushort type = ItemTypes.IndexLookup.GetIndex(Blocks.MOD_NAMESPACE + ".WaterBucket");

            //Determine to total value if hydration available
            float results = s.AmountContained(type) * ItemHydrateValue(type);

            Logger.Log("Water amount {0}", s.AmountContained(type));
            Logger.Log("Total Hydration Value = {0}", results);

            return(results);
        }
        /// <summary>
        /// INTERNAL
        /// From gives to items.
        /// </summary>
        /// <param name="from">The player sending the items.</param>
        /// <param name="to">The player recieving the items.</param>
        /// <param name="give">The ItemID of the item given.</param>
        /// <param name="giveamt">How many of the item given.</param>
        public static void tradeGive(Players.Player from, Players.Player to, ushort give, int giveamt)
        {
            Stockpile playerStockpile  = Stockpile.GetStockPile(from);
            Stockpile partnerStockpile = Stockpile.GetStockPile(to);

            string name;
            bool   legalIds = ItemTypes.IndexLookup.TryGetName(give, out name);

            if (!legalIds)
            {
                Chat.Send(from, "Invalid ID's");
                return;
            }

            if (playerStockpile.AmountContained(give) <= giveamt)
            {
                Chat.Send(from, "You can't afford that.");
                return;
            }

            playerStockpile.Remove(give, giveamt);
            partnerStockpile.Add(give, giveamt);
            Chat.Send(from, "You sent " + giveamt + " " + name + " to " + to.Name + ".");
            Chat.Send(to, from.Name + " sent " + giveamt + " " + name + " to you.");
        }
示例#3
0
        private void SplitStockpileOnLeave(Players.Player player)
        {
            Stockpile player_Stockpile      = Stockpile.GetStockPile(player);
            Stockpile fake_player_Stockpile = Stockpile.GetStockPile(fake_player);

            int split = playersOnTeam.Count + 1;

            player_Stockpile._items.Clear();

            for (ushort item = 0; item < ItemTypes.IndexLookup.MaxRegistered; item++)
            {
                int amount = fake_player_Stockpile.AmountContained(item);

                amount = amount / split;
                if (amount > 0)
                {
                    player_Stockpile.Add(item, amount);

                    fake_player_Stockpile.TryRemove(item, amount);
                }
            }

            player.SendStockpileInventory();
            fake_player.SendStockpileInventory();
        }
        /// <summary>
        /// INTERNAL
        /// Trashes items.
        /// </summary>
        /// <param name="item">The ItemID of the item given.</param>
        /// <param name="amount">How many of the item given.</param>
        public static void trashItems(Players.Player player, ushort item, int amount)
        {
            if (Permissions.PermissionsManager.CheckAndWarnPermission(player, "trash"))
            {
                Stockpile playerStockpile = Stockpile.GetStockPile(player);

                string name;
                bool   legalIds = ItemTypes.IndexLookup.TryGetName(item, out name);

                if (!legalIds)
                {
                    Helpers.Chat.sendSilent(player, "Invalid ID's", Helpers.Chat.ChatColour.orange);
                    return;
                }

                int stockPileAmount = playerStockpile.AmountContained(item);
                if (stockPileAmount <= amount)
                {
                    Helpers.Chat.sendSilent(player, "You have less than " + amount + ", trashing all.", Helpers.Chat.ChatColour.orange);
                    amount = stockPileAmount;
                }

                playerStockpile.Remove(item, amount);
                Helpers.Chat.sendSilent(player, String.Format("{0} of item [{1}] trashed.", amount, name), Helpers.Chat.ChatColour.orange);
            }
            else
            {
                Helpers.Chat.sendSilent(player, "Trashing Failed.", Helpers.Chat.ChatColour.red);
            }
        }
        /// <summary>
        /// INTERNAL
        /// From gives to items.
        /// </summary>
        /// <param name="from">The player sending the items.</param>
        /// <param name="to">The player recieving the items.</param>
        /// <param name="give">The ItemID of the item given.</param>
        /// <param name="giveamt">How many of the item given.</param>
        public static void tradeGive(Players.Player from, Players.Player to, ushort give, int giveamt)
        {
            if (getTradeEnabled())
            {
                Stockpile playerStockpile  = Stockpile.GetStockPile(from);
                Stockpile partnerStockpile = Stockpile.GetStockPile(to);

                string name;
                bool   legalIds = ItemTypes.IndexLookup.TryGetName(give, out name);

                if (!legalIds)
                {
                    Helpers.Chat.sendSilent(from, "Invalid ID's", Helpers.Chat.ChatColour.orange);
                    return;
                }

                if (playerStockpile.AmountContained(give) <= giveamt)
                {
                    Helpers.Chat.sendSilent(from, "You can't afford that.", Helpers.Chat.ChatColour.orange);
                    return;
                }

                playerStockpile.Remove(give, giveamt);
                partnerStockpile.Add(give, giveamt);
                Helpers.Chat.sendSilent(from, "You sent " + giveamt + " " + name + " to " + to.Name + ".", Helpers.Chat.ChatColour.orange);
                Helpers.Chat.sendSilent(to, from.Name + " sent " + giveamt + " " + name + " to you.", Helpers.Chat.ChatColour.orange);
            }
            else
            {
                Helpers.Chat.sendSilent(from, "Trade Disabled.", Helpers.Chat.ChatColour.red);
            }
        }
示例#6
0
        public static int UseHydration(float HydrationAmountNeeded, float TotalHydrationValue, Stockpile stockpile)
        {
            int    results = 0;
            ushort type    = ItemTypes.IndexLookup.GetIndex(Blocks.MOD_NAMESPACE + ".WaterBucket");

            //Future add logic to support other Hydration sources.

            //Figure out how many WaterBuckets are needed
            int totalWaterNeeded = Convert.ToInt32(HydrationAmountNeeded / ItemHydrateValue(type));

            Logger.Log("Total WaterBuckets Needed {0}", totalWaterNeeded.ToString());

            //Get the number of WaterBuckets in stockpile
            int totalWaterInStockPile = stockpile.AmountContained(type);

            Logger.Log("Total Water In Stockpile {0}", totalWaterInStockPile);

            //if total needed exceeds total in stockpile then figure out how many colonists do not have water
            if (totalWaterNeeded > totalWaterInStockPile)
            {
                results = Convert.ToInt32(((float)(totalWaterNeeded - totalWaterInStockPile) * ItemHydrateValue(type)) / Configuration.HydrationValuePerColonists);
                Logger.Log("Colonists Dehydrated = {0}", results.ToString());
                totalWaterNeeded = totalWaterInStockPile;
            }

            stockpile.TryRemove(type, totalWaterNeeded);
            Logger.Log("Water to remove = {0}", totalWaterNeeded);

            return(results);
        }
        /// <summary>
        /// INTERNAL
        /// Accepts the trade in player's current playerdata, set the items, and notify the users.
        /// </summary>
        /// <param name="player">The player who is accepting.</param>
        public static void acceptTrade(Players.Player player)
        {
            PlayerData pd = getPlayerData(player);

            if (pd.tradeData == null)
            {
                Chat.Send(Players.GetPlayer(player.ID), "You have no outstanding trade requests.");
                return;
            }

            PlayerData partnerData = pd.tradeData.partner;

            Stockpile playerStockpile = Stockpile.GetStockPile(Players.GetPlayer(player.ID));
            Stockpile partnerStockpile;

            Stockpile.TryGetStockpile(Players.GetPlayer(partnerData.PID), out partnerStockpile);

            if (partnerStockpile != null)
            {
                if (partnerStockpile.AmountContained(pd.tradeData.giveId) <= pd.tradeData.giveAmount)
                {
                    Chat.Send(player, "Your partner can't afford this trade. It will need to be remade.");
                    Chat.Send(Players.GetPlayer(partnerData.PID), "You can't afford your trade with " + player.Name + ". Please get the required items and send another request.");
                    rejectTrade(player, true);
                    return;
                }

                if (playerStockpile.AmountContained(pd.tradeData.takeId) <= pd.tradeData.takeAmount)
                {
                    Chat.Send(player, "You can't afford this trade. Please get the required items or reject the trade.");
                    return;
                }

                playerStockpile.Remove(pd.tradeData.takeId, pd.tradeData.takeAmount);
                partnerStockpile.Remove(pd.tradeData.giveId, pd.tradeData.giveAmount);
                playerStockpile.Add(pd.tradeData.giveId, pd.tradeData.giveAmount);
                partnerStockpile.Add(pd.tradeData.takeId, pd.tradeData.takeAmount);
            }
            else
            {
                Chat.Send(player, "Your partner doesn't exist. Ignoring trade.");
                rejectTrade(player, true);
                return;
            }

            Chat.Send(player, "Trade Accepted.");
            Chat.Send(Players.GetPlayer(partnerData.PID), player.Name + " accepted your trade request.");

            pd.tradeData                    = null;
            partnerData.tradeData           = null;
            playerDataDict[player.ID]       = pd;
            playerDataDict[partnerData.PID] = partnerData;
        }
示例#8
0
        public static ushort GetBestArmorFromStockpile(Stockpile s, ArmorSlot slot, int limit)
        {
            var best = default(ushort);

            foreach (var armor in ArmorLookup.Where(a => a.Value.Slot == slot))
            {
                if (s.Contains(armor.Key) && s.AmountContained(armor.Key) > limit)
                {
                    if (best == default(ushort) || (!armor.Value.IsMagical && armor.Value.ArmorRating > ArmorLookup[best].ArmorRating))
                    {
                        best = armor.Key;
                    }
                }
            }

            return(best);
        }
        public static void SyncronizeStockpile(Players.Player player, Players.Player fake_player)
        {
            Stockpile player_Stockpile      = Stockpile.GetStockPile(player);
            Stockpile fake_player_Stockpile = Stockpile.GetStockPile(fake_player);

            for (ushort item = 0; item < ItemTypes.IndexLookup.MaxRegistered; item++)
            {
                int amount = player_Stockpile.AmountContained(item);

                if (amount > 0)
                {
                    fake_player_Stockpile.Add(item, amount);

                    player_Stockpile.TryRemove(item, amount);
                }
            }
        }
        /// <summary>
        /// INTERNAL
        /// Notifies player to that there is a trade offer from from.
        /// If any of the arguments are invalid it will tell the users that they need to correct them.
        /// </summary>
        /// <param name="from">The player that is sending the request.</param>
        /// <param name="to">The player that is getting sent the request.</param>
        /// <param name="give">The ItemID of the item from is giving away.</param>
        /// <param name="giveamt">How many from is giving to to.</param>
        /// <param name="take">The ItemID of the item from wants from to.</param>
        /// <param name="takeamt">How many from wants from to.</param>
        public static void notifyTrade(Players.Player from, Players.Player to, ushort give, int giveamt, ushort take, int takeamt)
        {
            PlayerData fromPd = getPlayerData(from);
            PlayerData toPd   = getPlayerData(to);

            if (fromPd.tradeData != null || toPd.tradeData != null)
            {
                Chat.Send(from, "Trade to " + to.Name + " failed, you or your trade partner have an outstanding trade.");
                Chat.Send(to, "Trade from " + from.Name + " failed, you or your trade partner have an outstanding trade.");
                return;
            }
            string name;
            bool   legalIds = ItemTypes.IndexLookup.TryGetName(give, out name);

            legalIds = legalIds && ItemTypes.IndexLookup.TryGetName(take, out name);

            if (!legalIds)
            {
                Chat.Send(from, "Invalid ID's");
                return;
            }

            Stockpile fromSP = Stockpile.GetStockPile(from);
            Stockpile toSP   = Stockpile.GetStockPile(to);

            if (fromSP.AmountContained(take) <= takeamt)
            {
                Chat.Send(from, "You can't afford that trade.");
                return;
            }

            fromPd.tradeData = new TradeData(give, giveamt, take, takeamt, ref toPd, true);
            toPd.tradeData   = new TradeData(take, takeamt, give, giveamt, ref fromPd, false);

            Chat.Send(from, "Trade sent to " + to.Name + ":");
            Chat.Send(from, fromPd.tradeData.ToString() + " from " + to.Name);
            Chat.Send(from, "Type '/trade reject' to cancel your trade.");
            Chat.Send(to, "Incoming trade request:");
            Chat.Send(to, toPd.tradeData.ToString() + " from " + from.Name);
            Chat.Send(to, "Type '/trade accept' to accept the trade.");
            Chat.Send(to, "Type '/trade reject' to reject the trade.");

            playerDataDict[from.ID] = fromPd;
            playerDataDict[to.ID]   = toPd;
        }
示例#11
0
        override protected bool RunCommand(Players.Player ply, string[] args, NetworkID target)
        {
            if (PermissionsManager.CheckAndWarnPermission(ply, "cheats.clear"))
            {
                // get their stockpile
                Stockpile s = Stockpile.GetStockPile(ply);

                // Cycle through each item we manage, check how many we have, then remove that.
                foreach (string itemname in ColonyAPI.Managers.TypeManager.AddedTypes)
                {
                    ushort i = ItemTypes.IndexLookup.GetIndex(itemname);
                    s.Remove(i, s.AmountContained(i));
                }

                ColonyAPI.Helpers.Chat.sendSilent(ply, "Cleared Inventory!", ColonyAPI.Helpers.Chat.ChatColour.lime);
            }

            return(true);
        }
示例#12
0
        private bool ProcessCreative(Players.Player id, string chatItem)
        {
            if (PermissionsManager.CheckAndWarnPermission(id, "cheats.clear"))
            {
                // get their stockpile
                Stockpile s = Stockpile.GetStockPile(id);

                // Cycle through each item we manage, check how many we have, then remove that.
                foreach (string itemname in Classes.Managers.TypeManager.AddedTypes)
                {
                    ushort i = ItemTypes.IndexLookup.GetIndex(itemname);
                    s.Remove(i, s.AmountContained(i));
                }

                Chat.Send(id, "Cleared Inventory!", ChatSenderType.Server);
            }


            return(true);
        }
        public bool TryDoCommand(Players.Player causedBy, string chattext, List <string> splits)
        {
            if (!splits[0].Equals("/trash"))
            {
                return(false);
            }
            var m = Regex.Match(chattext, @"/trash (?<material>.+) (?<amount>\d+)");

            if (!m.Success)
            {
                Chat.Send(causedBy, "Command didn't match, use /trash [material] [amount]");
                return(true);
            }
            var    itemTypeName = m.Groups ["material"].Value;
            ushort itemType;

            if (!ItemTypes.IndexLookup.TryGetIndex(itemTypeName, out itemType))
            {
                Chat.Send(causedBy, "Command didn't match, item type not found");
                return(true);
            }
            var removeAmount = Int32.Parse(m.Groups ["amount"].Value);

            if (removeAmount <= 0)
            {
                Chat.Send(causedBy, "Command didn't match, amount too low");
                return(true);
            }

            Colony colony = causedBy.ActiveColony;

            if (colony == null)
            {
                Chat.Send(causedBy, "You have to be near an active colony to use this command");
                return(true);
            }

            // delete from the player's inventory first
            int       totalRemoved    = 0;
            Inventory playerInventory = causedBy.Inventory;

            foreach (var item in playerInventory.Items)
            {
                if (item.Type == itemType)
                {
                    int todoRemove = System.Math.Min(removeAmount, item.Amount);
                    if (playerInventory.TryRemove(item.Type, todoRemove))
                    {
                        removeAmount -= todoRemove;
                        totalRemoved += todoRemove;
                    }
                }
            }

            // then delete from the stockpile
            Stockpile playerStockpile = colony.Stockpile;

            if (playerStockpile == null)
            {
                Chat.Send(causedBy, "Could not get stockpile");
            }
            else
            {
                var actualAmount = System.Math.Min(playerStockpile.AmountContained(itemType), removeAmount);
                if (playerStockpile.TryRemove(itemType, actualAmount))
                {
                    totalRemoved += actualAmount;
                    Chat.Send(causedBy, $"Trashed {totalRemoved} x {ItemTypes.IndexLookup.GetName (itemType)}");
                }
                else
                {
                    Chat.Send(causedBy, $"Not enough items in stockpile");
                }
            }

            if (totalRemoved > 0)
            {
                // causedBy.ShouldSave = true;
            }

            return(true);
        }
示例#14
0
        void CheckItemAmount(Stockpile stockpile, ushort itemType, int minAmount)
        {
            var missing = minAmount - stockpile.AmountContained(itemType);

            stockpile.Add(itemType, missing);
        }