コード例 #1
0
ファイル: Wallet.cs プロジェクト: pharrisee/7dtd-ServerTools
        public static void AddCurrency(string _id, int _amount)
        {
            ClientInfo cInfo = PersistentOperations.GetClientInfoFromNameOrId(_id);

            if (cInfo != null)
            {
                EntityPlayer player = PersistentOperations.GetEntityPlayer(cInfo.entityId);
                if (player != null)
                {
                    if (player.IsSpawned())
                    {
                        ItemValue itemValue = ItemClass.GetItem(PersistentOperations.Currency_Item, false);
                        if (itemValue != null)
                        {
                            List <int> stackList = new List <int>();
                            int        maxStack  = itemValue.ItemClass.Stacknumber.Value;
                            if (_amount > maxStack)
                            {
                                for (int i = 0; i < 100; i++)
                                {
                                    if (_amount > maxStack)
                                    {
                                        _amount = _amount - maxStack;
                                        stackList.Add(maxStack);
                                    }
                                    else
                                    {
                                        stackList.Add(_amount);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                stackList.Add(_amount);
                            }
                            for (int i = 0; i < stackList.Count; i++)
                            {
                                World      world      = GameManager.Instance.World;
                                EntityItem entityItem = (EntityItem)EntityFactory.CreateEntity(new EntityCreationData
                                {
                                    entityClass     = EntityClass.FromString("item"),
                                    id              = EntityFactory.nextEntityID++,
                                    itemStack       = new ItemStack(itemValue, stackList[i]),
                                    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);
                            }
                        }
                    }
                    else
                    {
                        Timers.Wallet_Add_SingleUseTimer(cInfo.CrossplatformId.CombinedString, _amount);
                    }
                }
            }
            else
            {
                PersistentContainer.Instance.Players[cInfo.CrossplatformId.CombinedString].PlayerWallet += _amount;
                PersistentContainer.DataChange = true;
            }
        }