// Take logic to replace it with the Downgrade block, matching rotations. private void TakeTarget(object obj) { World world = GameManager.Instance.World; object[] array = (object[])obj; int clrIdx = (int)array[0]; BlockValue _blockValue = (BlockValue)array[1]; Vector3i vector3i = (Vector3i)array[2]; BlockValue block = world.GetBlock(vector3i); EntityPlayerLocal entityPlayerLocal = array[3] as EntityPlayerLocal; // Find the block value for the pick up value, and add it to the inventory BlockValue pickUpBlock = Block.GetBlockValue(this.PickedUpItemValue); LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal); ItemStack itemStack = new ItemStack(pickUpBlock.ToItemValue(), 1); if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack, true)) { uiforPlayer.xui.PlayerInventory.DropItem(itemStack); } entityPlayerLocal.PlayOneShot("Sounds/DestroyBlock/wooddestroy1"); // Damage the block for its full health this.DamageBlock(world, clrIdx, vector3i, block, block.Block.blockMaterial.MaxDamage, entityPlayerLocal.entityId, false); }
public override bool CheckRequirement(EntityPlayer player) { int count = 0; if (string.IsNullOrEmpty(Value)) { Value = "1"; } float flValue = 1f; float.TryParse(Value, out flValue); LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal); XUiM_PlayerInventory playerInventory = uiforPlayer.xui.PlayerInventory; ItemValue item = ItemClass.GetItem(ID); if (item != null) { count = playerInventory.Backpack.GetItemCount(item, -1, -1, false); count += playerInventory.Toolbelt.GetItemCount(item, false, -1, -1); AdvLogging.DisplayLog(AdvFeatureClass, "HasItemSDX: " + item.ItemClass.GetItemName() + " Player has Count: " + count + " Needs: " + flValue); if (flValue <= count) { return(true); } } AdvLogging.DisplayLog(AdvFeatureClass, "HasItemSDX: Player does not have enough " + item.ItemClass.GetItemName() + " Count: " + count + " Needs: " + flValue); return(false); }
public override void Execute(MinEventParams _params) { EntityPlayerLocal entityPlayer = _params.Self as EntityPlayerLocal; // Loot group if (_params.Self as EntityPlayerLocal != null && this.lootgroup > 0) { ItemStack[] array = LootContainer.lootList[lootgroup].Spawn(GameManager.Instance.lootManager.Random, this.CreateItemCount, EffectManager.GetValue(PassiveEffects.LootGamestage, null, (float)entityPlayer.HighestPartyGameStage, entityPlayer, null, default(FastTags), true, true, true, true, 1, true), 0f, entityPlayer, new FastTags()); for (int i = 0; i < array.Length; i++) { if (!LocalPlayerUI.GetUIForPlayer(entityPlayer).xui.PlayerInventory.AddItem(array[i], true)) { entityPlayer.world.gameManager.ItemDropServer(array[i], entityPlayer.GetPosition(), Vector3.zero, -1, 60f, false); } } return; } // item value. if (_params.Self as EntityPlayerLocal != null && this.CreateItem != null && this.CreateItemCount > 0) { ItemStack itemStack = new ItemStack(ItemClass.GetItem(this.CreateItem, false), this.CreateItemCount); if (!LocalPlayerUI.GetUIForPlayer(entityPlayer).xui.PlayerInventory.AddItem(itemStack, true)) { entityPlayer.world.gameManager.ItemDropServer(itemStack, entityPlayer.GetPosition(), Vector3.zero, -1, 60f, false); } } }
public override bool CheckRequirement(EntityPlayer player) { LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal); // The respondent is an EntityNPC, and we don't have that. Check for the patch scripted otherEntitySDX. Entity respondent = uiforPlayer.xui.Dialog.Respondent; if (respondent == null) { respondent = uiforPlayer.xui.Dialog.otherEntitySDX; } if (respondent != null) { EntityAliveSDX myEntity = player.world.GetEntity(respondent.entityId) as EntityAliveSDX; if (myEntity != null) { bool isTame = false; if (base.Value.EqualsCaseInsensitive("not")) { isTame = !myEntity.isTame(player); } else { isTame = myEntity.isTame(player); } return(isTame); } } return(false); }
public override bool CheckRequirement(EntityPlayer player) { int count = 0; if (string.IsNullOrEmpty(Value)) { Value = "1"; } float flValue = 1f; float.TryParse(Value, out flValue); LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal); XUiM_PlayerInventory playerInventory = uiforPlayer.xui.PlayerInventory; ItemValue item = ItemClass.GetItem(ID); if (item != null) { count = playerInventory.Backpack.GetItemCount(item, -1, -1, false); count += playerInventory.Toolbelt.GetItemCount(item, false, -1, -1); if (flValue <= count) { return(true); } } return(false); }
public override void PerformAction(EntityPlayer player) { Debug.Log("Perform Action for OpenDialogSDX"); LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal); uiforPlayer.windowManager.Open("HireInformation", true, false, true); }
// Handles what happens to the contents of the box when you pick up the block. private void EventData_Event(object obj) { #region EventData_Event World world = GameManager.Instance.World; object[] array = (object[])obj; int clrIdx = (int)array[0]; BlockValue blockValue = (BlockValue)array[1]; Vector3i vector3i = (Vector3i)array[2]; BlockValue block = world.GetBlock(vector3i); EntityPlayerLocal entityPlayerLocal = array[3] as EntityPlayerLocal; TileEntityLootContainer tileEntityLootContainer = world.GetTileEntity(clrIdx, vector3i) as TileEntityLootContainer; if (tileEntityLootContainer != null) { world.GetGameManager().DropContentOfLootContainerServer(blockValue, vector3i, tileEntityLootContainer.entityId); } // Pick up the item and put it inyor your inventory. LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal); ItemStack itemStack = new ItemStack(block.ToItemValue(), 1); if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack, true)) { uiforPlayer.xui.PlayerInventory.DropItem(itemStack); } world.SetBlockRPC(clrIdx, vector3i, BlockValue.Air); #endregion }
public override void OnOpen() { LocalPlayerUI uiforPlayer = base.xui.playerUI; // The respondent is an EntityNPC, and we don't have that. Check for the patch scripted otherEntitySDX. Entity respondent = uiforPlayer.xui.Dialog.Respondent; if (respondent == null) { respondent = uiforPlayer.xui.Dialog.otherEntitySDX; } if (respondent != null) { EntityAliveSDX myEntity = uiforPlayer.entityPlayer.world.GetEntity(respondent.entityId) as EntityAliveSDX; if (myEntity != null) { Debug.Log(GetType() + " Entity is EntityAliveSDX. Displaying message"); this.hireInformationLabel.Text = Localization.Get("HireOffer_" + myEntity.EntityName, ""); if (this.hireInformationLabel.Text == "Hire_Offer_" + myEntity.EntityName) { this.hireInformationLabel.Text = "I would like to join you. Will you accept me?"; } } } base.OnOpen(); }
public void SpawnFromGroup(string strEntityGroup, EntityPlayer player) { int EntityID = 0; // If the group is set, then use it. if (string.IsNullOrEmpty(strEntityGroup)) { return; } EntityID = EntityGroups.GetRandomFromGroup(strEntityGroup); if (EntityID == -1) { return; // failed } Entity NewEntity = EntityFactory.CreateEntity(EntityID, player.position, player.rotation); if (NewEntity) { NewEntity.SetSpawnerSource(EnumSpawnerSource.StaticSpawner); GameManager.Instance.World.SpawnEntityInWorld(NewEntity); if (NewEntity is EntityAliveSDX) { LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal); uiforPlayer.windowManager.Open("JoinInformation", true, false, true); //(NewEntity as EntityAliveSDX).SetOwner(player as EntityPlayerLocal); } } else { Debug.Log(" Could not Spawn NPC for: " + player.EntityName + " : " + player.entityId); } }
public void OnGUI() { if (GameManager.IsDedicatedServer) { return; } LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityVehicle.player); //if (!Event.current.type.Equals(EventType.Repaint) || GameManager.Instance.IsPaused() || GameManager.Instance.m_GUIConsole.isInputActive || entityVehicle.uiforPlayer.windowManager.IsModalWindowOpen()) if (!Event.current.type.Equals(EventType.Repaint) || GameManager.Instance.IsPaused() || GameManager.Instance.m_GUIConsole.isInputActive || uiforPlayer.windowManager.IsModalWindowOpen()) { return; } if (entityVehicle == null || entityVehicle.player == null) { InitController(); return; } if (entityVehicle.player.movementInput.bAltCameraMove || entityVehicle.player.IsDead() || !entityVehicle.hasDriver || !(entityVehicle.HasGun() || entityVehicle.HasExplosiveLauncher())) { return; } DrawCrosshair(); }
public override bool OnBlockActivated(int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player) { EntityPlayerLocal entityPlayerLocal = _player as EntityPlayerLocal; LocalPlayerUI uiForPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal); var tileEntity = _world.GetTileEntity(_cIdx, _blockPos) as TileEntitySecureLootContainer; if (_indexInBlockActivationCommands == 4) { if (!tileEntity.IsEmpty()) { GameManager.ShowTooltipWithAlert(entityPlayerLocal, Localization.Get("ttEmptyLootContainerBeforePickup", string.Empty), "ui_denied"); return(false); } TakeItemWithTimer(_cIdx, _blockPos, _blockValue, _player); return(true); } if (_indexInBlockActivationCommands == 5) { if (uiForPlayer != null) { ((XUiWindowGroup)uiForPlayer.windowManager.GetWindow("storage_box")).Controller.GetChildByType <XUiC_StorageBoxLabelWindow>().SetTileEntity(tileEntity); uiForPlayer.windowManager.Open("storage_box", true, false, true); } return(true); } return(base.OnBlockActivated(_indexInBlockActivationCommands, _world, _cIdx, _blockPos, _blockValue, _player)); }
public void TakeItemWithTimer(int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player) { if (_blockValue.damage > 0) { GameManager.ShowTooltipWithAlert(_player as EntityPlayerLocal, Localization.Get("ttRepairBeforePickup", string.Empty), "ui_denied"); } else { LocalPlayerUI playerUi = (_player as EntityPlayerLocal).PlayerUI; playerUi.windowManager.Open("timer", true, false, true); XUiC_Timer childByType = playerUi.xui.GetChildByType <XUiC_Timer>(); TimerEventData _eventData = new TimerEventData { Data = new object[4] { _cIdx, _blockValue, _blockPos, _player } }; _eventData.Event += new TimerEventHandler(this.EventData_Event); childByType.SetTimer(_takeDelay, _eventData); } }
public override bool OnBlockActivated(int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player) { if (_blockValue.ischild) { Vector3i parentPos = Block.list[_blockValue.type].multiBlockPos.GetParentPos(_blockPos, _blockValue); BlockValue block = _world.GetBlock(parentPos); return(this.OnBlockActivated(_indexInBlockActivationCommands, _world, _cIdx, parentPos, block, _player)); } TileEntitySign tileEntitySign = _world.GetTileEntity(_cIdx, _blockPos) as TileEntitySign; if (tileEntitySign == null) { return(false); } switch (_indexInBlockActivationCommands) { case 0: if (GameManager.Instance.IsEditMode() || !tileEntitySign.IsLocked() || tileEntitySign.IsUserAllowed(GamePrefs.GetString(EnumGamePrefs.PlayerId))) { return(this.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player)); } Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locked"); return(false); case 1: tileEntitySign.SetLocked(true); Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locking"); GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerLocked"); return(true); case 2: tileEntitySign.SetLocked(false); Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/unlocking"); GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerUnlocked"); return(true); case 3: XUiC_KeypadWindow.Open(LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal), tileEntitySign); return(true); case 4: LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal); ItemStack itemStack = new ItemStack(_blockValue.ToItemValue(), 1); if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack)) { uiforPlayer.xui.PlayerInventory.DropItem(itemStack); } _world.SetBlockRPC(_cIdx, _blockPos, BlockValue.Air); return(true); default: return(false); } }
void Update() { if (GameManager.IsDedicatedServer) { return; } if (entityVehicle == null || entityVehicle.player == null) { InitController(); return; } LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityVehicle.player); //if (GameManager.Instance.IsPaused() || GameManager.Instance.m_GUIConsole.isInputActive || entityVehicle.uiforPlayer.windowManager.IsModalWindowOpen()) if (GameManager.Instance.IsPaused() || GameManager.Instance.m_GUIConsole.isInputActive || uiforPlayer.windowManager.IsModalWindowOpen()) { if (GameManager.Instance.IsPaused()) { DebugMsg("GAME WAS PAUSED!"); gameWasPaused = true; gamePausedTime = Time.time; } return; } if (!entityVehicle.hasDriver) { return; } if (gameWasPaused && Time.time - 0.2f > gamePausedTime) { OnDriverOn(); gameWasPaused = false; } //if (!(entityVehicle.HasGun() || entityVehicle.HasExplosiveLauncher())) //return; if (entityVehicle.HasGun() && Input.GetMouseButton(0) && Time.time - gunShootDelay > lastGunShoot) { //DebugMsg("Left-click"); ShootProjectile(entityVehicle.gunLauncher, "vehicleGun", "Weapons/Ranged/AK47/ak47_fire_start", true); lastGunShoot = Time.time; } if (entityVehicle.HasExplosiveLauncher() && Input.GetMouseButton(1) && Time.time - missileShootDelay > lastMissileShoot) { //DebugMsg("Right-click"); ShootProjectile(entityVehicle.missileLauncher, "vehicleExplosiveLauncher", "Weapons/Ranged/M136/m136_fire", false); lastMissileShoot = Time.time; } }
// Displays the UI for the timer, calling TakeTarget when its done. public void TakeItemWithTimer(int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player) { LocalPlayerUI playerUI = (_player as EntityPlayerLocal).PlayerUI; playerUI.windowManager.Open("timer", true, false, true); XUiC_Timer xuiC_Timer = (XUiC_Timer)playerUI.xui.GetChildByType <XUiC_Timer>(); TimerEventData timerEventData = new TimerEventData(); timerEventData.Data = new object[] { _cIdx, _blockValue, _blockPos, _player }; timerEventData.Event += this.TakeTarget; float newTakeTime = this.fTakeDelay; // If the entity is holding a crow bar or hammer, then reduce the take time. if (_player.inventory.holdingItem.Name == "CrowBar" || _player.inventory.holdingItem.Name == "meleeToolClawHammer") { // Make sure the item can still be used if (_player.inventory.holdingItemItemValue.MaxUseTimes > 0) { // Bump the Use time by one. global::ItemValue itemValue = _player.inventory.holdingItemItemValue; // Calculate the degradation value. itemValue.UseTimes += (int)EffectManager.GetValue(PassiveEffects.DegradationPerUse, itemValue, 1f, _player, null, default(FastTags), true, true, true, true); _player.inventory.holdingItemData.itemValue = itemValue; // Automatically reduce the take delay by half if you have a crow bar or claw hammer. newTakeTime = (this.fTakeDelay / 2); float blockDamage = EffectManager.GetValue(PassiveEffects.BlockDamage, null, 1f, _player, null, default(FastTags), true, true, true, true); Debug.Log("Block Damage is: " + blockDamage); // Don't divde by 0, but take it as a full timer, since it's level 0. if (blockDamage == 0f) { newTakeTime = newTakeTime * 1f; } else { newTakeTime = newTakeTime * blockDamage; } } } xuiC_Timer.SetTimer(newTakeTime, timerEventData); }
private void Start() { if (isLocalPlayer) { localPlayerUI = LocalPlayerUI.Instance; healthUpdate += localPlayerUI.UpdateHealthBar; healthUpdate += localPlayerUI.UpdateDeathMenu; healthUpdate?.Invoke(currentHealth, maxHealth); } }
public override void Execute(MinEventParams _params) { EntityPlayerLocal entityPlayer = _params.Self as EntityPlayerLocal; if (_params.Self as EntityPlayerLocal != null && this.CreateItem != null && this.CreateItemCount > 0) { ItemStack itemStack = new ItemStack(ItemClass.GetItem(this.CreateItem, false), this.CreateItemCount); if (!LocalPlayerUI.GetUIForPlayer(entityPlayer).xui.PlayerInventory.AddItem(itemStack, true)) { entityPlayer.world.gameManager.ItemDropServer(itemStack, entityPlayer.GetPosition(), Vector3.zero, -1, 60f, false); } } }
/** * When the player activates this entityclass with an empty hand, try to pick it up. */ public override void Kill(DamageResponse _dmgResponse) { if (_dmgResponse.Source.getEntityId() == -1) { base.Kill(_dmgResponse); Log.Warning("Killer was not a player."); return; } EntityPlayerLocal entityPlayerLocal = GameManager.Instance.World.GetLocalPlayerFromID(_dmgResponse.Source.getEntityId()) as EntityPlayerLocal; if (!(entityPlayerLocal is EntityPlayerLocal)) { base.Kill(_dmgResponse); Log.Warning("Killer was an entity, but not a player."); return; } LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal); if (uiforPlayer.xui.isUsingItemActionEntryUse) { base.Kill(_dmgResponse); Log.Warning("XUI interfering."); return; } ItemStack pickup = new ItemStack(this.itemReturned, 1); if (!entityPlayerLocal.inventory.CanTakeItem(pickup) & !entityPlayerLocal.bag.CanTakeItem(pickup)) { base.Kill(_dmgResponse); Log.Warning("Canot take item - no room in inventory."); return; } Log.Out("Player is holding: " + entityPlayerLocal.inventory.holdingItem.GetItemName()); if (entityPlayerLocal.inventory.holdingItem.GetItemName() == "meleeHandPlayer") { Log.Out("Server, despawn the entity."); GameManager.Instance.World.RemoveEntity(this.entityId, EnumRemoveEntityReason.Killed); Log.Out("Player, add the item."); entityPlayerLocal.inventory.AddItem(pickup); return; } Log.Warning("Cannot activate."); base.Kill(_dmgResponse); return; }
// Displays the UI for the timer, calling TakeTarget when its done. public void TakeItemWithTimer(int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player) { LocalPlayerUI playerUI = (_player as EntityPlayerLocal).PlayerUI; playerUI.windowManager.Open("timer", true, false, true); XUiC_Timer xuiC_Timer = (XUiC_Timer)playerUI.xui.GetChildByType <XUiC_Timer>(); TimerEventData timerEventData = new TimerEventData(); timerEventData.Data = new object[] { _cIdx, _blockValue, _blockPos, _player }; timerEventData.Event += this.TakeTarget; float newTakeTime = this.fTakeDelay; // If the entity is holding a crow bar or hammer, then reduce the take time. if (_player.inventory.holdingItem.Name == "CrowBar" || _player.inventory.holdingItem.Name == "clawHammer") { // Make sure the item can still be used if (_player.inventory.holdingItemItemValue.MaxUseTimes > 0) { // Bump the Use time by one. global::ItemValue itemValue = _player.inventory.holdingItemItemValue; itemValue.UseTimes += global::AttributeBase.GetVal <global::AttributeDegradationRate>(itemValue, 1); _player.inventory.holdingItemData.itemValue = itemValue; // Automatically reduce the take delay by half if you have a crow bar or claw hammer. newTakeTime = (this.fTakeDelay / 2); Skill tmpSkill = (_player as EntityPlayerLocal).Skills.GetSkillByName("Breaking And Entering"); // Don't divde by 0, but take it as a full timer, since it's level 0. if (tmpSkill.Level == 0) { newTakeTime = newTakeTime / 1f; } else { newTakeTime = newTakeTime / tmpSkill.Level; } } } xuiC_Timer.SetTimer(newTakeTime, timerEventData); }
public static bool Prefix(ref Block __instance, int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player) { // Check if this feature is enabled. if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature)) { return(true); } if (_blockValue.ischild) { return(true); } TileEntitySecureDoor tileEntitySecureDoor = (TileEntitySecureDoor)_world.GetTileEntity(_cIdx, _blockPos); if (tileEntitySecureDoor == null) { return(true); } if (!tileEntitySecureDoor.IsLocked() || tileEntitySecureDoor.IsUserAllowed(GamePrefs.GetString(EnumGamePrefs.PlayerId))) { return(true); } if (tileEntitySecureDoor.IsLocked()) { // 1 == try to open locked door. if (_indexInBlockActivationCommands == 1) { // Check if the player has lock picks. LocalPlayerUI playerUI = (_player as EntityPlayerLocal).PlayerUI; XUiM_PlayerInventory playerInventory = playerUI.xui.PlayerInventory; ItemValue item = ItemClass.GetItem("resourceLockPick", false); if (playerInventory.GetItemCount(item) == 0) { playerUI.xui.CollectedItemList.AddItemStack(new ItemStack(item, 0), true); GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttLockpickMissing")); return(false); } tileEntitySecureDoor.SetLocked(true); XUiC_PickLocking.Open(playerUI, tileEntitySecureDoor, _blockValue, _blockPos); return(false); } } return(true); }
public override bool OnEntityActivated(int _indexInBlockActivationCommands, Vector3i _tePos, EntityAlive _entityFocusing) { // set the IsBusy flag, so it won't wander away when you are talking to it. this.emodel.avatarController.SetBool("IsBusy", true); // Look at the entity that is talking to you. this.SetLookPosition(_entityFocusing.getHeadPosition()); // Add a reference for the dialog otherEntitySDX to the UI, since the respondent doesn't always carry forward LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_entityFocusing as EntityPlayerLocal); uiforPlayer.xui.Dialog.otherEntitySDX = this; base.OnEntityActivated(_indexInBlockActivationCommands, _tePos, _entityFocusing); return(true); }
public override void PerformAction(EntityPlayer player) { if (string.IsNullOrEmpty(Value)) { Value = "1"; } int flValue = 1; int.TryParse(Value, out flValue); LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal); XUiM_PlayerInventory playerInventory = uiforPlayer.xui.PlayerInventory; ItemStack itemStack = new ItemStack(ItemClass.GetItem(ID, false), flValue); playerInventory.RemoveItem(itemStack); }
// Adaptation of GameUtils.WZ(ItemActionAttackData itemActionAttackData, ItemValue itemValue, int num, float num2, string text, bool flag = true). // .WZ is obfuscated if will be named different on your machine. public void AddHarvestItemToInventory(ItemValue itemValue, int num, float num2, string text) { //string msg = "Harvest: " + itemValue.ItemClass.GetItemName(); if (itemValue == null || itemValue.ItemClass == null || (itemValue.ItemClass.GetItemName() == "yuccaFibers" && !harvestBlocks.Contains("grass"))) { //DebugMsg(msg += " (NOT HARVESTED)"); return; } //DebugMsg(msg); if (UnityEngine.Random.value <= num2 && num > 0) { ItemStack itemStack = new ItemStack(itemValue, num); bool addedToVehicleInv = false; if (harvestToVehicleInventory && entityVehicle.HasStorage()) { //addedToVehicleInv = entityVehicle.xuiC_VehicleContainer.AddItem(itemStack); //XUiC_VehicleContainer vehicleContainer = entityVehicle.GetVehicleContainer(); //XUiC_VehicleContainer vehicleContainer = EntityCustomVehicle.GetVehicleContainer(entityVehicle, entityVehicle.player, entityVehicle.vehicleXuiName); //if (vehicleContainer != null) if (entityVehicle.xuiC_VehicleContainer != null) { //addedToVehicleInv = entityVehicle.inventory.AddItem(itemStack); //addedToVehicleInv = vehicleContainer.AddItem(itemStack); addedToVehicleInv = entityVehicle.xuiC_VehicleContainer.AddItem(itemStack); } } if (!addedToVehicleInv) { LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityVehicle.player); //if (!entityVehicle.playerInventory.AddItem(itemStack, true)) //if (!entityVehicle.player.inventory.AddItem(itemStack)) if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack, true)) { GameManager.Instance.ItemDropServer(new ItemStack(itemValue, num), entityVehicle.player.GetPosition(), Vector3.zero, entityVehicle.player.GetInstanceID(), 60f, false); } } // The harvesting XP is only added when destroyed blocks are also harvested and when HarvestXPFactor xml property > 0. if (harvestXPFactor != 0) { entityVehicle.player.AddExp(Mathf.RoundToInt(itemStack.itemValue.ItemClass.MadeOfMaterial.Experience * (float)num * harvestXPFactor)); } } }
private void EventData_Event(object obj) { World world = GameManager.Instance.World; var eventData = obj as TimerEventData; object[] objArray = (object[])eventData.Data; int _clrIdx = (int)objArray[0]; BlockValue blockValue = (BlockValue)objArray[1]; Vector3i vector3i = (Vector3i)objArray[2]; BlockValue block = world.GetBlock(vector3i); EntityPlayerLocal entityPlayerLocal = objArray[3] as EntityPlayerLocal; if (block.damage > 0) { GameManager.ShowTooltipWithAlert(entityPlayerLocal, Localization.Get("ttRepairBeforePickup", string.Empty), "ui_denied"); } else if (block.type != blockValue.type) { GameManager.ShowTooltipWithAlert(entityPlayerLocal, Localization.Get("ttBlockMissingPickup", string.Empty), "ui_denied"); } else { TileEntitySecureLootContainer tileEntity = world.GetTileEntity(_clrIdx, vector3i) as TileEntitySecureLootContainer; if (tileEntity.IsUserAccessing()) { GameManager.ShowTooltipWithAlert(entityPlayerLocal, Localization.Get("ttCantPickupInUse", string.Empty), "ui_denied"); } else { LocalPlayerUI uiForPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal); ItemStack itemStack = new ItemStack(block.ToItemValue(), 1); if (!uiForPlayer.xui.PlayerInventory.AddItem(itemStack, true)) { uiForPlayer.xui.PlayerInventory.DropItem(itemStack); } world.SetBlockRPC(_clrIdx, vector3i, BlockValue.Air); } } }
public override void PerformAction(EntityPlayer player) { LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal); // The respondent is an EntityNPC, and we don't have that. Check for the patch scripted otherEntitySDX. Entity respondent = uiforPlayer.xui.Dialog.Respondent; if (respondent == null) { respondent = uiforPlayer.xui.Dialog.otherEntitySDX; } if (respondent != null) { EntityAliveSDX myEntity = player.world.GetEntity(respondent.entityId) as EntityAliveSDX; if (myEntity != null) { myEntity.ExecuteCMD(base.ID, player); } } }
/** * Called when a block is destroyed by an entity. It cam be useful for separating things out if needed depending on what * entity destroyed it. */ public override bool OnBlockDestroyedBy(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, int _entityId, bool _bUseHarvestTool) { TileEntityBlockTransformer tileEntityBlockTransformer = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntityBlockTransformer; if (tileEntityBlockTransformer != null) { tileEntityBlockTransformer.OnDestroy(); } LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(GameManager.Instance.World.GetEntity(_entityId) as EntityPlayerLocal); if (null != uiforPlayer && uiforPlayer.windowManager.IsWindowOpen("looting") && ((XUiC_LootWindow)uiforPlayer.xui.GetWindow("windowLooting").Controller).GetLootBlockPos() == _blockPos) { uiforPlayer.windowManager.Close("looting"); } if (tileEntityBlockTransformer != null) { _world.GetGameManager().DropContentOfLootContainerServer(_blockValue, _blockPos, tileEntityBlockTransformer.entityId); } return(true); }
public static void lootContainerOpened(TileEntityLootContainer _te, LocalPlayerUI _playerUI, int _entityIdThatOpenedIt) { if (_playerUI != null) { bool flag = true; string lootContainerName = string.Empty; if (_te.entityId != -1) { Entity entity = GameManager.Instance.World.GetEntity(_te.entityId); if (entity != null) { lootContainerName = Localization.Get(EntityClass.list[entity.entityClass].entityClassName, ""); if (entity is EntityVehicle) { flag = false; } } } else { BlockValue block = GameManager.Instance.World.GetBlock(_te.ToWorldPos()); lootContainerName = Localization.Get(Block.list[block.type].GetBlockName(), ""); } if (flag) { ((XUiC_LootWindowGroup)((XUiWindowGroup)_playerUI.windowManager.GetWindow("looting")).Controller).SetTileEntityChest(lootContainerName, _te); _playerUI.windowManager.Open("looting", true, false, true); } LootContainer lootContainer = LootContainer.lootList[_te.lootListIndex]; if (lootContainer != null && _playerUI.entityPlayer != null) { lootContainer.ExecuteBuffActions(_te.entityId, _playerUI.entityPlayer); } } if (SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer) { GameManager.Instance.lootManager.LootContainerOpened(_te, _entityIdThatOpenedIt); _te.bTouched = true; _te.SetModified(); } }
public static bool Hire(int EntityID, EntityPlayerLocal _player) { DisplayLog("Hire()"); bool result = false; EntityAliveSDX myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAliveSDX; if (myEntity == null) { return(result); } DisplayLog("Hire(): I have an entity"); LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal); if (uiforPlayer) { DisplayLog("Hire(): I have a player."); DisplayLog(" The Player wants to hire me for " + GetHireCost(EntityID) + " " + GetHireCurrency(EntityID)); if (uiforPlayer.xui.PlayerInventory.GetItemCount(GetHireCurrency(EntityID)) >= GetHireCost(EntityID)) { DisplayLog(" The Player has enough currency: " + uiforPlayer.xui.PlayerInventory.GetItemCount(GetHireCurrency(EntityID))); // Create the stack of currency ItemStack stack = new ItemStack(GetHireCurrency(EntityID), GetHireCost(EntityID)); DisplayLog(" Removing Item: " + stack.ToString()); uiforPlayer.xui.PlayerInventory.RemoveItems(new ItemStack[] { stack }, 1); // Add the stack of currency to the NPC, and set its orders. //myEntity.bag.AddItem(stack); SetLeaderAndOwner(EntityID, _player.entityId); return(true); } else { GameManager.ShowTooltipWithAlert(_player, "You cannot afford me. I want " + GetHireCost(EntityID) + " " + GetHireCurrency(EntityID), "ui_denied"); } } return(false); }
public override void OnOpen() { LocalPlayerUI uiforPlayer = base.xui.playerUI; // The respondent is an EntityNPC, and we don't have that. Check for the patch scripted otherEntitySDX. Entity respondent = uiforPlayer.xui.Dialog.Respondent; if (respondent == null) { respondent = uiforPlayer.xui.Dialog.otherEntitySDX; } if (respondent != null) { EntityAliveSDX myEntity = uiforPlayer.entityPlayer.world.GetEntity(respondent.entityId) as EntityAliveSDX; if (myEntity != null) { this.hireInformationLabel.Text = "Hire " + myEntity.EntityName + " for " + myEntity.GetHireCost() + " " + myEntity.GetHireCurrency().ItemClass.GetLocalizedItemName() + "?"; } } base.OnOpen(); }
private void BtnConfirmHireInformation_OnPressed(XUiController _sender, OnPressEventArgs _onPressEventArgs) { LocalPlayerUI uiforPlayer = base.xui.playerUI; // The respondent is an EntityNPC, and we don't have that. Check for the patch scripted otherEntitySDX. Entity respondent = uiforPlayer.xui.Dialog.Respondent; if (respondent == null) { respondent = uiforPlayer.xui.Dialog.otherEntitySDX; } if (respondent != null) { EntityAliveSDX myEntity = uiforPlayer.entityPlayer.world.GetEntity(respondent.entityId) as EntityAliveSDX; if (myEntity != null) { myEntity.SetOwner(uiforPlayer.entityPlayer as EntityPlayerLocal); } } base.xui.playerUI.windowManager.Close(this.windowGroup.ID); }