Пример #1
0
        public static void DoCleanup(World world, ChunkManager.ChunkObserver co, string commandType, int ts = 0, ThreadManager.TaskInfo taskInfo = null)
        {
            var bcmTask = BCTask.GetTask(commandType, taskInfo?.GetHashCode());

            for (var i = 0; i < ts; i++)
            {
                if (bcmTask != null)
                {
                    bcmTask.Output = new { timer = i, total = ts }
                }
                ;
                Thread.Sleep(1000);
            }
            world.m_ChunkManager.RemoveChunkObserver(co);
        }
Пример #2
0
        public static void Execute(ClientInfo _cInfo, Vector3i _vec3i)
        {
            World   world = GameManager.Instance.World;
            Vector3 _vec3 = _vec3i.ToVector3();
            Chunk   chunk = (Chunk)world.GetChunkFromWorldPos(World.worldToBlockPos(_vec3));

            if (chunk != null)
            {
                bool          _found = false, _alert = false;
                List <Entity> Entities = GameManager.Instance.World.Entities.list;
                int           _counter = 0;
                for (int i = 0; i < Entities.Count; i++)
                {
                    Entity _entity = Entities[i];
                    if (_entity != null)
                    {
                        string _name = EntityClass.list[_entity.entityClass].entityClassName;
                        if (_name == "Backpack")
                        {
                            int x = (int)_entity.position.x;
                            int y = (int)_entity.position.y;
                            int z = (int)_entity.position.z;
                            if (x >= _vec3i.x - 10 && x <= _vec3i.x + 10 && y >= _vec3i.y - 10 && y <= _vec3i.y + 10 && z >= _vec3i.z - 10 && z <= _vec3i.z + 10)
                            {
                                _counter++;
                                if (_counter <= 1)
                                {
                                    _found     = true;
                                    _entityDel = _entity;
                                    _stacks    = _entity.lootContainer.GetItems();
                                }
                                if (_counter > 1)
                                {
                                    _found = false;
                                    _alert = true;
                                    continue;
                                }
                            }
                        }
                    }
                }
                if (_found)
                {
                    _entityDel.lootContainer.SetEmpty();
                    if (Observer == true)
                    {
                        world.GetGameManager().RemoveChunkObserver(_chunkObserver);
                        Observer = false;
                    }
                    _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Bag was found. Attempting to send it to you.[-]", Config.Chat_Response_Color), Config.Server_Response_Name, false, "ServerTools", false));
                    ReturnItem(_cInfo);
                    PersistentContainer.Instance.Players[_cInfo.playerId, true].LastBackpack = DateTime.Now;
                    PersistentContainer.Instance.Save();
                }
                if (!_found && !_alert)
                {
                    if (Observer == true)
                    {
                        world.GetGameManager().RemoveChunkObserver(_chunkObserver);
                        Observer = false;
                    }
                    _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}No bag was found. It may have been looted. If you are sure you have one, relog and try again.[-]", Config.Chat_Response_Color), Config.Server_Response_Name, false, "ServerTools", false));
                    LastBagPos.Remove(_cInfo.entityId);
                    Que();
                }
                if (_alert)
                {
                    if (Observer == true)
                    {
                        world.GetGameManager().RemoveChunkObserver(_chunkObserver);
                        Observer = false;
                    }
                    _cInfo.SendPackage(new NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}Too many bags were found in your dropped bag location. Can not return your items.[-]", Config.Chat_Response_Color), Config.Server_Response_Name, false, "ServerTools", false));
                    LastBagPos.Remove(_cInfo.entityId);
                    Que();
                }
            }
            else
            {
                Observer       = true;
                _chunkObserver = world.GetGameManager().AddChunkObserver(_vec3, false, 3, -1);
                que.Insert(0, _cInfo);
            }
        }
Пример #3
0
 private static bool IsPlayer(ChunkManager.ChunkObserver oe)
 {
     return(GameManager.Instance.World.Players.dict.ContainsKey(oe.entityIdToSendChunksTo));
 }
Пример #4
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));
     }
 }