using Audio; public class ItemActionExchangeItemRebirth : ItemActionExchangeItem { protected int removeWater = 0; private bool isFocusingBlock(WorldRayHitInfo _hitInfo) { for (int i = 0; i < this.focusedBlocks.Count; i++) { BlockValue other = this.focusedBlocks[i]; if (_hitInfo.hit.blockValue.Equals(other)) { return true; } } return false; } public override void ExecuteAction(ItemActionData _actionData, bool _bReleased) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction START"); if (!_bReleased) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction 1"); return; } if (_actionData.lastUseTime > 0f) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction 2"); return; } ItemInventoryData invData = _actionData.invData; Ray lookRay = invData.holdingEntity.GetLookRay(); lookRay.origin += lookRay.direction.normalized * 0.5f; //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction EntityName: " + invData.holdingEntity.EntityName); //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction Voxel.voxelRayHitInfo.bHitValid: " + Voxel.voxelRayHitInfo.bHitValid); //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction this.isFocusingBlock(Voxel.voxelRayHitInfo): " + this.isFocusingBlock(Voxel.voxelRayHitInfo)); if (!Voxel.Raycast(invData.world, lookRay, Constants.cDigAndBuildDistance, -538480645, 4095, 0.0f)) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction 3"); return; } /*if (!Voxel.Raycast(invData.world, lookRay, Constants.cDigAndBuildDistance, -538480645, 4095, 0f)) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction 3"); return; }*/ if (Voxel.voxelRayHitInfo.hit.waterValue.HasMass()) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction 4"); this.removeWater = _actionData.invData.holdingEntity.inventory.holdingCount; this.hitLiquidBlock = Voxel.voxelRayHitInfo.hit.blockValue; this.hitLiquidPos = Voxel.voxelRayHitInfo.hit.blockPos; _actionData.lastUseTime = Time.time; invData.holdingEntity.RightArmAnimationUse = true; if (this.soundStart != null) { invData.holdingEntity.PlayOneShot(this.soundStart, false); } return; } if (Voxel.voxelRayHitInfo.bHitValid && this.isFocusingBlock(Voxel.voxelRayHitInfo)) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction Block Name: " + Voxel.voxelRayHitInfo.hit.blockValue.Block.GetBlockName()); if ((Voxel.voxelRayHitInfo.hit.blockValue.Block.GetBlockName() == "FuriousRamsayWaterTank" || Voxel.voxelRayHitInfo.hit.blockValue.Block.GetBlockName() == "FuriousRamsayDewCollector") && _actionData.invData.item.GetItemName() == "bucketRiverWater") { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction A"); Chunk chunk = (Chunk)invData.world.GetChunkFromWorldPos(Voxel.voxelRayHitInfo.hit.blockPos); TileEntityWaterTankRebirth tileEntity = invData.world.GetTileEntity(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos) as TileEntityWaterTankRebirth; if (tileEntity != null) { int waterMax = tileEntity.waterMax; if (Voxel.voxelRayHitInfo.hit.blockValue.Block.Properties.Values.ContainsKey("MaxWater")) { waterMax = Int16.Parse(Voxel.voxelRayHitInfo.hit.blockValue.Block.Properties.Values["MaxWater"]); } if (tileEntity.waterCount == waterMax) { return; } else { this.removeWater = 1; this.hitLiquidBlock = Voxel.voxelRayHitInfo.hit.blockValue; this.hitLiquidPos = Voxel.voxelRayHitInfo.hit.blockPos; _actionData.lastUseTime = Time.time; invData.holdingEntity.RightArmAnimationUse = true; if (this.soundStart != null) { invData.holdingEntity.PlayOneShot(this.soundStart, false); } int waterCount = tileEntity.waterCount + 200; if (waterCount > waterMax) { waterCount = waterMax; } if (!invData.world.IsRemote()) { tileEntity.waterCount = waterCount; } else { if (SingletonMonoBehaviour.Instance.IsServer) { SingletonMonoBehaviour.Instance.SendPackage((NetPackage)NetPackageManager.GetPackage().Setup(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos, waterCount)); } else { SingletonMonoBehaviour.Instance.SendToServer((NetPackage)NetPackageManager.GetPackage().Setup(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos, waterCount)); tileEntity.waterCount = waterCount; } } } } } else if ((Voxel.voxelRayHitInfo.hit.blockValue.Block.GetBlockName() == "FuriousRamsayWaterTank" || Voxel.voxelRayHitInfo.hit.blockValue.Block.GetBlockName() == "FuriousRamsayDewCollector") && (_actionData.invData.item.GetItemName() == "drinkJarRiverWater" || _actionData.invData.item.GetItemName() == "drinkJarBoiledWater" || _actionData.invData.item.GetItemName() == "drinkJarPureMineralWater") ) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction B"); Chunk chunk = (Chunk)invData.world.GetChunkFromWorldPos(Voxel.voxelRayHitInfo.hit.blockPos); TileEntityWaterTankRebirth tileEntity = invData.world.GetTileEntity(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos) as TileEntityWaterTankRebirth; if (tileEntity != null) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction B1"); int waterMax = tileEntity.waterMax; if (Voxel.voxelRayHitInfo.hit.blockValue.Block.Properties.Values.ContainsKey("MaxWater")) { waterMax = Int16.Parse(Voxel.voxelRayHitInfo.hit.blockValue.Block.Properties.Values["MaxWater"]); } if (tileEntity.waterCount == waterMax) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction B2"); return; } else { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction B3"); this.hitLiquidBlock = Voxel.voxelRayHitInfo.hit.blockValue; this.hitLiquidPos = Voxel.voxelRayHitInfo.hit.blockPos; _actionData.lastUseTime = Time.time; invData.holdingEntity.RightArmAnimationUse = true; if (this.soundStart != null) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction B4"); invData.holdingEntity.PlayOneShot(this.soundStart, false); } int numWater = _actionData.invData.holdingEntity.inventory.holdingCount; int missingWater = waterMax - tileEntity.waterCount; this.removeWater = 0; if (numWater >= missingWater) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction B5"); this.removeWater = missingWater; } else { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction B6"); this.removeWater = numWater; } int waterCount = tileEntity.waterCount + this.removeWater; if (!invData.world.IsRemote()) { tileEntity.waterCount = waterCount; } else { if (SingletonMonoBehaviour.Instance.IsServer) { SingletonMonoBehaviour.Instance.SendPackage((NetPackage)NetPackageManager.GetPackage().Setup(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos, waterCount)); } else { SingletonMonoBehaviour.Instance.SendToServer((NetPackage)NetPackageManager.GetPackage().Setup(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos, waterCount)); tileEntity.waterCount = waterCount; } } } } } else if ((Voxel.voxelRayHitInfo.hit.blockValue.Block.GetBlockName() == "FuriousRamsayWaterTank" || Voxel.voxelRayHitInfo.hit.blockValue.Block.GetBlockName() == "FuriousRamsayDewCollector") && _actionData.invData.item.GetItemName() == "drinkJarEmpty" ) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction C"); Chunk chunk = (Chunk)invData.world.GetChunkFromWorldPos(Voxel.voxelRayHitInfo.hit.blockPos); TileEntityWaterTankRebirth tileEntity = invData.world.GetTileEntity(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos) as TileEntityWaterTankRebirth; if (tileEntity != null) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction C1"); if (tileEntity.waterCount == 0) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction C2"); return; } else { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction C3"); this.hitLiquidBlock = Voxel.voxelRayHitInfo.hit.blockValue; this.hitLiquidPos = Voxel.voxelRayHitInfo.hit.blockPos; _actionData.lastUseTime = Time.time; invData.holdingEntity.RightArmAnimationUse = true; if (this.soundStart != null) { invData.holdingEntity.PlayOneShot(this.soundStart, false); } int numEmpty = _actionData.invData.holdingEntity.inventory.holdingCount; int missingWater = 0; if (numEmpty > tileEntity.waterCount) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction C4"); missingWater = tileEntity.waterCount; } else { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction C5"); missingWater = numEmpty; } this.removeWater = missingWater; int waterCount = tileEntity.waterCount - this.removeWater; if (!invData.world.IsRemote()) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction C6"); tileEntity.waterCount = waterCount; } else { if (SingletonMonoBehaviour.Instance.IsServer) { SingletonMonoBehaviour.Instance.SendPackage((NetPackage)NetPackageManager.GetPackage().Setup(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos, waterCount)); } else { SingletonMonoBehaviour.Instance.SendToServer((NetPackage)NetPackageManager.GetPackage().Setup(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos, waterCount)); tileEntity.waterCount = waterCount; } } } } } else if ((Voxel.voxelRayHitInfo.hit.blockValue.Block.GetBlockName() == "FuriousRamsayWaterTank" || Voxel.voxelRayHitInfo.hit.blockValue.Block.GetBlockName() == "FuriousRamsayDewCollector") && _actionData.invData.item.GetItemName() == "bucketEmpty" ) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction D"); Chunk chunk = (Chunk)invData.world.GetChunkFromWorldPos(Voxel.voxelRayHitInfo.hit.blockPos); TileEntityWaterTankRebirth tileEntity = invData.world.GetTileEntity(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos) as TileEntityWaterTankRebirth; if (tileEntity != null) { if (tileEntity.waterCount < 200) { Manager.PlayInsidePlayerHead("ui_denied"); GameManager.ShowTooltip(invData.holdingEntity as EntityPlayerLocal, Localization.Get("ttNeedMoreBucketWater"), string.Empty, "ui_denied", null); return; } else { this.hitLiquidBlock = Voxel.voxelRayHitInfo.hit.blockValue; this.hitLiquidPos = Voxel.voxelRayHitInfo.hit.blockPos; _actionData.lastUseTime = Time.time; invData.holdingEntity.RightArmAnimationUse = true; if (this.soundStart != null) { invData.holdingEntity.PlayOneShot(this.soundStart, false); } int numEmpty = 200; int missingWater = 0; if (numEmpty > tileEntity.waterCount) { missingWater = tileEntity.waterCount; } else { missingWater = numEmpty; } this.removeWater = missingWater; int waterCount = tileEntity.waterCount - this.removeWater; if (!invData.world.IsRemote()) { tileEntity.waterCount = waterCount; } else { if (SingletonMonoBehaviour.Instance.IsServer) { SingletonMonoBehaviour.Instance.SendPackage((NetPackage)NetPackageManager.GetPackage().Setup(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos, waterCount)); } else { SingletonMonoBehaviour.Instance.SendToServer((NetPackage)NetPackageManager.GetPackage().Setup(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos, waterCount)); tileEntity.waterCount = waterCount; } } } } } else { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction E"); Chunk chunk = (Chunk)invData.world.GetChunkFromWorldPos(Voxel.voxelRayHitInfo.hit.blockPos); TileEntityLootContainer tileEntity = invData.world.GetTileEntity(chunk.ClrIdx, Voxel.voxelRayHitInfo.hit.blockPos) as TileEntityLootContainer; if (tileEntity != null) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction E1"); if (tileEntity.bPlayerStorage) { //Log.Out("ItemActionExchangeItemRebirth-ExecuteAction E2"); Manager.PlayInsidePlayerHead("ui_denied"); GameManager.ShowTooltip(invData.holdingEntity as EntityPlayerLocal, Localization.Get("ttNoPlumbing"), string.Empty, "ui_denied", null); return; } } /*PrefabInstance prefabFromWorldPos = GameManager.Instance.GetDynamicPrefabDecorator().GetPrefabFromWorldPos((int)Voxel.voxelRayHitInfo.hit.blockPos.x, (int)Voxel.voxelRayHitInfo.hit.blockPos.z); if (prefabFromWorldPos != null) { // RETURNS NULL FOR country_junkyard_02 // part_appliance_pile-02 (toilet) Log.Out("ItemActionExchangeItemRebirth-ExecuteAction E3 prefabFromWorldPos: " + prefabFromWorldPos.name); Manager.PlayInsidePlayerHead("ui_denied"); GameManager.ShowTooltip(invData.holdingEntity as EntityPlayerLocal, Localization.Get("ttNoPlumbing"), string.Empty, "ui_denied", null); return; }*/ this.removeWater = _actionData.invData.holdingEntity.inventory.holdingCount; this.hitLiquidBlock = Voxel.voxelRayHitInfo.hit.blockValue; this.hitLiquidPos = Voxel.voxelRayHitInfo.hit.blockPos; _actionData.lastUseTime = Time.time; invData.holdingEntity.RightArmAnimationUse = true; if (this.soundStart != null) { invData.holdingEntity.PlayOneShot(this.soundStart, false); } } } else if (Voxel.voxelRayHitInfo.bHitValid && !this.isFocusingBlock(Voxel.voxelRayHitInfo)) { if (Voxel.voxelRayHitInfo.hit.blockValue.Block.Properties.Values.ContainsKey("WaterSource")) { string WaterSource = Voxel.voxelRayHitInfo.hit.blockValue.Block.Properties.Values["WaterSource"]; if (WaterSource == "False") { Manager.PlayInsidePlayerHead("ui_denied"); GameManager.ShowTooltip(invData.holdingEntity as EntityPlayerLocal, Localization.Get("ttNoPlumbing"), string.Empty, "ui_denied", null); return; } } } } public override void OnHoldingUpdate(ItemActionData _actionData) { ////Log.Out("ItemActionExchangeItemRebirth-OnHoldingUpdate START"); if (_actionData.lastUseTime == 0f || this.IsActionRunning(_actionData)) { ////Log.Out("ItemActionExchangeItemRebirth-OnHoldingUpdate 1"); return; } QuestEventManager.Current.ExchangedFromItem(_actionData.invData.itemStack); ItemValue item = ItemClass.GetItem(this.changeItemToItem, false); if (this.removeWater > 0) { //Log.Out("ItemActionExchangeItemRebirth-OnHoldingUpdate 2"); EntityPlayerLocal player = (EntityPlayerLocal)_actionData.invData.holdingEntity; int itemIndex = player.inventory.GetFocusedItemIdx(); int decrease = 1; if (!_actionData.invData.item.GetItemName().Contains("bucket")) { decrease = this.removeWater; } //Log.Out("ItemActionExchangeItemRebirth-OnHoldingUpdate decrease: " + decrease); int numItems = player.inventory.DecItem(_actionData.invData.holdingEntity.inventory.holdingItemItemValue, decrease, false); //Log.Out("ItemActionExchangeItemRebirth-OnHoldingUpdate numItems: " + numItems); //Log.Out("ItemActionExchangeItemRebirth-OnHoldingUpdate this.changeItemToItem: " + this.changeItemToItem); ItemValue newItem = ItemClass.GetItem(this.changeItemToItem, false); ItemClass itemClass = newItem.ItemClass; ItemStack @is = new ItemStack(new ItemValue(itemClass.Id, false), decrease); bool couldAdd = player.inventory.AddItem(@is); if (!couldAdd) { couldAdd = player.bag.AddItem(@is); if (!couldAdd) { GameManager.Instance.ItemDropServer(@is, player.GetPosition(), new Vector3(0.5f, 0f, 0.5f), player.entityId, 60f, false); player.PlayOneShot("itemdropped", false); } } player.PlayerUI.xui.playerUI.entityPlayer.AddUIHarvestingItem(@is, true); this.removeWater = 0; _actionData.lastUseTime = 0; } //Log.Out("ItemActionExchangeItemRebirth-OnHoldingUpdate END"); } }