Upload from upload_mods.ps1
This commit is contained in:
166
Scripts/XUIC/NPCs/XUiC_PickUpNPCPopupRebirth.cs
Normal file
166
Scripts/XUIC/NPCs/XUiC_PickUpNPCPopupRebirth.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
using Audio;
|
||||
|
||||
internal class XUiC_PickUpNPCPopupRebirth : XUiController
|
||||
{
|
||||
public XUiV_Label Label;
|
||||
public XUiV_Panel Panel;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Panel = (XUiV_Panel)GetChildById("Popup").ViewComponent;
|
||||
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnCancel")).OnPressed += BtnCancel_OnPressed;
|
||||
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnConfirm")).OnPressed += BtnConfirm_OnPressed;
|
||||
Label = (XUiV_Label)Panel.Controller.GetChildById("Label").ViewComponent;
|
||||
}
|
||||
|
||||
public override void OnOpen()
|
||||
{
|
||||
//Log.Out("XUiC_PickUpNPCPopupRebirth-OnOpen START");
|
||||
EntityPlayer player = xui.playerUI.entityPlayer;
|
||||
|
||||
var entityID = 0;
|
||||
if (player.Buffs.HasCustomVar("CurrentNPC"))
|
||||
{
|
||||
//Log.Out("XUiC_PickUpNPCPopupRebirth-OnOpen 1");
|
||||
entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
|
||||
}
|
||||
|
||||
if (entityID == 0)
|
||||
{
|
||||
//Log.Out("XUiC_PickUpNPCPopupRebirth-OnOpen 2");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("XUiC_PickUpNPCPopupRebirth-OnOpen entityID: " + entityID);
|
||||
|
||||
EntityNPCRebirth myEntity = player.world.GetEntity(entityID) as EntityNPCRebirth;
|
||||
if (myEntity != null)
|
||||
{
|
||||
//Log.Out("XUiC_PickUpNPCPopupRebirth-OnOpen 3");
|
||||
Label.Text = string.Format(Localization.Get("ttPickUpCost"), myEntity.EntityName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("XUiC_PickUpNPCPopupRebirth-OnOpen Entity == null");
|
||||
}
|
||||
|
||||
base.OnOpen();
|
||||
}
|
||||
|
||||
private void BtnConfirm_OnPressed(XUiController _sender, int _mouseButton)
|
||||
{
|
||||
EntityPlayer player = xui.playerUI.entityPlayer;
|
||||
|
||||
var entityID = 0;
|
||||
if (player.Buffs.HasCustomVar("CurrentNPC"))
|
||||
entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
|
||||
|
||||
if (entityID == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntityNPCRebirth myEntity = player.world.GetEntity(entityID) as EntityNPCRebirth;
|
||||
|
||||
if (myEntity != null)
|
||||
{
|
||||
ItemValue item = ItemClass.GetItem("casinoCoin", false);
|
||||
ItemClass itemClass = item.ItemClass;
|
||||
if (itemClass != null)
|
||||
{
|
||||
var uiforPlayer = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal);
|
||||
|
||||
int itemCount = player.bag.GetItemCount(item, -1, -1, false);
|
||||
int itemCount2 = player.inventory.GetItemCount(item, false, -1, -1);
|
||||
|
||||
//Log.Out("XUiC_PickUpNPCPopupRebirth-BtnConfirm_OnPressed itemCount + itemCount2: " + (itemCount + itemCount2));
|
||||
|
||||
if (itemCount + itemCount2 >= 250)
|
||||
{
|
||||
int Remaining = 250;
|
||||
bool needMore = false;
|
||||
|
||||
int Withdraw = Remaining - itemCount2;
|
||||
|
||||
if (Withdraw <= 0)
|
||||
{
|
||||
player.inventory.DecItem(item, 250, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.inventory.DecItem(item, itemCount2, false);
|
||||
needMore = true;
|
||||
Remaining = Remaining - itemCount2;
|
||||
player.bag.DecItem(item, Remaining, false);
|
||||
}
|
||||
|
||||
var playerInventory = uiforPlayer.xui.PlayerInventory;
|
||||
if (playerInventory == null) return;
|
||||
|
||||
string ID = myEntity.EntityClass.Properties.Values["SpawnBlockName"];
|
||||
|
||||
var itemAdd = ItemClass.GetItem(ID);
|
||||
if (itemAdd == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var itemStack = new ItemStack(itemAdd, 1);
|
||||
if (!playerInventory.AddItem(itemStack, true))
|
||||
player.world.gameManager.ItemDropServer(itemStack, player.GetPosition(), Vector3.zero);
|
||||
|
||||
if (myEntity.Buffs.HasBuff("FuriousRamsayNPCSilencer"))
|
||||
{
|
||||
ID = "modGunSoundSuppressorSilencer";
|
||||
|
||||
itemAdd = ItemClass.GetItem(ID);
|
||||
itemStack = new ItemStack(itemAdd, 1);
|
||||
if (!playerInventory.AddItem(itemStack, true))
|
||||
player.world.gameManager.ItemDropServer(itemStack, player.GetPosition(), Vector3.zero);
|
||||
}
|
||||
|
||||
ItemStack[] array = myEntity.lootContainer.GetItems();
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (!array[i].IsEmpty())
|
||||
{
|
||||
if (!playerInventory.AddItem(array[i], true))
|
||||
{
|
||||
player.world.gameManager.ItemDropServer(array[i], player.GetPosition(), Vector3.zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
myEntity.bIsChunkObserver = false;
|
||||
|
||||
//Log.Out("XUiC_PickUpNPCPopupRebirth-BtnConfirm_OnPressed REMOVED HIRE, hire: " + myEntity.entityId);
|
||||
RebirthManager.RemoveHire(myEntity.entityId);
|
||||
|
||||
GameManager.Instance.World.RemoveEntity(myEntity.entityId, EnumRemoveEntityReason.Despawned);
|
||||
}
|
||||
else
|
||||
{
|
||||
Manager.PlayInsidePlayerHead("misc/missingitemtorepair");
|
||||
GameManager.ShowTooltip(uiforPlayer.entityPlayer, Localization.Get("ttMissingCash"));
|
||||
ItemStack @is = new ItemStack(new ItemValue(itemClass.Id, false), 0);
|
||||
uiforPlayer.entityPlayer.AddUIHarvestingItem(@is, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xui.playerUI.windowManager.Close(windowGroup.ID);
|
||||
}
|
||||
|
||||
private void BtnCancel_OnPressed(XUiController _sender, int _mouseButton)
|
||||
{
|
||||
Panel.IsVisible = false;
|
||||
xui.playerUI.windowManager.Close(windowGroup.ID);
|
||||
}
|
||||
|
||||
public override void OnClose()
|
||||
{
|
||||
if (xui.playerUI.windowManager.HasWindow("dialog") && xui.playerUI.windowManager.IsWindowOpen("dialog"))
|
||||
xui.playerUI.windowManager.Close("dialog");
|
||||
base.OnClose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user