public static void Exec(ClientInfo _cInfo)
        {
            World world = GameManager.Instance.World;

            foreach (KeyValuePair <string, int[]> kvp in startItemList)
            {
                ItemValue _itemValue = new ItemValue(ItemClass.GetItem(kvp.Key).type, kvp.Value[1], kvp.Value[1], true);
                var       entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                {
                    entityClass     = EntityClass.FromString("item"),
                    id              = EntityFactory.nextEntityID++,
                    itemStack       = new ItemStack(_itemValue, kvp.Value[0]),
                    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);
                Log.Out(string.Format("[SERVERTOOLS] Spawned starting item {0} for {1}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name, _cInfo.playerName));
            }
            string _sql = string.Format("UPDATE Players SET startingItems = 'true' WHERE steamid = '{0}'", _cInfo.playerId);

            SQL.FastQuery(_sql);
        }
    public override bool CheckRequirement(EntityPlayer player)
    {
        int count = 0;

        if (string.IsNullOrEmpty(Value))
        {
            Value = "1";
        }

        float flValue = 1f;

        float.TryParse(Value, out flValue);

        LocalPlayerUI        uiforPlayer     = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal);
        XUiM_PlayerInventory playerInventory = uiforPlayer.xui.PlayerInventory;
        ItemValue            item            = ItemClass.GetItem(ID);

        if (item != null)
        {
            count  = playerInventory.Backpack.GetItemCount(item, -1, -1, false);
            count += playerInventory.Toolbelt.GetItemCount(item, false, -1, -1);
            AdvLogging.DisplayLog(AdvFeatureClass, "HasItemSDX: " + item.ItemClass.GetItemName() + " Player has Count: " + count + " Needs: " + flValue);
            if (flValue <= count)
            {
                return(true);
            }
        }

        AdvLogging.DisplayLog(AdvFeatureClass, "HasItemSDX: Player does not have enough " + item.ItemClass.GetItemName() + " Count: " + count + " Needs: " + flValue);

        return(false);
    }
Example #3
0
 public void RefreshEquipment()
 {
     if (PlayerStorage != null)
     {
         CurrentPlayer = PlayerStorage.GetComponent <PlayerBuyingEquipment>().GetPlayer();
     }
     //CurrentPlayer = PlayerBuyingEquipment.GetPlayer();
     if (Weapon)
     {
         Item = ItemClass.GetItem(ItemSlot.WEAPON, CurrentPlayer.WeaponEquippedID);
         Prime(Item);
     }
     if (Shields)
     {
         Item = ItemClass.GetItem(ItemSlot.SHIELDS, CurrentPlayer.ShieldEquippedID);
         Prime(Item);
     }
     if (Engines)
     {
         Item = ItemClass.GetItem(ItemSlot.ENGINES, CurrentPlayer.EngineEquippedID);
         Prime(Item);
     }
     if (Armor)
     {
         Item = ItemClass.GetItem(ItemSlot.ARMOR, CurrentPlayer.ArmorEquippedID);
         Prime(Item);
     }
     if (Power)
     {
         Item = ItemClass.GetItem(ItemSlot.MISC, CurrentPlayer.MiscEquippedID);
         Prime(Item);
     }
 }
Example #4
0
 private static void RandomItem(ClientInfo _cInfo)
 {
     try
     {
         string    _randomItem = List.RandomObject();
         ItemValue _itemValue  = new ItemValue(ItemClass.GetItem(_randomItem, false).type, false);
         if (Dict.TryGetValue(_randomItem, out int[] _itemData))
Example #5
0
 public static void Exec()
 {
     if (ConnectionManager.Instance.ClientCount() > 0)
     {
         List <ClientInfo> ClientInfoList = ConnectionManager.Instance.Clients.List.ToList();
         for (int i = 0; i < ClientInfoList.Count; i++)
         {
             ClientInfo _cInfo = ClientInfoList[i];
             if (_cInfo != null)
             {
                 EntityAlive _player = (EntityAlive)GameManager.Instance.World.GetEntity(_cInfo.entityId);
                 if (_player != null)
                 {
                     string    _pos         = (int)_player.position.x + " " + (int)_player.position.y + " " + (int)_player.position.z;
                     string    _holdingItem = _player.inventory.holdingItem.Name;
                     ItemValue _itemValue   = ItemClass.GetItem(_holdingItem, true);
                     if (_itemValue.type != ItemValue.None.type)
                     {
                         _holdingItem = _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name;
                     }
                     string _sql = string.Format("INSERT INTO Tracking (dateTime, position, steamId, playerName, holding) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')", DateTime.Now.ToString(), _pos, _cInfo.playerId, _cInfo.playerName, _holdingItem);
                     SQL.FastQuery(_sql, "Tracking");
                 }
             }
         }
     }
 }
Example #6
0
        public static IEnumerator spawnItemGhost(string item, Vector3 position, Vector3 motion)
        {
            /* TODO: speed per weight
             * TODO: position up by multiblockdim of the item
             */
            ItemStack itemStack = new ItemStack(ItemClass.GetItem(item, false), 1); // this.CreateItemCount

            //yield return Zombiome.Routines.Start(SdtdUtils.EffectsEntity.Ghost.GetGhost(player));
            //Entity ghost = SdtdUtils.EffectsEntity.Ghost.Current;
            yield return(Zombiome.Routines.Start(TheGhost.Ensure(), "TheGhost.Ensure"));

            Entity ghost = TheGhost.Current;

            Printer.FLog(27, "spawnItemGhost ghost {0}", ghost);
            // Entity ghost = GameManager.Instance.World.GetEntity(ghostId);
            if (ghost == null)
            {
                yield break;
            }
            GameManager.Instance.ItemDropServer(
                itemStack,
                position + new Vector3(0.0f, 0.75f, 0.0f), // initial pos
                Vector3.zero,                              /// rdm
                motion,                                    ///  _initialMotion
                ghost.entityId,                            // -1 plante (pour gagner XP ?)
                60f,                                       // 1 second lifetime
                false,
                0
                );
        }
    public override void Execute(MinEventParams _params)
    {
        EntityPlayerLocal entityPlayer = _params.Self as EntityPlayerLocal;

        // Loot group
        if (_params.Self as EntityPlayerLocal != null && this.lootgroup > 0)
        {
            ItemStack[] array = LootContainer.lootList[lootgroup].Spawn(GameManager.Instance.lootManager.Random, this.CreateItemCount, EffectManager.GetValue(PassiveEffects.LootGamestage, null, (float)entityPlayer.HighestPartyGameStage, entityPlayer, null, default(FastTags), true, true, true, true, 1, true), 0f, entityPlayer, new FastTags());
            for (int i = 0; i < array.Length; i++)
            {
                if (!LocalPlayerUI.GetUIForPlayer(entityPlayer).xui.PlayerInventory.AddItem(array[i], true))
                {
                    entityPlayer.world.gameManager.ItemDropServer(array[i], entityPlayer.GetPosition(), Vector3.zero, -1, 60f, false);
                }
            }
            return;
        }

        // item value.
        if (_params.Self as EntityPlayerLocal != null && this.CreateItem != null && this.CreateItemCount > 0)
        {
            ItemStack itemStack = new ItemStack(ItemClass.GetItem(this.CreateItem, false), this.CreateItemCount);
            if (!LocalPlayerUI.GetUIForPlayer(entityPlayer).xui.PlayerInventory.AddItem(itemStack, true))
            {
                entityPlayer.world.gameManager.ItemDropServer(itemStack, entityPlayer.GetPosition(), Vector3.zero, -1, 60f, false);
            }
        }
    }
Example #8
0
        public static void ShopPurchase(ClientInfo _cInfo, string _itemName, int _count, int _quality, int _price, string _playerName, int currentCoins)
        {
            World     world      = GameManager.Instance.World;
            ItemValue itemValue  = new ItemValue(ItemClass.GetItem(_itemName).type, _quality, _quality, true);
            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("Sold {0} to {1}.", itemValue.ItemClass.GetLocalizedItemName() ?? itemValue.ItemClass.Name, _cInfo.playerName));
            string _message = "{Count} {Item} was purchased through the shop. If your bag is full, check the ground.";

            _message = _message.Replace("{Count}", _count.ToString());
            _message = _message.Replace("{Item}", itemValue.ItemClass.GetLocalizedItemName() ?? itemValue.ItemClass.Name);
            ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + _message + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
            Wallet.SubtractCoinsFromWallet(_cInfo.playerId, _price);
        }
Example #9
0
        public static void ReturnBlock(ClientInfo _cInfo, string _blockName, int _quantity)
        {
            EntityPlayer _player = PersistentOperations.GetEntityPlayer(_cInfo.playerId);

            if (_player != null && _player.IsSpawned() && !_player.IsDead())
            {
                World     _world     = GameManager.Instance.World;
                ItemValue _itemValue = ItemClass.GetItem(_blockName, false);
                if (_itemValue != null)
                {
                    var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                    {
                        entityClass     = EntityClass.FromString("item"),
                        id              = EntityFactory.nextEntityID++,
                        itemStack       = new ItemStack(_itemValue, _quantity),
                        pos             = _world.Players.dict[_cInfo.entityId].position,
                        rot             = new 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.Despawned);
                    Phrases.Dict.TryGetValue(901, out string _phrase901);
                    _phrase901 = _phrase901.Replace("{Value}", _quantity.ToString());
                    _phrase901 = _phrase901.Replace("{ItemName}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name);
                    ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase901 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                }
            }
        }
    public override void CopyPropertiesFromEntityClass()
    {
        base.CopyPropertiesFromEntityClass();

        EntityClass entityClass = EntityClass.list[this.entityClass];

        if (!entityClass.Properties.Values.ContainsKey(this.propItemToReturn))
        {
            throw new Exception("Entity " + entityClass.entityClassName + " does not have a " + this.propItemToReturn + " property.");
        }

        this.itemReturned = ItemClass.GetItem(entityClass.Properties.Values[this.propItemToReturn], false);
        if (this.itemReturned.IsEmpty())
        {
            throw new Exception("Item with name '" + entityClass.Properties.Values[this.propItemToReturn] + "' not found!");
        }

        this.holdingItem = ItemClass.GetItem("meleeHandPlayer", false);
        if (entityClass.Properties.Values.ContainsKey(this.propHoldingItem))
        {
            this.holdingItem = ItemClass.GetItem(entityClass.Properties.Values[this.propHoldingItem], false);
            if (this.holdingItem.IsEmpty())
            {
                throw new Exception("Item with name '" + EntityClass.Properties.Values[this.propHoldingItem] + "' not found!");
            }
        }
    }
Example #11
0
 public static void Send(ClientInfo _cInfo)
 {
     if (StartingItems.startItemList.Count > 0)
     {
         World world = GameManager.Instance.World;
         foreach (KeyValuePair <string, int[]> kvp in StartingItems.startItemList)
         {
             ItemValue _itemValue = new ItemValue(ItemClass.GetItem(kvp.Key).type, kvp.Value[1], kvp.Value[1], true);
             var       entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
             {
                 entityClass     = EntityClass.FromString("item"),
                 id              = EntityFactory.nextEntityID++,
                 itemStack       = new ItemStack(_itemValue, kvp.Value[0]),
                 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("Spawned starting item {0} for {1}.", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name, _cInfo.playerName));
             Log.Out(string.Format("[SERVERTOOLS] Spawned starting item {0} for {1}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name, _cInfo.playerName));
         }
         string _phrase806;
         if (!Phrases.Dict.TryGetValue(806, out _phrase806))
         {
             _phrase806 = "you have received the starting items. Check your inventory. If full, check the ground.";
         }
         ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + _phrase806 + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
     }
 }
    public override bool CheckRequirement(EntityPlayer player)
    {
        int count = 0;

        if (string.IsNullOrEmpty(Value))
        {
            Value = "1";
        }

        float flValue = 1f;

        float.TryParse(Value, out flValue);

        LocalPlayerUI        uiforPlayer     = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal);
        XUiM_PlayerInventory playerInventory = uiforPlayer.xui.PlayerInventory;
        ItemValue            item            = ItemClass.GetItem(ID);

        if (item != null)
        {
            count  = playerInventory.Backpack.GetItemCount(item, -1, -1, false);
            count += playerInventory.Toolbelt.GetItemCount(item, false, -1, -1);
            if (flValue <= count)
            {
                return(true);
            }
        }

        return(false);
    }
Example #13
0
        private static void ItemOrBlockRandom(ClientInfo _cInfo)
        {
            string _item = list.RandomObject();

            int[] _values;
            if (dict.TryGetValue(_item, out _values))
            {
                int _count = 1;
                if (_values[0] != _values[1] && _values[1] > _values[0])
                {
                    _count = rnd.Next(_values[0], _values[1] + 1);
                }
                else if (_values[0] > 0)
                {
                    _count = _values[0];
                }
                int quality = rnd.Next(_values[2], _values[3] + 1);
                if (quality < 1)
                {
                    quality = 1;
                }
                ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_item).type, quality, quality, false, default(FastTags), 1);
                Give(_cInfo, _itemValue, _count);
                ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + " got a nice reward for voting: " + _count.ToString() + " " + _itemValue.ItemClass.GetLocalizedItemName() + (_itemValue.Quality == 0 ? "" : " (quality " + _itemValue.Quality + ")") + "[-]", _cInfo.entityId, LoadConfig.Server_Response_Name, EChatType.Global, null);
            }
        }
Example #14
0
        public IEnumerator Fly(BlockPos pos, string item)
        {
            int my = (pos.Value.Block.isMultiBlock) ? pos.Value.Block.multiBlockPos.dim.y : 1;
            // GameManager.Instance.World.SetBlockRPC(pos.Pos, BlockValue.Air);
            // yield return WaitFrame;
            int     wgt    = ItemClass.GetItem(item, false).ItemClass.Weight.Value; // TODO: quicker access string->ItemValue->ItemClass
            Vector3 dir    = Upward(this.rand, wgt);
            float   offset = (1f + my / 2f - 1f);

            offset = offset = Math.Max(offset, 2);
            if (item.Equals("ZBProj_treeShrub"))
            {
                offset = offset = Math.Max(offset, 3);
            }

            SdtdUtils.EffectsItem.SpawnParticle(Vectors.ToFloat(pos.Pos), "wire_tool_sparks", biome.groundColor, "electric_fence_impact");
            yield return(afterParticle);

            yield return(Zombiome.Routines.Start(EffectsItem.spawnItemGhost(
                                                     item,
                                                     Vectors.ToFloat(pos.Pos) + offset * Vectors.Float.UnitY,
                                                     dir// throw dir
                                                     ), "FlyDeco-Item"));

            // yield return WaitFrame; // o ther way around, byt careful not to spawn on existing (ghost proj will delay it though)
            GameManager.Instance.World.SetBlockRPC(pos.Pos, BlockValue.Air);
            // Do not repop because the projectile does at impact !
        }
Example #15
0
 private static void RandomItem(ClientInfo _cInfo)
 {
     try
     {
         string _randomItem = list.RandomObject();
         ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_randomItem, false).type, false);
         int[] _itemData;
         if (Dict.TryGetValue(_randomItem, out _itemData))
         {
             int _count = 0;
             if (_itemData[0] > _itemData[1])
             {
                 _count = random.Next(_itemData[1], _itemData[0] + 1);
             }
             else
             {
                 _count = random.Next(_itemData[0], _itemData[1] + 1);
             }
             if (_itemValue.HasQuality && _itemData[2] > 0 && _itemData[3] >= _itemData[2])
             {
                 _itemValue.Quality = random.Next(_itemData[2], _itemData[3] + 1);
             }
             var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
             {
                 entityClass = EntityClass.FromString("item"),
                 id = EntityFactory.nextEntityID++,
                 itemStack = new ItemStack(_itemValue, _count),
                 pos = GameManager.Instance.World.Players.dict[_cInfo.entityId].position,
                 rot = new Vector3(20f, 0f, 20f),
                 lifetime = 60f,
                 belongsPlayerId = _cInfo.entityId
             });
             GameManager.Instance.World.SpawnEntityInWorld(entityItem);
             _cInfo.SendPackage(NetPackageManager.GetPackage<NetPackageEntityCollect>().Setup(entityItem.entityId, _cInfo.entityId));
             GameManager.Instance.World.RemoveEntity(entityItem.entityId, EnumRemoveEntityReason.Despawned);
             if (Wallet.IsEnabled && Command_Cost >= 1)
             {
                 Wallet.SubtractCoinsFromWallet(_cInfo.playerId, Command_Cost);
             }
             PersistentContainer.Instance.Players[_cInfo.playerId].LastGimme = DateTime.Now;
             PersistentContainer.Instance.Save();
             Phrases.Dict.TryGetValue(22, out string _phrase22);
             _phrase22 = _phrase22.Replace("{ItemCount}", _count.ToString());
             Dict1.TryGetValue(_randomItem, out string _name);
             if (_name != "")
             {
                 _phrase22 = _phrase22.Replace("{ItemName}", _name);
             }
             else
             {
                 _phrase22 = _phrase22.Replace("{ItemName}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.Name);
             }
             ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _phrase22 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in Gimme.RandomItem: {0}", e.Message));
     }
 }
Example #16
0
        public static void AddToBag(EntityPlayer player, string item, bool merge = true, int n = 1)
        {
            /* item can also be a block ! */
            ItemStack stack = new ItemStack(ItemClass.GetItem(item, false), n);

            EffectsBag.AddItem(((EntityAlive)player).bag, stack, merge);
        }
Example #17
0
        private static void ItemOrBlockRandom(ClientInfo _cInfo)
        {
            string _item = list.RandomObject();

            int[] _values;
            if (dict.TryGetValue(_item, out _values))
            {
                int _count = 1;
                if (_values[0] != _values[1] && _values[1] > _values[0])
                {
                    _count = rnd.Next(_values[0], _values[1] + 1);
                }
                else if (_values[0] > 0)
                {
                    _count = _values[0];
                }
                int quality = rnd.Next(_values[2], _values[3] + 1);
                if (quality < 1)
                {
                    quality = 1;
                }
                ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_item).type, quality, quality, false, null, 1);
                Give(_cInfo, _itemValue, _count);
            }
        }
Example #18
0
        public IEnumerator _Effect1(EntityPlayer player, Emplacement place, OptionEffect opt)
        {
            // Careful, place.direction is the "to" (or I need a range option somewhere, or natural fadeaway)
            float y = 1.1f; // air above surface (+1) + offset

            // foreach (Emplacement place in Iter.On(Placer.Get(player.GetPosition()))) {
            Printer.Log(40, "FireStorm _Effect1:", place, opt.OptionItem.item); // line manage +5;
            if (place.valid)
            {
                // Vector3i at = Geo3D.Surface(Vectors.ToInt(place.position));
                Vector3i at = Geo3D.Surface(Vectors.ToInt(place.position), -1, Geo3D.IsGroundOrBuilding);
                for (int x = 0; x < opt.OptionShape.shape.x; x++)
                {
                    for (int z = 0; z < opt.OptionShape.shape.z; z++)
                    {
                        Vector3 shift = new Vector3(3 * x, y, 3 * z); // TODO randomize
                        int     echos = 1;
                        if (ItemClass.GetItem(opt.OptionItem.item, false).ItemClass.Properties.Contains("Replicates"))
                        {
                            echos = 3;
                        }
                        yield return(Zombiome.Routines.Start(
                                         Fire.ThrowItem(Vectors.ToFloat(at) + shift, opt.OptionItem.item, echos),
                                         "FireStorm-spawnItemGhost"
                                         ));
                    }
                }
            }
            else
            {
                Printer.Log(41, "Invalid place:", place, place.valid_msg);
            }
        }
Example #19
0
    internal ItemClass GetItem(ItemSlot itemSlot)
    {
        int ItemReference = 0;

        if (itemSlot == ItemSlot.ARMOR)
        {
            ItemReference = ArmorEquippedID;
        }
        if (itemSlot == ItemSlot.WEAPON)
        {
            ItemReference = WeaponEquippedID;
        }
        if (itemSlot == ItemSlot.MISC)
        {
            ItemReference = MiscEquippedID;
        }
        if (itemSlot == ItemSlot.SHIELDS)
        {
            ItemReference = ShieldEquippedID;
        }
        if (itemSlot == ItemSlot.ENGINES)
        {
            ItemReference = EngineEquippedID;
        }
        return(ItemClass.GetItem(itemSlot, ItemReference));
    }
Example #20
0
        public static void SpawnItems(ClientInfo _cInfo)
        {
            try
            {
                if (StartingItems.Dict.Count > 0)
                {
                    World world = GameManager.Instance.World;
                    if (world.Players.dict.ContainsKey(_cInfo.entityId))
                    {
                        EntityPlayer _player = PersistentOperations.GetEntityPlayer(_cInfo.entityId);
                        if (_player != null && _player.IsSpawned() && !_player.IsDead())
                        {
                            PersistentContainer.Instance.Players[_cInfo.CrossplatformId.CombinedString].StartingItems = true;
                            PersistentContainer.DataChange = true;
                            List <string> _itemList = StartingItems.Dict.Keys.ToList();
                            for (int i = 0; i < _itemList.Count; i++)
                            {
                                string _item = _itemList[i];
                                StartingItems.Dict.TryGetValue(_item, out int[]  _itemData);
                                ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_item, false).type, false);
                                if (_itemValue.HasQuality && _itemData[1] > 0)
                                {
                                    _itemValue.Quality = _itemData[1];
                                }
                                EntityItem entityItem = new EntityItem();
                                entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                                {
                                    entityClass     = EntityClass.FromString("item"),
                                    id              = EntityFactory.nextEntityID++,
                                    itemStack       = new ItemStack(_itemValue, _itemData[0]),
                                    pos             = world.Players.dict[_cInfo.entityId].position,
                                    rot             = new 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.Despawned);
                                Thread.Sleep(TimeSpan.FromSeconds(1));
                            }
                            Log.Out(string.Format("[SERVERTOOLS] '{0}' with id '{1}' received their starting items", _cInfo.playerName, _cInfo.CrossplatformId.CombinedString));
                            SingletonMonoBehaviour <SdtdConsole> .Instance.Output(string.Format("[SERVERTOOLS] '{0}' with id '{1}' received their starting items", _cInfo.playerName, _cInfo.CrossplatformId.CombinedString));

                            Phrases.Dict.TryGetValue("StartingItems1", out string _phrase);
                            ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                        }
                        else
                        {
                            SingletonMonoBehaviour <SdtdConsole> .Instance.Output(string.Format("[SERVERTOOLS] Player with id '{0}' has not spawned. Unable to give starting items", _cInfo.CrossplatformId.CombinedString));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Out(string.Format("[SERVERTOOLS] Error in GiveStartingItemsConsole.SpawnItems: {0}", e.Message));
            }
        }
Example #21
0
 public static void BuyAuction(ClientInfo _cInfo, int _purchase, int _price)
 {
     if (AuctionItems.TryGetValue(_purchase, out string _steamId))
     {
         if (PersistentContainer.Instance.Players[_steamId].Auction != null && PersistentContainer.Instance.Players[_steamId].Auction.Count > 0)
         {
             PersistentContainer.Instance.Players[_steamId].Auction.TryGetValue(_purchase, out ItemDataSerializable _itemData);
             ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_itemData.name, false).type, false);
             if (_itemValue != null)
             {
                 _itemValue.UseTimes = _itemData.useTimes;
                 _itemValue.Quality  = _itemData.quality;
                 World      world      = GameManager.Instance.World;
                 EntityItem entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                 {
                     entityClass     = EntityClass.FromString("item"),
                     id              = EntityFactory.nextEntityID++,
                     itemStack       = new ItemStack(_itemValue, _itemData.count),
                     pos             = world.Players.dict[_cInfo.entityId].position,
                     rot             = new 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.Despawned);
                 AuctionItems.Remove(_purchase);
                 PersistentContainer.Instance.Players[_steamId].Auction.Remove(_purchase);
                 PersistentContainer.Instance.AuctionPrices.Remove(_purchase);
                 PersistentContainer.DataChange = true;
                 Wallet.SubtractCoinsFromWallet(_cInfo.playerId, _price);
                 float _fee           = _price * ((float)Tax / 100);
                 int   _adjustedPrice = _price - (int)_fee;
                 Wallet.AddCoinsToWallet(_steamId, _adjustedPrice);
                 string _playerName = PersistentOperations.GetPlayerDataFileFromSteamId(_steamId).ecd.entityName;
                 using (StreamWriter sw = new StreamWriter(filepath, true, Encoding.UTF8))
                 {
                     sw.WriteLine(string.Format("{0}: {1} {2} has purchased auction entry {3}, profits went to steam id {4} {5}", DateTime.Now, _cInfo.playerId, _cInfo.playerName, _purchase, _steamId, _playerName));
                     sw.WriteLine();
                     sw.Flush();
                     sw.Close();
                 }
                 Phrases.Dict.TryGetValue(629, out string _phrase629);
                 _phrase629 = _phrase629.Replace("{Count}", _itemData.count.ToString());
                 _phrase629 = _phrase629.Replace("{ItemName}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.GetItemName());
                 _phrase629 = _phrase629.Replace("{Value}", _price.ToString());
                 _phrase629 = _phrase629.Replace("{CoinName}", Wallet.Coin_Name);
                 ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase629 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                 ClientInfo _cInfo2 = ConnectionManager.Instance.Clients.ForPlayerId(_steamId);
                 if (_cInfo2 != null)
                 {
                     Phrases.Dict.TryGetValue(630, out string _phrase630);
                     ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase630 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                 }
             }
         }
     }
 }
Example #22
0
        public static bool IsValidItem(string itemName)
        {
            ItemValue itemValue = ItemClass.GetItem(itemName, false);

            if (itemValue.type != ItemValue.None.type)
            {
                return(true);
            }
            return(false);
        }
        public static void Send(ClientInfo _cInfo)
        {
            if (StartingItems.startItemList.Count > 0)
            {
                World world = GameManager.Instance.World;
                foreach (KeyValuePair <string, int[]> kvp in StartingItems.startItemList)
                {
                    ItemValue itemValue;
                    var       itemId = 4096;
                    int       _itemId;
                    if (int.TryParse(kvp.Key, out _itemId))
                    {
                        int calc = (_itemId + 4096);
                        itemId    = calc;
                        itemValue = ItemClass.list[itemId] == null ? ItemValue.None : new ItemValue(itemId, kvp.Value[1], kvp.Value[1], true);
                    }
                    else
                    {
                        if (!ItemClass.ItemNames.Contains(kvp.Key))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Unable to find item {0}", kvp.Key));
                        }

                        itemValue = new ItemValue(ItemClass.GetItem(kvp.Key).type, kvp.Value[1], kvp.Value[1], true);
                    }

                    if (Equals(itemValue, ItemValue.None))
                    {
                        Log.Out(string.Format("[SERVERTOOLS] Unable to find item {0}", kvp.Key));
                    }
                    var entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                    {
                        entityClass     = EntityClass.FromString("item"),
                        id              = EntityFactory.nextEntityID++,
                        itemStack       = new ItemStack(itemValue, kvp.Value[0]),
                        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("Spawned starting item {0} for {1}.", itemValue.ItemClass.localizedName ?? itemValue.ItemClass.Name, _cInfo.playerName));
                    Log.Out(string.Format("[SERVERTOOLS] Spawned starting item {0} for {1}", itemValue.ItemClass.localizedName ?? itemValue.ItemClass.Name, _cInfo.playerName));
                }
                string _phrase806;
                if (!Phrases.Dict.TryGetValue(806, out _phrase806))
                {
                    _phrase806 = "{PlayerName} have received the starting items. Check your inventory. If full, check the ground.";
                }
                _phrase806 = _phrase806.Replace("{PlayerName}", _cInfo.playerName);
                _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", Config.Chat_Response_Color, _phrase806), Config.Server_Response_Name, false, "ServerTools", false));
            }
        }
Example #24
0
 public static void AuctionList(ClientInfo _cInfo)
 {
     try
     {
         if (AuctionItems.Count > 0)
         {
             if (PersistentContainer.Instance.AuctionPrices != null)
             {
                 Dictionary <int, int> _auctionPrices = PersistentContainer.Instance.AuctionPrices;
                 List <string>         playerlist     = AuctionItems.Values.ToList();
                 if (playerlist != null && playerlist.Count > 0)
                 {
                     for (int i = 0; i < playerlist.Count; i++)
                     {
                         string _steamId = playerlist[i];
                         if (PersistentContainer.Instance.Players[_steamId].Auction != null && PersistentContainer.Instance.Players[_steamId].Auction.Count > 0)
                         {
                             Dictionary <int, ItemDataSerializable> _auctionItems = PersistentContainer.Instance.Players[_steamId].Auction;
                             foreach (var _item in _auctionItems)
                             {
                                 ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_item.Value.name, false).type, false);
                                 if (_itemValue != null)
                                 {
                                     if (_auctionPrices.TryGetValue(_item.Key, out int _price))
                                     {
                                         Phrases.Dict.TryGetValue(625, out string _phrase625);
                                         _phrase625 = _phrase625.Replace("{Id}", _item.Key.ToString());
                                         _phrase625 = _phrase625.Replace("{Count}", _item.Value.count.ToString());
                                         _phrase625 = _phrase625.Replace("{Item}", _itemValue.ItemClass.GetLocalizedItemName() ?? _itemValue.ItemClass.GetItemName());
                                         _phrase625 = _phrase625.Replace("{Quality}", _item.Value.quality.ToString());
                                         _phrase625 = _phrase625.Replace("{Durability}", (_item.Value.useTimes / _itemValue.MaxUseTimes * 100).ToString());
                                         _phrase625 = _phrase625.Replace("{Price}", _price.ToString());
                                         _phrase625 = _phrase625.Replace("{Coin}", Wallet.Coin_Name);
                                         ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase625 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             Phrases.Dict.TryGetValue(626, out string _phrase626);
             ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase626 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in AuctionBox.AuctionList: {0}", e.Message));
     }
 }
 public static void SpawnItems(ClientInfo _cInfo)
 {
     try
     {
         if (ItemList.Count > 0)
         {
             PersistentContainer.Instance.Players[_cInfo.playerId].StartingItems = true;
             PersistentContainer.Instance.Save();
             World         world     = GameManager.Instance.World;
             List <string> _itemList = ItemList.Keys.ToList();
             for (int i = 0; i < _itemList.Count; i++)
             {
                 string _item = _itemList[i];
                 int[]  _itemData;
                 if (ItemList.TryGetValue(_item, out _itemData))
                 {
                     ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_item, false).type, false);
                     if (_itemValue.HasQuality && _itemData[1] > 0)
                     {
                         _itemValue.Quality = _itemData[1];
                     }
                     EntityItem entityItem = new EntityItem();
                     entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                     {
                         entityClass     = EntityClass.FromString("item"),
                         id              = EntityFactory.nextEntityID++,
                         itemStack       = new ItemStack(_itemValue, _itemData[0]),
                         pos             = world.Players.dict[_cInfo.entityId].position,
                         rot             = new 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.Despawned);
                     Thread.Sleep(TimeSpan.FromSeconds(1));
                 }
             }
             Log.Out(string.Format("[SERVERTOOLS] {0} with steam id {1} received their starting items", _cInfo.playerName, _cInfo.playerId));
             SdtdConsole.Instance.Output(string.Format("[SERVERTOOLS] {0} with steam id {1} received their starting items", _cInfo.playerName, _cInfo.playerId));
             string _phrase806;
             if (!Phrases.Dict.TryGetValue(806, out _phrase806))
             {
                 _phrase806 = "You have received the starting items. Check your inventory. If full, check the ground.";
             }
             ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _phrase806 + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null);
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in StartingItems.SpawnItems: {0}", e.Message));
     }
 }
Example #26
0
 public static void CancelAuction(ClientInfo _cInfo, string _auctionId)
 {
     if (int.TryParse(_auctionId, out int _id))
     {
         if (AuctionItems.ContainsKey(_id))
         {
             if (PersistentContainer.Instance.Players[_cInfo.playerId].Auction != null && PersistentContainer.Instance.Players[_cInfo.playerId].Auction.Count > 0)
             {
                 if (PersistentContainer.Instance.Players[_cInfo.playerId].Auction.TryGetValue(_id, out ItemDataSerializable _itemData))
                 {
                     ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_itemData.name, false).type, false);
                     if (_itemValue != null)
                     {
                         _itemValue.UseTimes = _itemData.useTimes;
                         _itemValue.Quality  = _itemData.quality;
                         World world      = GameManager.Instance.World;
                         var   entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                         {
                             entityClass     = EntityClass.FromString("item"),
                             id              = EntityFactory.nextEntityID++,
                             itemStack       = new ItemStack(_itemValue, _itemData.count),
                             pos             = world.Players.dict[_cInfo.entityId].position,
                             rot             = new 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.Despawned);
                         AuctionItems.Remove(_id);
                         PersistentContainer.Instance.Players[_cInfo.playerId].Auction.Remove(_id);
                         PersistentContainer.Instance.AuctionPrices.Remove(_id);
                         PersistentContainer.DataChange = true;
                         using (StreamWriter sw = new StreamWriter(filepath, true, Encoding.UTF8))
                         {
                             sw.WriteLine(string.Format("{0}: {1} {2} has cancelled their auction entry # {3}.", DateTime.Now, _cInfo.playerId, _cInfo.playerName, _cInfo.entityId));
                             sw.WriteLine();
                             sw.Flush();
                             sw.Close();
                         }
                         Phrases.Dict.TryGetValue(631, out string _phrase631);
                         ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase631 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                     }
                 }
             }
         }
         else
         {
             Phrases.Dict.TryGetValue(632, out string _phrase632);
             ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase632 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
         }
     }
 }
    public override void Init(EntityAlive _theEntity)
    {
        base.Init(_theEntity);
        this.MutexBits    = 3;
        this.executeDelay = 0.5f;

        // There is too many values that we need to read in from the entity, so we'll read them directly from the entityclass
        EntityClass entityClass = EntityClass.list[_theEntity.entityClass];

        this.lstFoodBins   = ConfigureEntityClass("FoodBins", entityClass);
        this.lstFoodItems  = ConfigureEntityClass("FoodItems", entityClass);
        this.lstWaterBins  = ConfigureEntityClass("WaterBins", entityClass);
        this.lstWaterItems = ConfigureEntityClass("WaterItems", entityClass);


        this.lstHomeBlocks   = ConfigureEntityClass("HomeBlocks", entityClass);
        this.lstHungryBuffs  = ConfigureEntityClass("HungryBuffs", entityClass);
        this.lstThirstyBuffs = ConfigureEntityClass("ThirstyBuffs", entityClass);

        this.lstSanitation      = ConfigureEntityClass("ToiletBlocks", entityClass);
        this.lstSanitationBuffs = ConfigureEntityClass("SanitationBuffs", entityClass);

        if (entityClass.Properties.Values.ContainsKey("SanitationBlock"))
        {
            this.strSanitationBlock = entityClass.Properties.Values["SanitationBlock"];
        }

        this.lstBeds            = ConfigureEntityClass("Beds", entityClass);
        this.lstProductionBuffs = ConfigureEntityClass("ProductionFinishedBuff", entityClass);


        if (entityClass.Properties.Classes.ContainsKey("ProductionItems"))
        {
            DynamicProperties dynamicProperties3 = entityClass.Properties.Classes["ProductionItems"];
            foreach (KeyValuePair <string, object> keyValuePair in dynamicProperties3.Values.Dict.Dict)
            {
                ProductionItem item = new ProductionItem();
                item.item  = ItemClass.GetItem(keyValuePair.Key, false);
                item.Count = int.Parse(dynamicProperties3.Values[keyValuePair.Key]);


                String strCvar = "Nothing";
                if (dynamicProperties3.Params1.TryGetValue(keyValuePair.Key, out strCvar))
                {
                    item.cvar = strCvar;
                }

                this.lstProductionItem.Add(item);
                DisplayLog("Adding Production Item: " + keyValuePair.Key + " with a count of: " + item.Count + " and will reset: " + strCvar);
            }
        }
    }
    /**
     * Executing the drop
     */

    public override void Execute(MinEventParams _params)
    {
        for (int i = 0; i < this.targets.Count; i++)
        {
            Log.Out("Checking for Local Player");
            if (this.targets[i] as EntityAlive != null)
            {
                Log.Out("Player Found! Dropping item on ground.");
                EntityHelper.DropItemOnGround(this.targets[i], ItemClass.GetItem(this.item), this.count);
            }
            Log.Warning("Player not found...");
        }
    }
Example #29
0
    public override void Execute(MinEventParams _params)
    {
        EntityPlayerLocal entityPlayer = _params.Self as EntityPlayerLocal;

        if (_params.Self as EntityPlayerLocal != null && this.CreateItem != null && this.CreateItemCount > 0)
        {
            ItemStack itemStack = new ItemStack(ItemClass.GetItem(this.CreateItem, false), this.CreateItemCount);
            if (!LocalPlayerUI.GetUIForPlayer(entityPlayer).xui.PlayerInventory.AddItem(itemStack, true))
            {
                entityPlayer.world.gameManager.ItemDropServer(itemStack, entityPlayer.GetPosition(), Vector3.zero, -1, 60f, false);
            }
        }
    }
    /**
     * Returns a TransformerItemInput or TransformerItemOutput for the ITransformerItem passed in.
     */

    protected ITransformerItem GetITransformerItemForType(TransformationStringType type, string itemName, int itemCount, double itemProb)
    {
        switch (type)
        {
        case (TransformationStringType.INPUT):
            return(new TransformerItemInput(ItemClass.GetItem(itemName), itemCount));

        case (TransformationStringType.OUTPUT):
            return(new TransformerItemOutput(ItemClass.GetItem(itemName), itemCount, itemProb));

        default:
            throw new Exception("Item property name " + itemName + " is not an input or output string.");
        }
    }