Esempio n. 1
0
    public override void OnDisabledActivate()
    {
        ItemActionEntryResharpenSDX.StateTypes stateTypes = this.state;
        if (stateTypes != ItemActionEntryResharpenSDX.StateTypes.NotEnoughMaterials)
        {
            return;
        }
        GameManager.ShowTooltip(base.ItemController.xui.playerUI.entityPlayer, this.lblNeedMaterials);
        ItemClass forId = ItemClass.GetForId(((XUiC_ItemStack)base.ItemController).ItemStack.itemValue.type);

        if (forId.Properties.Contains("SharpenItem"))
        {
            String strSharpenItem = String.Empty;
            forId.Properties.ParseString("SharpenItem", ref strSharpenItem);
            if (String.IsNullOrEmpty(strSharpenItem))
            {
                return;
            }
            ItemClass itemClass = ItemClass.GetItemClass(strSharpenItem, false);
            if (itemClass != null)
            {
                ItemStack @is = new ItemStack(new ItemValue(itemClass.Id, false), 0);
                base.ItemController.xui.playerUI.entityPlayer.AddUIHarvestingItem(@is, true);
            }
        }
    }
Esempio n. 2
0
    public static void RemoveRadiusEffect(String strItemClass, ref Block myBlock)
    {
        ItemClass itemClass = ItemClass.GetItemClass(strItemClass, false);

        if (itemClass.Properties.Values.ContainsKey("ActivatedBuff"))
        {
            String   strBuff = itemClass.Properties.Values["ActivatedBuff"];
            string[] array5  = strBuff.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

            // Grab the current radius effects
            List <BlockRadiusEffect> list2 = myBlock.RadiusEffects.OfType <BlockRadiusEffect>().ToList();
            foreach (string text4 in array5)
            {
                int num12 = text4.IndexOf('(');
                int num13 = text4.IndexOf(')');
                BlockRadiusEffect item = default(BlockRadiusEffect);
                if (num12 != -1 && num13 != -1 && num13 > num12 + 1)
                {
                    item.radius   = StringParsers.ParseFloat(text4.Substring(num12 + 1, num13 - num12 - 1), 0, -1, NumberStyles.Any);
                    item.variable = text4.Substring(0, num12);
                }
                else
                {
                    item.radius   = 1f;
                    item.variable = text4;
                }
                if (list2.Contains(item))
                {
                    list2.Remove(item);
                }
            }

            myBlock.RadiusEffects = list2.ToArray();
        }
    }
Esempio n. 3
0
    public override void RefreshEnabled()
    {
        base.RefreshEnabled();
        this.state = ItemActionEntryResharpenSDX.StateTypes.Normal;
        XUi xui = base.ItemController.xui;

        if (((XUiC_ItemStack)base.ItemController).ItemStack.IsEmpty() || ((XUiC_ItemStack)base.ItemController).StackLock)
        {
            return;
        }
        ItemClass forId = ItemClass.GetForId(((XUiC_ItemStack)base.ItemController).ItemStack.itemValue.type);

        base.Enabled = (this.state == ItemActionEntryResharpenSDX.StateTypes.Normal);
        if (!base.Enabled)
        {
            base.IconName = "ui_game_symbol_book";
            return;
        }
        ItemValue itemValue = ((XUiC_ItemStack)base.ItemController).ItemStack.itemValue;

        if (forId.RepairTools != null && forId.RepairTools.Length > 0)
        {
            ItemClass itemClass = ItemClass.GetItemClass(forId.RepairTools[0].Value, false);
            if (itemClass != null)
            {
                int b = Convert.ToInt32(Math.Ceiling((double)((float)Mathf.CeilToInt(itemValue.UseTimes) / (float)itemClass.RepairAmount.Value)));
                xui.PlayerInventory.GetItemCount(new ItemValue(itemClass.Id, false));
                if (Mathf.Min(xui.PlayerInventory.GetItemCount(new ItemValue(itemClass.Id, false)), b) * itemClass.RepairAmount.Value <= 0)
                {
                    this.state   = ItemActionEntryResharpenSDX.StateTypes.NotEnoughMaterials;
                    base.Enabled = (this.state == ItemActionEntryResharpenSDX.StateTypes.Normal);
                }
            }
        }
    }
Esempio n. 4
0
    /*
     *  1: petite explo (mine qui pete, small smoke trail only, no fire)
     *  2: med/Large explo orange / rouge + etincelles (pas vraiment explo)
     *  3: redish fire, flamme rouge montante + bcp black smoke
     *  4: redish idem, larger
     *  5: yellow/orange expl, +bcp black smoke
     *  6 :idem
     *  7: vomit, 8: gore block explo
     *  9: like 6
     *
     *  10: molotov (fire ball when in the air)
     *  11-12: yellow etincelles only, no smoke
     *  13: orange boom no smoke, like 1
     *  14-19: crée un bout de bidons détruit
     *  14: le bout part en l'air avec une trainée de flamme ("napalm")
     *  15/ 16: additionnal "napalm"
     */

    public override void Execute(List <string> _params, CommandSenderInfo _senderInfo)
    {
        Printer.Print("ConsoleCmdExplShowExplo", _params);
        EntityPlayerLocal player = GameManager.Instance.World.GetLocalPlayers()[0];

        if (_params[0] == "p")
        {
            Color color = Color.white;
            if (_params.Count >= 3)
            {
                string[] split = _params[2].Split(',');
                float[]  def   = new float[] { 0, 0, 0, 1 };
                for (int k = 0; k < split.Length; k++)
                {
                    def[k] = float.Parse(split[k]);
                }
                color = new Color(def[0], def[1], def[2], def[3]);
            }
            Printer.Print(color);
            ExecuteParticle(_params[1], player.GetPosition() + new Vector3(0, 0, 6), color);
            return;
        }
        else if (_params[0] == "pa")
        {
            ExecuteParticleAttach(_params[1], player.GetPosition());
            return;
        }
        else if (_params[0] == "pg")
        {
            ExecuteParticleGhost(_params[1], player.GetPosition());
            return;
        }
        else if (_params[0] == "s")
        {
            float intens = 1f;
            if (_params.Count > 0)
            {
                intens = float.Parse(_params[1]);
            }
            ExecuteScreenEffect(_params[1]);
            return;
        }
        int ei = int.Parse(_params[0]);

        Emplacement place = Emplacement.At(player.GetPosition() + new Vector3(0, 1, 10), Vectors.Float.Zero); // N

        ItemClass         itemClass = ItemClass.GetItemClass("thrownAmmoMolotovCocktail", false);
        DynamicProperties baseProps = itemClass.Properties;
        ExplosionData     ed        = new ExplosionData(baseProps);

        ed.ParticleIndex = ei;
        GameManager.Instance.ExplosionServer(0, place.position, place.ipos, Quaternion.identity, ed, player.entityId, 0.1f, false, null); // try -1
    }
Esempio n. 5
0
        public static void Explosion(EntityPlayer player, Emplacement place, OptionEffect options)
        {
            /// effet graphique seul (mm si molo contient des degats, ils concernent le onImpact, pas l'explosion elle meme)
            ///
            ItemClass itemClass = ItemClass.GetItemClass("thrownAmmoMolotovCocktail", false);

            Debug.Log(String.Format("Explosion --> {0}", itemClass));
            // GameManager.Instance.ExplosionServer(0, place.position, place.position, Quaternion.identity, new ExplosionData(itemClass.Properties), player.entityId, 0.1f, false, null); // try -1
            GameManager.Instance.ExplosionServer(0, place.position, place.ipos, Quaternion.identity, new ExplosionData(itemClass.Properties), -1, 0.1f, false, null);
            // try in the air
            // altérer particule pour toutes les essayer
        }
Esempio n. 6
0
    public override TileEntityPowerSource CreateTileEntity(Chunk chunk)
    {
        if (this.slotItem == null)
        {
            this.slotItem = ItemClass.GetItemClass(this.SlotItemName, false);
        }
        TileEntityPowerSource entityPowerSource = new TileEntityPowerSource(chunk);

        entityPowerSource.PowerItemType = (PowerItem.PowerItemTypes) 12;
        entityPowerSource.SlotItem      = this.slotItem;
        //entityPowerSource.PowerItem = new WindmillPowerItem();
        return(entityPowerSource);
    }
    public static bool CheckIngredients(List <ItemStack> ingredients, EntityPlayerLocal player)
    {
        bool result = false;

        foreach (ItemStack ingredient in ingredients)
        {
            // Check if the palyer hs the items in their inventory or bag.
            int playerHas = player.inventory.GetItemCount(ingredient.itemValue);
            if (ingredient.count < playerHas)
            {
                playerHas = player.bag.GetItemCount(ingredient.itemValue);
                if (ingredient.count < playerHas)
                {
                    ItemClass itemClass    = ItemClass.GetItemClass(ingredient.itemValue.ItemClass.GetItemName(), false);
                    ItemStack missingStack = new ItemStack(ingredient.itemValue, ingredient.count);
                    player.AddUIHarvestingItem(missingStack, true);
                    result = false;
                }
            }
        }

        return(result);
    }
Esempio n. 8
0
        public static void LoadXml()
        {
            if (!Utils.FileExists(filePath))
            {
                UpdateXml();
            }
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(filePath);
            }
            catch (XmlException e)
            {
                Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message));
                return;
            }
            XmlNode _XmlNode = xmlDoc.DocumentElement;

            foreach (XmlNode childNode in _XmlNode.ChildNodes)
            {
                if (childNode.Name == "Rewards")
                {
                    dict.Clear();
                    list.Clear();
                    foreach (XmlNode subChild in childNode.ChildNodes)
                    {
                        if (subChild.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (subChild.NodeType != XmlNodeType.Element)
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Rewards' section: {0}", subChild.OuterXml));
                            continue;
                        }
                        XmlElement _line = (XmlElement)subChild;
                        if (!_line.HasAttribute("itemOrBlock"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing itemOrBlock attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("countMin"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing countMin attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("countMax"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing countMax attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("qualityMin"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing qualityMin attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("qualityMax"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring reward entry because of missing qualityMax attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        int _countMin   = 1;
                        int _countMax   = 1;
                        int _qualityMin = 1;
                        int _qualityMax = 1;
                        if (!int.TryParse(_line.GetAttribute("countMin"), out _countMin))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring reward entry because of invalid (non-numeric) value for 'count' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("countMax"), out _countMax))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring reward entry because of invalid (non-numeric) value for 'count' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("qualityMin"), out _qualityMin))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring reward entry because of invalid (non-numeric) value for 'quality' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("qualityMax"), out _qualityMax))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring reward entry because of invalid (non-numeric) value for 'quality' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        string    _item = _line.GetAttribute("itemOrBlock");
                        ItemClass _class;
                        Block     _block;
                        int       _id;
                        if (int.TryParse(_item, out _id))
                        {
                            _class = ItemClass.GetForId(_id);
                            _block = Block.GetBlockByName(_item, true);
                        }
                        else
                        {
                            _class = ItemClass.GetItemClass(_item, true);
                            _block = Block.GetBlockByName(_item, true);
                        }
                        if (_class == null && _block == null)
                        {
                            SdtdConsole.Instance.Output(string.Format("Unable to find item or block {0}", _item));
                            return;
                        }
                        else
                        {
                            if (!dict.ContainsKey(_item))
                            {
                                int[] _c = new int[] { _countMin, _countMax, _qualityMin, _qualityMax };
                                dict.Add(_item, _c);
                            }
                        }
                    }
                }
            }
            list = new List <string>(dict.Keys);
            if (updateConfig)
            {
                updateConfig = false;
                UpdateXml();
            }
        }
 public override void Execute(List <string> _params, CommandSenderInfo _senderInfo)
 {
     try
     {
         if (_params.Count < 1 && _params.Count > 2)
         {
             SdtdConsole.Instance.Output(string.Format("Wrong number of arguments, expected 1 or 2, found {0}", _params.Count));
             return;
         }
         if (_params[0].ToLower().Equals("off"))
         {
             if (AuctionBox.IsEnabled)
             {
                 AuctionBox.IsEnabled = false;
                 LoadConfig.WriteXml();
                 SdtdConsole.Instance.Output(string.Format("Auction has been set to off"));
                 return;
             }
             else
             {
                 SdtdConsole.Instance.Output(string.Format("Auction is already off"));
                 return;
             }
         }
         else if (_params[0].ToLower().Equals("on"))
         {
             if (!AuctionBox.IsEnabled)
             {
                 AuctionBox.IsEnabled = true;
                 LoadConfig.WriteXml();
                 SdtdConsole.Instance.Output(string.Format("Auction has been set to on"));
                 return;
             }
             else
             {
                 SdtdConsole.Instance.Output(string.Format("Auction is already on"));
                 return;
             }
         }
         else if (_params[0].ToLower().Equals("cancel"))
         {
             if (_params.Count != 2)
             {
                 SdtdConsole.Instance.Output(string.Format("Wrong number of arguments, expected 2, found {0}", _params.Count));
                 return;
             }
             int _id;
             if (int.TryParse(_params[1], out _id))
             {
                 if (AuctionBox.AuctionItems.ContainsKey(_id))
                 {
                     ClientInfo _cInfo = ConnectionManager.Instance.Clients.ForEntityId(_id);
                     if (_cInfo != null)
                     {
                         string    _auctionName    = PersistentContainer.Instance.Players[_cInfo.playerId].AuctionItemName;
                         int       _auctionCount   = PersistentContainer.Instance.Players[_cInfo.playerId].AuctionItemCount;
                         int       _auctionQuality = PersistentContainer.Instance.Players[_cInfo.playerId].AuctionItemQuality;
                         int       _auctionPrice   = PersistentContainer.Instance.Players[_cInfo.playerId].AuctionItemPrice;
                         ItemClass _class          = ItemClass.GetItemClass(_auctionName, false);
                         Block     _block          = Block.GetBlockByName(_auctionName, false);
                         if (_class == null && _block == null)
                         {
                             ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + "Could not complete the auction cancel. Unable to find item {0} in the item.xml list. Contact an administrator.[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                             Log.Out(string.Format("Could not complete the auction cancel. Unable to find item {0} in the item.xml list", _auctionName));
                             return;
                         }
                         ItemValue itemValue  = new ItemValue(ItemClass.GetItem(_auctionName).type, _auctionQuality, _auctionQuality, false, null, 1);
                         World     world      = GameManager.Instance.World;
                         var       entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                         {
                             entityClass     = EntityClass.FromString("item"),
                             id              = EntityFactory.nextEntityID++,
                             itemStack       = new ItemStack(itemValue, _auctionCount),
                             pos             = world.Players.dict[_cInfo.entityId].position,
                             rot             = new UnityEngine.Vector3(20f, 0f, 20f),
                             lifetime        = 60f,
                             belongsPlayerId = _cInfo.entityId
                         });
                         world.SpawnEntityInWorld(entityItem);
                         _cInfo.SendPackage(NetPackageManager.GetPackage <NetPackageEntityCollect>().Setup(entityItem.entityId, _cInfo.entityId));
                         world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Killed);
                         AuctionBox.AuctionItems.Remove(_id);
                         PersistentContainer.Instance.Players[_cInfo.playerId].AuctionId          = 0;
                         PersistentContainer.Instance.Players[_cInfo.playerId].AuctionItemName    = "";
                         PersistentContainer.Instance.Players[_cInfo.playerId].AuctionItemCount   = 0;
                         PersistentContainer.Instance.Players[_cInfo.playerId].AuctionItemQuality = 0;
                         PersistentContainer.Instance.Players[_cInfo.playerId].AuctionItemPrice   = 0;
                         PersistentContainer.Instance.Players[_cInfo.playerId].AuctionCancelTime  = DateTime.Now;
                         PersistentContainer.Instance.Save();
                     }
                     else
                     {
                         AuctionBox.AuctionItems.Remove(_id);
                         PersistentContainer.Instance.Players[_cInfo.playerId].AuctionReturn = true;
                         PersistentContainer.Instance.Save();
                     }
                 }
                 else
                 {
                     SdtdConsole.Instance.Output(string.Format("Auction does not contain id {0}", _id));
                 }
             }
             else
             {
                 SdtdConsole.Instance.Output(string.Format("Invalid integer {0}", _id));
             }
             return;
         }
         else if (_params[0].ToLower().Equals("clear"))
         {
             if (_params.Count != 2)
             {
                 SdtdConsole.Instance.Output(string.Format("Wrong number of arguments, expected 2, found {0}", _params.Count));
             }
             int _id;
             if (int.TryParse(_params[1], out _id))
             {
                 if (AuctionBox.AuctionItems.ContainsKey(_id))
                 {
                     AuctionBox.AuctionItems.Remove(_id);
                     SdtdConsole.Instance.Output(string.Format("Id {0} has been removed from the auction", _id));
                 }
                 else
                 {
                     SdtdConsole.Instance.Output(string.Format("Auction does not contain id {0}", _id));
                 }
             }
             else
             {
                 SdtdConsole.Instance.Output(string.Format("Invalid integer {0}", _id));
             }
             return;
         }
         else if (_params[0].ToLower().Equals("list"))
         {
             if (_params.Count != 1)
             {
                 SdtdConsole.Instance.Output(string.Format("Wrong number of arguments, expected 1, found {0}", _params.Count));
                 return;
             }
             bool          _auctionItemsFound = false;
             List <string> playerlist         = PersistentContainer.Instance.Players.SteamIDs;
             for (int i = 0; i < playerlist.Count; i++)
             {
                 string _steamId   = playerlist[i];
                 int    _auctionId = PersistentContainer.Instance.Players[_steamId].AuctionId;
                 if (_auctionId > 0 && AuctionBox.AuctionItems.ContainsKey(_auctionId))
                 {
                     _auctionItemsFound = true;
                     int    _auctionCount   = PersistentContainer.Instance.Players[_steamId].AuctionItemCount;
                     string _auctionName    = PersistentContainer.Instance.Players[_steamId].AuctionItemName;
                     int    _auctionQuality = PersistentContainer.Instance.Players[_steamId].AuctionItemQuality;
                     int    _auctionPrice   = PersistentContainer.Instance.Players[_steamId].AuctionItemPrice;
                     if (_auctionQuality > 1)
                     {
                         string _message = "# {Id}: {Count} {Item} at {Quality} quality, for {Price} {Name}";
                         _message = _message.Replace("{Id}", _auctionId.ToString());
                         _message = _message.Replace("{Count}", _auctionCount.ToString());
                         _message = _message.Replace("{Item}", _auctionName);
                         _message = _message.Replace("{Quality}", _auctionQuality.ToString());
                         _message = _message.Replace("{Price}", _auctionPrice.ToString());
                         _message = _message.Replace("{Name}", Wallet.Coin_Name);
                         SdtdConsole.Instance.Output(_message);
                     }
                     else
                     {
                         string _message = "# {Id}: {Count} {Item} for {Price} {Name}";
                         _message = _message.Replace("{Id}", _auctionId.ToString());
                         _message = _message.Replace("{Count}", _auctionCount.ToString());
                         _message = _message.Replace("{Item}", _auctionName);
                         _message = _message.Replace("{Price}", _auctionPrice.ToString());
                         _message = _message.Replace("{Name}", Wallet.Coin_Name);
                         SdtdConsole.Instance.Output(_message);
                     }
                 }
             }
             if (!_auctionItemsFound)
             {
                 SdtdConsole.Instance.Output("No items are currently for sale");
             }
         }
         else
         {
             SdtdConsole.Instance.Output(string.Format("Invalid argument {0}", _params[0]));
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in AuctionConsole.Execute: {0}", e));
     }
 }
        public static void Exec(ClientInfo _cInfo, string _itemNameAndCount)
        {
            Log.Out("[SERVERTOOLS] Test 1");
            if (_cInfo != null && !string.IsNullOrEmpty(_itemNameAndCount))
            {
                try
                {
                    string _itemName = "";
                    int    _count    = 1;
                    if (_itemNameAndCount.Contains(" "))
                    {
                        string _amount = _itemNameAndCount.Split(' ').Last();
                        if (int.TryParse(_amount, out _count))
                        {
                            _itemName = _itemNameAndCount.Replace(" " + _amount, "");
                            Log.Out(string.Format("[SERVERTOOLS] _itemName: {0}", _itemName));
                            ItemClass _class = ItemClass.GetItemClass(_itemName, true);
                            Block     _block = Block.GetBlockByName(_itemName, true);
                            if (_class == null && _block == null)
                            {
                                Log.Out(string.Format("[SERVERTOOLS] invalid item to remove. Item not found: {0}", _itemName));
                                return;
                            }
                            else
                            {
                                Log.Out("[SERVERTOOLS] Test 2. Building local player");
                                EntityPlayerLocal _entityPlayerLocal = BuildLocalPlayer(_cInfo);
                                LocalPlayerUI     uiforPlayer        = LocalPlayerUI.GetUIForPlayer(_entityPlayerLocal);
                                if (uiforPlayer != null)
                                {
                                    Log.Out("[SERVERTOOLS] Test 3. uiforPlayer is not null");
                                }
                                EntityPlayerLocal _localPlayerFromID = GameManager.Instance.World.GetLocalPlayerFromID(_cInfo.entityId);
                                if (_localPlayerFromID != null)
                                {
                                    Log.Out("[SERVERTOOLS] Test 3.5. _localPlayerFromID is not null");
                                }
                                Log.Out("[SERVERTOOLS] Test 4. Adjusting local player bag");
                                EntityPlayerLocal _entityPlayerLocalAdjusted = Adjust(_entityPlayerLocal, _itemName, _count);
                                Log.Out("[SERVERTOOLS] Test 5 Sending package");

                                _cInfo.SendPackage(NetPackageManager.GetPackage <NetPackagePlayerInventory>().Setup(_entityPlayerLocalAdjusted, false, true, false));
                                Log.Out("[SERVERTOOLS] Test 6 Operation complete");
                            }
                        }
                        else
                        {
                            Log.Out(string.Format("[SERVERTOOLS] you must input a valid item count. {0}", _amount));
                            return;
                        }
                    }
                    else
                    {
                        Log.Out(string.Format("[SERVERTOOLS] you must input a valid item name and count. {0}", _itemNameAndCount));
                        return;
                    }
                }
                catch (Exception e)
                {
                    Log.Out(string.Format("[ServerTools] Failed to run ", e.Message));
                }
            }
        }
Esempio n. 11
0
 public override void Execute(List <string> _params, CommandSenderInfo _senderInfo)
 {
     try
     {
         if (_params.Count != 3)
         {
             SdtdConsole.Instance.Output(string.Format("Wrong number of arguments, expected 3, found {0}", _params.Count));
             return;
         }
         if (_params[0].Length < 1 || _params[0].Length > 17)
         {
             SdtdConsole.Instance.Output(string.Format("Can not give block to all players or player with Id: Invalid \"all\" or Id {0}", _params[0]));
             return;
         }
         if (_params[1].Length < 1 || _params[0].Length > 4)
         {
             SdtdConsole.Instance.Output(string.Format("Can not give block: Invalid blockId {0}", _params[1]));
             return;
         }
         if (_params[2].Length < 1 || _params[2].Length > 1)
         {
             SdtdConsole.Instance.Output(string.Format("Can not give block: Invalid count {0}", _params[2]));
             return;
         }
         else
         {
             ItemValue _itemValue;
             ItemClass _class;
             Block     _block;
             int       _id;
             if (int.TryParse(_params[1], out _id))
             {
                 _class = ItemClass.GetForId(_id);
                 _block = Block.GetBlockByName(_params[1], true);
             }
             else
             {
                 _class = ItemClass.GetItemClass(_params[1], true);
                 _block = Block.GetBlockByName(_params[1], true);
             }
             if (_class == null && _block == null)
             {
                 SdtdConsole.Instance.Output(string.Format("Unable to find block {0}", _params[1]));
                 return;
             }
             else
             {
                 _itemValue = new ItemValue(ItemClass.GetItem(_params[1]).type, 1, 1, true, default(FastTags), 1);
             }
             if (_params[0].ToLower() == "all")
             {
                 List <ClientInfo> _cInfoList = ConnectionManager.Instance.Clients.List.ToList();
                 foreach (var _cInfo in _cInfoList)
                 {
                     int count = 1;
                     int _count;
                     if (int.TryParse(_params[2], out _count))
                     {
                         if (_count > 0 & _count < 100000)
                         {
                             count = _count;
                         }
                     }
                     World world = GameManager.Instance.World;
                     if (world.Players.dict[_cInfo.entityId].IsSpawned())
                     {
                         var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                         {
                             entityClass     = EntityClass.FromString("item"),
                             id              = EntityFactory.nextEntityID++,
                             itemStack       = new ItemStack(_itemValue, count),
                             pos             = world.Players.dict[_cInfo.entityId].position,
                             rot             = new Vector3(20f, 0f, 20f),
                             lifetime        = 60f,
                             belongsPlayerId = _cInfo.entityId
                         });
                         world.SpawnEntityInWorld(entityItem);
                         _cInfo.SendPackage(new NetPackageEntityCollect(entityItem.entityId, _cInfo.entityId));
                         world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Killed);
                         SdtdConsole.Instance.Output(string.Format("Gave {0} to {1}.", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name, _cInfo.playerName));
                         string _phrase804;
                         if (!Phrases.Dict.TryGetValue(804, out _phrase804))
                         {
                             _phrase804 = "{Count} {ItemName} was sent to your inventory. If your bag is full, check the ground.";
                         }
                         _phrase804 = _phrase804.Replace("{Count}", count.ToString());
                         _phrase804 = _phrase804.Replace("{ItemName}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name);
                         ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + _phrase804 + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                     }
                     else
                     {
                         SdtdConsole.Instance.Output(string.Format("Player with steamdId {0} is not spawned", _params[0]));
                     }
                 }
             }
             else
             {
                 ClientInfo _cInfo = ConsoleHelper.ParseParamIdOrName(_params[0]);
                 if (_cInfo != null)
                 {
                     int count = 1;
                     int _count;
                     if (int.TryParse(_params[2], out _count))
                     {
                         if (_count > 0 & _count < 10000)
                         {
                             count = _count;
                         }
                     }
                     World world = GameManager.Instance.World;
                     if (world.Players.dict[_cInfo.entityId].IsSpawned())
                     {
                         var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                         {
                             entityClass     = EntityClass.FromString("item"),
                             id              = EntityFactory.nextEntityID++,
                             itemStack       = new ItemStack(_itemValue, count),
                             pos             = world.Players.dict[_cInfo.entityId].position,
                             rot             = new Vector3(20f, 0f, 20f),
                             lifetime        = 60f,
                             belongsPlayerId = _cInfo.entityId
                         });
                         world.SpawnEntityInWorld(entityItem);
                         _cInfo.SendPackage(new NetPackageEntityCollect(entityItem.entityId, _cInfo.entityId));
                         world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Killed);
                         string _phrase804;
                         if (!Phrases.Dict.TryGetValue(804, out _phrase804))
                         {
                             _phrase804 = "{Count} {ItemName} was sent to your inventory. If your bag is full, check the ground.";
                         }
                         _phrase804 = _phrase804.Replace("{Count}", count.ToString());
                         _phrase804 = _phrase804.Replace("{ItemName}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name);
                         ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + _phrase804 + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                     }
                     else
                     {
                         SdtdConsole.Instance.Output(string.Format("Player with Id {0} is not spawned", _params[0]));
                     }
                 }
                 else
                 {
                     SdtdConsole.Instance.Output(string.Format("Player with steamdId {0} does not exist", _params[0]));
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in GiveItemDirectConsole.Run: {0}.", e));
     }
 }
Esempio n. 12
0
        public static void LoadXml()
        {
            if (!Utils.FileExists(filePath))
            {
                UpdateXml();
            }
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(filePath);
            }
            catch (XmlException e)
            {
                Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message));
                return;
            }
            XmlNode _XmlNode = xmlDoc.DocumentElement;

            foreach (XmlNode childNode in _XmlNode.ChildNodes)
            {
                if (childNode.Name == "items")
                {
                    dict.Clear();
                    dict1.Clear();
                    categories.Clear();
                    foreach (XmlNode subChild in childNode.ChildNodes)
                    {
                        if (subChild.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (subChild.NodeType != XmlNodeType.Element)
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Market' section: {0}", subChild.OuterXml));
                            continue;
                        }
                        XmlElement _line = (XmlElement)subChild;
                        if (!_line.HasAttribute("item"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing item attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("name"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing name attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("secondaryname"))
                        {
                            updateConfig = true;
                        }
                        if (!_line.HasAttribute("count"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing count attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("quality"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing quality attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("price"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing price attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("category"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring Market entry because of missing category attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        int _item    = 1;
                        int _count   = 1;
                        int _quality = 1;
                        int _price   = 1;
                        if (!int.TryParse(_line.GetAttribute("item"), out _item))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring Market entry because of invalid (non-numeric) value for 'item' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("count"), out _count))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring Market entry because of invalid (non-numeric) value for 'count' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("quality"), out _quality))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring Market entry because of invalid (non-numeric) value for 'quality' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("price"), out _price))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring Market Item entry because of invalid (non-numeric) value for 'price' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (_quality > 6)
                        {
                            _quality = 1;
                        }
                        string _name = _line.GetAttribute("name");
                        string _secondaryname;
                        if (_line.HasAttribute("secondaryname"))
                        {
                            _secondaryname = _line.GetAttribute("secondaryname");
                        }
                        else
                        {
                            _secondaryname = _name;
                        }
                        ItemClass _class;
                        Block     _block;
                        int       _id;
                        if (int.TryParse(_name, out _id))
                        {
                            _class = ItemClass.GetForId(_id);
                            _block = Block.GetBlockByName(_name, true);
                        }
                        else
                        {
                            _class = ItemClass.GetItemClass(_name, true);
                            _block = Block.GetBlockByName(_name, true);
                        }
                        if (_class == null && _block == null)
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Market entry skipped. Item not found: {0}", _name));
                            continue;
                        }
                        string _category = _line.GetAttribute("category");
                        _category = _category.ToLower();
                        if (!categories.Contains(_category))
                        {
                            categories.Add(_category);
                        }
                        if (!dict.ContainsKey(_item))
                        {
                            string[] _n = new string[] { _name, _secondaryname, _category };
                            dict.Add(_item, _n);
                            int[] _c = new int[] { _count, _quality, _price };
                            dict1.Add(_item, _c);
                        }
                    }
                }
            }
            if (updateConfig)
            {
                updateConfig = false;
                UpdateXml();
            }
        }
Esempio n. 13
0
        public static void LoadXml()
        {
            if (!Utils.FileExists(filePath))
            {
                UpdateXml();
            }
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(filePath);
            }
            catch (XmlException e)
            {
                Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message));
                return;
            }
            XmlNode _XmlNode = xmlDoc.DocumentElement;

            foreach (XmlNode childNode in _XmlNode.ChildNodes)
            {
                if (childNode.Name == "Weapons")
                {
                    dict.Clear();
                    foreach (XmlNode subChild in childNode.ChildNodes)
                    {
                        if (subChild.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (subChild.NodeType != XmlNodeType.Element)
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Weapons' section: {0}", subChild.OuterXml));
                            continue;
                        }
                        XmlElement _line = (XmlElement)subChild;
                        if (!_line.HasAttribute("Name"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring weapons entry because of missing Name attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("NewName"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring weapons entry because of missing NewName attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        string    _name  = _line.GetAttribute("Name");
                        ItemClass _class = ItemClass.GetItemClass(_name, true);
                        if (_class == null)
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Kill Notice entry skipped. Weapon not found: {0}", _name));
                            continue;
                        }
                        if (!dict.ContainsKey(_name))
                        {
                            dict.Add(_name, _line.GetAttribute("NewName"));
                        }
                    }
                }
            }
            if (updateConfig)
            {
                updateConfig = false;
                UpdateXml();
            }
        }
        public static void LoadXml()
        {
            if (!Utils.FileExists(filePath))
            {
                UpdateXml();
            }
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(filePath);
            }
            catch (XmlException e)
            {
                Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message));
                return;
            }
            XmlNode _XmlNode = xmlDoc.DocumentElement;

            foreach (XmlNode childNode in _XmlNode.ChildNodes)
            {
                if (childNode.Name == "items")
                {
                    Dict.Clear();
                    Dict1.Clear();
                    foreach (XmlNode subChild in childNode.ChildNodes)
                    {
                        if (subChild.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (subChild.NodeType != XmlNodeType.Element)
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'items' section: {0}", subChild.OuterXml));
                            continue;
                        }
                        XmlElement _line = (XmlElement)subChild;
                        if (!_line.HasAttribute("name"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring BloodmoonWarrior entry because of missing name attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("secondaryname"))
                        {
                            updateConfig = true;
                        }
                        if (!_line.HasAttribute("minCount"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring BloodmoonWarrior entry because of missing minCount attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("maxCount"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring BloodmoonWarrior entry because of missing maxCount attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("minQuality"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring BloodmoonWarrior entry because of missing minQuality attribute: {0}", subChild.OuterXml));
                        }
                        if (!_line.HasAttribute("maxQuality"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring BloodmoonWarrior entry because of missing maxQuality attribute: {0}", subChild.OuterXml));
                        }
                        int _minCount = 1, _maxCount = 1, _minQuality = 1, _maxQuality = 1;
                        if (!int.TryParse(_line.GetAttribute("minCount"), out _minCount))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring BloodmoonWarrior entry because of invalid (non-numeric) value for 'minCount' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("maxCount"), out _maxCount))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring BloodmoonWarrior entry because of invalid (non-numeric) value for 'maxCount' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("minQuality"), out _minQuality))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring BloodmoonWarrior entry because of invalid (non-numeric) value for 'minQuality' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("maxQuality"), out _maxQuality))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring BloodmoonWarrior entry because of invalid (non-numeric) value for 'maxQuality' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        string    _name  = _line.GetAttribute("name");
                        ItemClass _class = ItemClass.GetItemClass(_name, true);
                        Block     _block = Block.GetBlockByName(_name, true);
                        if (_class == null && _block == null)
                        {
                            Log.Out(string.Format("[SERVERTOOLS] BloodmoonWarrior entry skipped. Item name not found: {0}", _name));
                            continue;
                        }
                        string _secondaryname;
                        if (_line.HasAttribute("secondaryname"))
                        {
                            _secondaryname = _line.GetAttribute("secondaryname");
                        }
                        else
                        {
                            _secondaryname = _name;
                        }
                        if (!Dict.ContainsKey(_name))
                        {
                            int[] _c = new int[] { _minCount, _maxCount, _minQuality, _maxQuality };
                            Dict.Add(_name, _c);
                        }
                        if (!Dict1.ContainsKey(_name))
                        {
                            Dict1.Add(_name, _secondaryname);
                        }
                    }
                }
            }
            if (updateConfig)
            {
                updateConfig = false;
                UpdateXml();
            }
        }
Esempio n. 15
0
    public override void OnActivated()
    {
        XUi xui = base.ItemController.xui;
        XUiM_PlayerInventory     playerInventory = xui.PlayerInventory;
        ItemValue                itemValue       = ((XUiC_ItemStack)base.ItemController).ItemStack.itemValue;
        ItemClass                forId           = ItemClass.GetForId(itemValue.type);
        XUiC_CraftingWindowGroup childByType     = xui.FindWindowGroupByName("crafting").GetChildByType <XUiC_CraftingWindowGroup>();

        if (itemValue.HasQuality)
        {
            if (itemValue.PercentUsesLeft < 0.30)
            {
                String text = "This item is too worn out to be resharpened.";
                GameManager.ShowTooltip(ItemController.xui.playerUI.entityPlayer, text);
                return;
            }
            if (itemValue.PercentUsesLeft > 0.8)
            {
                String text = "This item is still in pretty good shape.";
                GameManager.ShowTooltip(ItemController.xui.playerUI.entityPlayer, text);
                return;
            }
        }
        if (forId.Properties.Contains("SharpenItem"))
        {
            String strSharpenItem = String.Empty;
            forId.Properties.ParseString("SharpenItem", ref strSharpenItem);
            if (String.IsNullOrEmpty(strSharpenItem))
            {
                return;
            }

            Recipe recipe = new Recipe();
            recipe.count = 1;
            ItemClass itemClass = ItemClass.GetItemClass(strSharpenItem, false);
            if (itemClass == null)
            {
                return;
            }


            int Count = playerInventory.GetItemCount(new ItemValue(itemClass.Id, false));
            if (Count < 1)
            {
                String text = "Not enough " + strSharpenItem + " to craft this: " + Count + " / 1";
                GameManager.ShowTooltip(ItemController.xui.playerUI.entityPlayer, text);
                return;
            }
            if (childByType != null)
            {
                recipe.ingredients.Add(new ItemStack(new ItemValue(itemClass.Id, false), 1));
                recipe.itemValueType = itemValue.type;
                recipe.craftingTime  = 1;
                recipe.craftExpGain  = 1;
            }
            // ItemClass.GetForId(recipe.itemValueType);
            GameRandom random   = GameRandomManager.Instance.CreateGameRandom();
            float      flRandom = random.RandomRange((int)itemValue.UseTimes, ((float)itemValue.MaxUseTimes / 1.20f));
            if (!childByType.AddRepairItemToQueue(recipe.craftingTime, itemValue.Clone(), (int)flRandom))
            {
                WarnQueueFull(ItemController);
                return;
            }
            ((XUiC_ItemStack)ItemController).ItemStack = ItemStack.Empty.Clone();
            playerInventory.RemoveItems(recipe.ingredients, 1);
        }
    }
        public static void LoadXml()
        {
            if (!Utils.FileExists(filePath))
            {
                UpdateXml();
            }
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(filePath);
            }
            catch (XmlException e)
            {
                Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message));
                return;
            }
            XmlNode _XmlNode = xmlDoc.DocumentElement;

            foreach (XmlNode childNode in _XmlNode.ChildNodes)
            {
                if (childNode.Name == "Items")
                {
                    ItemList.Clear();
                    foreach (XmlNode subChild in childNode.ChildNodes)
                    {
                        if (subChild.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (subChild.NodeType != XmlNodeType.Element)
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'StartingItems' section: {0}", subChild.OuterXml));
                            continue;
                        }
                        XmlElement _line = (XmlElement)subChild;
                        if (!_line.HasAttribute("Name"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring starting item entry because of missing Name attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("Count"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring starting item entry because of missing Count attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!_line.HasAttribute("Quality"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring starting item entry because of missing Quality attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("Count"), out int _count))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring starting item entry because of invalid (non-numeric) value for 'Count' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (!int.TryParse(_line.GetAttribute("Quality"), out int _quality))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring starting item entry because of invalid (non-numeric) value for 'Quality' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (_quality < 1)
                        {
                            _quality = 1;
                        }
                        string    _item = _line.GetAttribute("Name");
                        ItemClass _class;
                        Block     _block;
                        int       _id;
                        if (int.TryParse(_item, out _id))
                        {
                            _class = ItemClass.GetForId(_id);
                            _block = Block.GetBlockByName(_item, true);
                        }
                        else
                        {
                            _class = ItemClass.GetItemClass(_item, true);
                            _block = Block.GetBlockByName(_item, true);
                        }
                        if (_class == null && _block == null)
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Starting item entry skipped. Item not found: {0}", _item));
                            continue;
                        }
                        if (!ItemList.ContainsKey(_item))
                        {
                            int[] _c = new int[] { _count, _quality };
                            ItemList.Add(_item, _c);
                        }
                    }
                }
            }
            if (updateConfig)
            {
                updateConfig = false;
                UpdateXml();
            }
        }
    public static ItemStack CreateItemStack(string strItemName, int Count)
    {
        ItemClass itemClass = ItemClass.GetItemClass(strItemName, false);

        return(new ItemStack(ItemClass.GetItem(strItemName, false), Count));
    }
Esempio n. 18
0
        public static void Withdraw(ClientInfo _cInfo, string _amount)
        {
            int _coinAmount;

            if (int.TryParse(_amount, out _coinAmount))
            {
                string    _sql    = string.Format("SELECT bank FROM Players WHERE steamid = '{0}'", _cInfo.playerId);
                DataTable _result = SQL.TQuery(_sql);
                int       _bank;
                int.TryParse(_result.Rows[0].ItemArray.GetValue(0).ToString(), out _bank);
                _result.Dispose();
                if (_bank >= _coinAmount)
                {
                    ItemClass _class = ItemClass.GetItemClass(Ingame_Coin, false);
                    if (_class == null)
                    {
                        Log.Out(string.Format("[SERVERTOOLS] Unable to find item {0}", Ingame_Coin));
                        return;
                    }
                    ItemValue _item       = new ItemValue(ItemClass.GetItem(Ingame_Coin).type, 1, 1, false);
                    int       _maxAllowed = ItemClass.list[_item.type].Stacknumber.Value;
                    if (_coinAmount <= _maxAllowed)
                    {
                        World world = GameManager.Instance.World;
                        if (world.Players.dict[_cInfo.entityId].IsSpawned())
                        {
                            var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                            {
                                entityClass     = EntityClass.FromString("item"),
                                id              = EntityFactory.nextEntityID++,
                                itemStack       = new ItemStack(_item, _coinAmount),
                                pos             = world.Players.dict[_cInfo.entityId].position,
                                rot             = new Vector3(20f, 0f, 20f),
                                lifetime        = 60f,
                                belongsPlayerId = _cInfo.entityId
                            });
                            world.SpawnEntityInWorld(entityItem);

                            _cInfo.SendPackage(new NetPackageEntityCollect(entityItem.entityId, _cInfo.entityId));
                            world.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Killed);
                            _sql = string.Format("UPDATE Players SET bank = {0} WHERE steamid = '{1}'", _bank - _coinAmount, _cInfo.playerId);
                            SQL.FastQuery(_sql);
                            string _message = "you have received your {Name}. If your inventory is full, check the ground.";
                            _message = _message.Replace("{Name}", Ingame_Coin);
                            ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + _message + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                            using (StreamWriter sw = new StreamWriter(filepath, true))
                            {
                                sw.WriteLine(string.Format("{0}: {1} has removed {2} from their bank account as {3}.", DateTime.Now, _cInfo.playerName, _coinAmount, Ingame_Coin));
                                sw.WriteLine();
                                sw.Flush();
                                sw.Close();
                            }
                        }
                    }
                    else
                    {
                        string _message = "you can only withdraw a full stack at a time. The maximum stack size is {Max}.";
                        _message = _message.Replace("{Max}", _maxAllowed.ToString());
                        ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + _message + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                    }
                }
                else
                {
                    ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + ", your bank account does not have enough to withdraw that value.[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
                }
            }
            else
            {
                ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + ", you input an invalid integer. Type " + ChatHook.Command_Private + Command96 + " #.[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
            }
        }
Esempio n. 19
0
        private static void LoadXml()
        {
            if (!Utils.FileExists(filePath))
            {
                UpdateXml();
            }
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(filePath);
            }
            catch (XmlException e)
            {
                Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message));
                return;
            }
            XmlNode _XmlNode = xmlDoc.DocumentElement;

            foreach (XmlNode childNode in _XmlNode.ChildNodes)
            {
                if (childNode.Name == "Items")
                {
                    dict.Clear();
                    foreach (XmlNode subChild in childNode.ChildNodes)
                    {
                        if (subChild.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (subChild.NodeType != XmlNodeType.Element)
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Items' section: {0}", subChild.OuterXml));
                            continue;
                        }
                        XmlElement _line = (XmlElement)subChild;
                        if (!_line.HasAttribute("itemName"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring Item entry because of missing 'itemName' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        string    _item = _line.GetAttribute("itemName");
                        ItemClass _class;
                        Block     _block;
                        int       _id;
                        if (int.TryParse(_item, out _id))
                        {
                            _class = ItemClass.GetForId(_id);
                            _block = Block.GetBlockByName(_item, true);
                        }
                        else
                        {
                            _class = ItemClass.GetItemClass(_item, true);
                            _block = Block.GetBlockByName(_item, true);
                        }
                        if (_class == null && _block == null)
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Invalid item entry skipped. Item or block not found: {0}", _item));
                            continue;
                        }
                        if (!dict.Contains(_item))
                        {
                            dict.Add(_item);
                        }
                    }
                }
            }
        }
Esempio n. 20
0
 private static void LoadXml()
 {
     try
     {
         if (!File.Exists(FilePath))
         {
             UpdateXml();
         }
         XmlDocument xmlDoc = new XmlDocument();
         try
         {
             xmlDoc.Load(FilePath);
         }
         catch (XmlException e)
         {
             Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message));
             return;
         }
         bool        upgrade    = true;
         XmlNodeList childNodes = xmlDoc.DocumentElement.ChildNodes;
         if (childNodes != null)
         {
             Dict.Clear();
             for (int i = 0; i < childNodes.Count; i++)
             {
                 if (childNodes[i].NodeType != XmlNodeType.Comment)
                 {
                     XmlElement _line = (XmlElement)childNodes[i];
                     if (_line.HasAttributes)
                     {
                         if (_line.HasAttribute("Version") && _line.GetAttribute("Version") == Config.Version)
                         {
                             upgrade = false;
                             continue;
                         }
                         else if (_line.HasAttribute("Name"))
                         {
                             string    item   = _line.GetAttribute("Name");
                             ItemClass _class = ItemClass.GetItemClass(item, true);
                             if (_class == null)
                             {
                                 Log.Out(string.Format("[SERVERTOOLS] Invalid InvalidItems.xml entry. Item or block not found: {0}", item));
                                 continue;
                             }
                             if (!Dict.Contains(item))
                             {
                                 Dict.Add(item);
                             }
                         }
                     }
                 }
             }
         }
         if (upgrade)
         {
             XmlNodeList nodeList = xmlDoc.DocumentElement.ChildNodes;
             XmlNode     node     = nodeList[0];
             XmlElement  line     = (XmlElement)nodeList[0];
             if (line != null)
             {
                 if (line.HasAttributes)
                 {
                     OldNodeList = nodeList;
                     File.Delete(FilePath);
                     UpgradeXml();
                     return;
                 }
                 else
                 {
                     nodeList = node.ChildNodes;
                     line     = (XmlElement)nodeList[0];
                     if (line != null)
                     {
                         if (line.HasAttributes)
                         {
                             OldNodeList = nodeList;
                             File.Delete(FilePath);
                             UpgradeXml();
                             return;
                         }
                     }
                     File.Delete(FilePath);
                     UpdateXml();
                     Log.Out(string.Format("[SERVERTOOLS] The existing InvalidItems.xml was too old or misconfigured. File deleted and rebuilt for version {0}", Config.Version));
                 }
             }
         }
     }
     catch (Exception e)
     {
         if (e.Message == "Specified cast is not valid.")
         {
             File.Delete(FilePath);
             UpdateXml();
         }
         else
         {
             Log.Out(string.Format("[SERVERTOOLS] Error in InvalidItems.LoadXml: {0}", e.Message));
         }
     }
 }