コード例 #1
0
        private void CreateNewCLB(BasePlayer player, string name, int type, ulong skin = 0)
        {
            if (boxCreators.ContainsKey(player.userID))
            {
                if (boxCreators[player.userID].entity != null)
                {
                    ClearContainer(boxCreators[player.userID].entity);
                    boxCreators[player.userID].entity.KillMessage();
                }
                boxCreators.Remove(player.userID);
            }
            CustomBoxData boxData = boxTypes[type];
            Vector3       pos     = GetGroundPosition(player.transform.position + (player.eyes.BodyForward() * 2));

            BaseEntity box = GameManager.server.CreateEntity(boxData.boxType.Type, pos);

            if (boxData.boxType.SkinID != 0)
            {
                box.skinID = boxData.boxType.SkinID;
            }

            box.SendMessage("SetDeployedBy", player, UnityEngine.SendMessageOptions.DontRequireReceiver);
            box.Spawn();

            ClearContainer(box);

            boxCreators.Add(player.userID, new BoxCreator {
                entity = box, boxData = new CustomBoxData {
                    Name = name, boxType = boxData.boxType
                }
            });
        }
コード例 #2
0
        private void SpawnLoot(BaseEntity entity, int ID)
        {
            CLBox boxData;

            if (!clsData.lootBoxes.TryGetValue(ID, out boxData))
            {
                return;
            }

            if (!string.IsNullOrEmpty(boxData.customLoot) && clsData.customBoxes.ContainsKey(boxData.customLoot))
            {
                CustomBoxData customLoot = clsData.customBoxes[boxData.customLoot];
                if (customLoot.itemList.Count > 0)
                {
                    timer.In(3, () =>
                    {
                        ClearContainer(entity);
                        for (int i = 0; i < customLoot.itemList.Count; i++)
                        {
                            ItemStorage itemInfo = customLoot.itemList[i];
                            Item item            = CreateItem(itemInfo.ID, itemInfo.Amount, itemInfo.SkinID);
                            if (entity is LootContainer)
                            {
                                item.MoveToContainer((entity as LootContainer).inventory);
                            }
                            else
                            {
                                item.MoveToContainer((entity as StorageContainer).inventory);
                            }
                        }
                    });
                }
            }
        }
コード例 #3
0
        private void AddSpawn(BasePlayer player, int type, int time)
        {
            CustomBoxData boxData = boxTypes[type];
            Vector3       pos     = GetSpawnPos(player);
            int           ID      = GenerateRandomID();

            clsData.lootBoxes.Add(ID, new CLBox {
                Position = pos, yRotation = player.GetNetworkRotation().y, boxType = boxData.boxType, customLoot = boxData.Name, time = time
            });
            SaveData();
            InitializeNewBox(ID);
        }
コード例 #4
0
        private void StoreBoxData(BasePlayer player)
        {
            ulong ID      = player.userID;
            var   boxData = boxCreators[ID];

            var itemList = new List <Item>();

            if (boxData.entity is LootContainer)
            {
                itemList = (boxData.entity as LootContainer).inventory.itemList;
            }
            else
            {
                itemList = (boxData.entity as StorageContainer).inventory.itemList;
            }

            var storedList = new List <ItemStorage>();

            for (int i = 0; i < itemList.Count; i++)
            {
                storedList.Add(new ItemStorage {
                    ID = itemList[i].info.itemid, Amount = itemList[i].amount, Shortname = itemList[i].info.shortname, SkinID = itemList[i].skin
                });
            }

            if (storedList.Count == 0)
            {
                SendMSG(player, MSG("noItems", player.UserIDString));
                boxData.entity.KillMessage();
                boxCreators.Remove(player.userID);
                return;
            }
            var data = new CustomBoxData {
                boxType = boxData.boxData.boxType, Name = boxData.boxData.Name, itemList = storedList
            };

            clsData.customBoxes.Add(boxData.boxData.Name, data);
            boxTypes.Add(boxTypes.Count + 1, data);
            SaveData();
            SendMSG(player, string.Format(MSG("boxCreated", player.UserIDString), boxTypes.Count, boxData.boxData.Name));
            ClearContainer(boxData.entity);
            boxData.entity.KillMessage();
            boxCreators.Remove(player.userID);
        }