public bool CheckContainer() { this.theEntity.SetLookPosition(seekPos); Ray lookRay = new Ray(this.theEntity.position, theEntity.GetLookVector()); if (!Voxel.Raycast(this.theEntity.world, lookRay, Constants.cDigAndBuildDistance, -538480645, 4095, 0f)) { DisplayLog(" Ray cast is invalid"); return(false); // Not seeing the target. } if (!Voxel.voxelRayHitInfo.bHitValid) { DisplayLog(" Look cast is not valid."); return(false); // Missed the target. Overlooking? } // float sqrMagnitude2 = (this.seekPos - this.theEntity.position).sqrMagnitude; //if (sqrMagnitude2 > 1f) //{ // return false; // too far away from it //} DisplayLog(" Looking at: " + this.seekPos + " My position is: " + this.theEntity.position); TileEntityLootContainer tileEntityLootContainer = this.theEntity.world.GetTileEntity(Voxel.voxelRayHitInfo.hit.clrIdx, new Vector3i(seekPos)) as TileEntityLootContainer; if (tileEntityLootContainer == null) { DisplayLog("No Loot container here."); return(false); } //Debug.Log(" Starting: " + "IsLooting"); //this.theEntity.emodel.avatarController.SetBool("IsLooting", true); //CoroutineJobTasks job = new CoroutineJobTasks(); //job.Start(); //Debug.Log(" Ending " + "IsLooting"); //this.theEntity.emodel.avatarController.SetBool("IsLooting", false); //job.ConfigureRoutine(this.theEntity, "IsLooting", 5f); //job.StartCoroutine("Start"); GetItemFromContainer(tileEntityLootContainer); if (tileEntityLootContainer.IsEmpty()) { DisplayLog(" Looted Container."); return(true); } else { DisplayLog("Did not loot the container."); } return(false); }
private static void Penalty(PlayerDataFile _pdf, ClientInfo _cInfo) { try { Chunk chunk = (Chunk)GameManager.Instance.World.GetChunkFromWorldPos((int)_pdf.ecd.pos.x, (int)_pdf.ecd.pos.y, (int)_pdf.ecd.pos.z); if (chunk != null) { BlockValue _blockValue = Block.GetBlockValue("cntStorageChest"); if (_blockValue.Block != null) { Vector3i _pos = new Vector3i((int)_pdf.ecd.pos.x, (int)_pdf.ecd.pos.y, (int)_pdf.ecd.pos.z); 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); } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in BattleLogger.Penalty: {0}", e.Message)); } }
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)); } }