private static void Penalty(string _id)
 {
     try
     {
         PlayerDataFile _playerDataFile = PersistentOperations.GetPlayerDataFileFromSteamId(_id);
         if (_playerDataFile != null)
         {
             PersistentPlayerData _persistentPlayerData = PersistentOperations.GetPersistentPlayerDataFromSteamId(_id);
             if (_persistentPlayerData != null)
             {
                 GC.Collect();
                 MemoryPools.Cleanup();
                 EntityBackpack entityBackpack = new EntityBackpack();
                 entityBackpack               = EntityFactory.CreateEntity("Backpack".GetHashCode(), _playerDataFile.ecd.pos + Vector3.up * 2f) as EntityBackpack;
                 entityBackpack.RefPlayerId   = _playerDataFile.ecd.clientEntityId;
                 entityBackpack.lootContainer = new TileEntityLootContainer(null);
                 entityBackpack.lootContainer.SetUserAccessing(true);
                 entityBackpack.lootContainer.SetEmpty();
                 entityBackpack.lootContainer.lootListIndex = entityBackpack.GetLootList();
                 entityBackpack.lootContainer.SetContainerSize(LootContainer.lootList[entityBackpack.GetLootList()].size, true);
                 if (All || Bag)
                 {
                     for (int i = 0; i < _playerDataFile.bag.Length; i++)
                     {
                         if (!_playerDataFile.bag[i].IsEmpty())
                         {
                             entityBackpack.lootContainer.AddItem(_playerDataFile.bag[i]);
                             _playerDataFile.bag[i] = ItemStack.Empty.Clone();
                         }
                     }
                 }
                 if (All || Belt)
                 {
                     for (int i = 0; i < _playerDataFile.inventory.Length; i++)
                     {
                         if (!_playerDataFile.inventory[i].IsEmpty())
                         {
                             entityBackpack.lootContainer.AddItem(_playerDataFile.inventory[i]);
                             _playerDataFile.inventory[i] = ItemStack.Empty.Clone();
                         }
                     }
                 }
                 if (All || Equipment)
                 {
                     ItemValue[] _equipmentValues = _playerDataFile.equipment.GetItems();
                     for (int i = 0; i < _equipmentValues.Length; i++)
                     {
                         if (!_equipmentValues[i].IsEmpty())
                         {
                             entityBackpack.lootContainer.AddItem(new ItemStack(_equipmentValues[i], 1));
                         }
                     }
                     if (!_playerDataFile.equipment.HasAnyItems())
                     {
                         _playerDataFile.equipment = new Equipment();
                     }
                 }
                 _playerDataFile.droppedBackpackPosition      = new Vector3i(_playerDataFile.ecd.pos);
                 entityBackpack.lootContainer.bPlayerBackpack = true;
                 entityBackpack.lootContainer.SetUserAccessing(false);
                 entityBackpack.lootContainer.SetModified();
                 entityBackpack.entityId    = -1;
                 entityBackpack.RefPlayerId = _playerDataFile.ecd.clientEntityId;
                 EntityCreationData entityCreationData = new EntityCreationData(entityBackpack);
                 entityCreationData.entityName    = string.Format(Localization.Get("playersBackpack", ""), _playerDataFile.ecd.entityName);
                 entityCreationData.id            = -1;
                 entityCreationData.lootContainer = entityBackpack.lootContainer.Clone();
                 PersistentOperations.SavePlayerDataFile(_id, _playerDataFile);
                 GameManager.Instance.RequestToSpawnEntityServer(entityCreationData);
                 entityBackpack.OnEntityUnload();
                 BattleLogger.Players.Remove(_id);
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in BattleLogger.Penalty: {0}.", e.Message));
     }
 }
Beispiel #2
0
 private static void Penalty(ClientInfo _cInfo)
 {
     try
     {
         PlayerDataFile _pdf = PersistentOperations.GetPlayerDataFileFromSteamId(_cInfo.playerId);
         if (_pdf != null)
         {
             Vector3i _pos = new Vector3i((int)_pdf.ecd.pos.x, (int)_pdf.ecd.pos.y, (int)_pdf.ecd.pos.z);
             if (GameManager.Instance.World.IsChunkAreaLoaded(_pos.x, _pos.y, _pos.z))
             {
                 Chunk chunk = (Chunk)GameManager.Instance.World.GetChunkFromWorldPos(_pos.x, _pos.y, _pos.z);
                 if (chunk != null)
                 {
                     BlockValue _blockValue = Block.GetBlockValue("cntStorageChest");
                     if (_blockValue.Block != null)
                     {
                         GameManager.Instance.World.SetBlockRPC(chunk.ClrIdx, _pos, _blockValue);
                         TileEntityLootContainer tileEntityLootContainer = GameManager.Instance.World.GetTileEntity(chunk.ClrIdx, _pos) as TileEntityLootContainer;
                         if (tileEntityLootContainer != null)
                         {
                             if (All || Bag)
                             {
                                 for (int i = 0; i < _pdf.bag.Length; i++)
                                 {
                                     if (!_pdf.bag[i].IsEmpty())
                                     {
                                         tileEntityLootContainer.AddItem(_pdf.bag[i]);
                                         _pdf.bag[i] = ItemStack.Empty.Clone();
                                     }
                                 }
                             }
                             if (All || Belt)
                             {
                                 for (int i = 0; i < _pdf.inventory.Length; i++)
                                 {
                                     if (!_pdf.inventory[i].IsEmpty())
                                     {
                                         tileEntityLootContainer.AddItem(_pdf.inventory[i]);
                                         _pdf.inventory[i] = ItemStack.Empty.Clone();
                                     }
                                 }
                             }
                             if (All || Equipment)
                             {
                                 ItemValue[] _equipmentValues = _pdf.equipment.GetItems();
                                 for (int i = 0; i < _equipmentValues.Length; i++)
                                 {
                                     if (!_equipmentValues[i].IsEmpty())
                                     {
                                         ItemStack _itemStack = new ItemStack(_equipmentValues[i], 1);
                                         tileEntityLootContainer.AddItem(_itemStack);
                                         _equipmentValues[i].Clear();
                                     }
                                 }
                             }
                             if (tileEntityLootContainer.IsEmpty())
                             {
                                 GameManager.Instance.World.SetBlockRPC(chunk.ClrIdx, _pos, BlockValue.Air);
                             }
                             else
                             {
                                 tileEntityLootContainer.SetModified();
                             }
                             PersistentOperations.SavePlayerDataFile(_cInfo.playerId, _pdf);
                         }
                     }
                 }
             }
             else
             {
                 ChunkManager.ChunkObserver _observer = GameManager.Instance.AddChunkObserver(_pos.ToVector3(), false, 2, -1);
                 if (_observer != null)
                 {
                     Thread.Sleep(1000);
                     Chunk _chunk = (Chunk)GameManager.Instance.World.GetChunkFromWorldPos(_pos.x, _pos.y, _pos.z);
                     if (_chunk != null)
                     {
                         EntityBackpack entityBackpack = new EntityBackpack();
                         entityBackpack               = EntityFactory.CreateEntity("Backpack".GetHashCode(), _pdf.ecd.pos + Vector3.up * 2f) as EntityBackpack;
                         entityBackpack.RefPlayerId   = _pdf.ecd.clientEntityId;
                         entityBackpack.lootContainer = new TileEntityLootContainer(null);
                         entityBackpack.lootContainer.SetUserAccessing(true);
                         entityBackpack.lootContainer.SetEmpty();
                         entityBackpack.lootContainer.lootListIndex = entityBackpack.GetLootList();
                         entityBackpack.lootContainer.SetContainerSize(LootContainer.lootList[entityBackpack.GetLootList()].size, true);
                         if (All || Bag)
                         {
                             for (int i = 0; i < _pdf.bag.Length; i++)
                             {
                                 if (!_pdf.bag[i].IsEmpty())
                                 {
                                     entityBackpack.lootContainer.AddItem(_pdf.bag[i]);
                                     _pdf.bag[i] = ItemStack.Empty.Clone();
                                 }
                             }
                         }
                         if (All || Belt)
                         {
                             for (int i = 0; i < _pdf.inventory.Length; i++)
                             {
                                 if (!_pdf.inventory[i].IsEmpty())
                                 {
                                     entityBackpack.lootContainer.AddItem(_pdf.inventory[i]);
                                     _pdf.inventory[i] = ItemStack.Empty.Clone();
                                 }
                             }
                         }
                         if (All || Equipment)
                         {
                             ItemValue[] _equipmentValues = _pdf.equipment.GetItems();
                             for (int i = 0; i < _equipmentValues.Length; i++)
                             {
                                 if (!_equipmentValues[i].IsEmpty())
                                 {
                                     ItemStack _itemStack = new ItemStack(_equipmentValues[i], 1);
                                     entityBackpack.lootContainer.AddItem(_itemStack);
                                     _equipmentValues[i].Clear();
                                 }
                             }
                         }
                         _pdf.droppedBackpackPosition = new Vector3i(_pdf.ecd.pos);
                         entityBackpack.lootContainer.bPlayerBackpack = true;
                         entityBackpack.lootContainer.SetUserAccessing(false);
                         entityBackpack.lootContainer.SetModified();
                         entityBackpack.entityId    = -1;
                         entityBackpack.RefPlayerId = _pdf.ecd.clientEntityId;
                         EntityCreationData entityCreationData = new EntityCreationData(entityBackpack);
                         entityCreationData.entityName    = string.Format(Localization.Get("playersBackpack"), _pdf.ecd.entityName);
                         entityCreationData.id            = -1;
                         entityCreationData.lootContainer = entityBackpack.lootContainer.Clone();
                         PersistentOperations.SavePlayerDataFile(_cInfo.playerId, _pdf);
                         GameManager.Instance.RequestToSpawnEntityServer(entityCreationData);
                         entityBackpack.OnEntityUnload();
                     }
                     GameManager.Instance.RemoveChunkObserver(_observer);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in ExitCommand.Penalty: {0}", e.Message));
     }
 }