209 lines
8.9 KiB
C#
209 lines
8.9 KiB
C#
using Audio;
|
|
|
|
internal class XUiC_HireNPCPopupRebirth : XUiController
|
|
{
|
|
public XUiV_Label hireInformationLabel;
|
|
public XUiV_Panel hireInformationPanel;
|
|
public EntityNPCRebirth myEntity;
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
hireInformationPanel = (XUiV_Panel)GetChildById("HireInformationPopup").ViewComponent;
|
|
((XUiC_SimpleButton)hireInformationPanel.Controller.GetChildById("btnCancel")).OnPressed += BtnCancelHireInformation_OnPressed;
|
|
((XUiC_SimpleButton)hireInformationPanel.Controller.GetChildById("btnConfirm")).OnPressed += BtnConfirmHireInformation_OnPressed;
|
|
hireInformationLabel = (XUiV_Label)hireInformationPanel.Controller.GetChildById("HireInformationLabel").ViewComponent;
|
|
}
|
|
|
|
public override void OnOpen()
|
|
{
|
|
//Log.Out("XUiC_HireNPCPopupRebirth-OnOpen START");
|
|
EntityPlayer player = xui.playerUI.entityPlayer;
|
|
|
|
int entityID = RebirthVariables.talkingToNPC; // (int)player.Buffs.GetCustomVar("CurrentNPC");
|
|
|
|
if (entityID == 0)
|
|
return;
|
|
|
|
//Log.Out("XUiC_HireNPCPopupRebirth-OnOpen entityID: " + entityID);
|
|
|
|
myEntity = player.world.GetEntity(entityID) as EntityNPCRebirth;
|
|
|
|
if (myEntity == null)
|
|
{
|
|
//Log.Out("XUiC_HireNPCPopupRebirth-OnOpen ENTITY == null");
|
|
return;
|
|
}
|
|
|
|
myEntity.Buffs.AddBuff("buffTalkingTo");
|
|
|
|
int numHirecost = EntityUtilities.GetHireCost(entityID);
|
|
int flNPCLevel = (int)myEntity.Buffs.GetCustomVar("$FR_NPC_Level");
|
|
numHirecost = numHirecost + (500 * flNPCLevel);
|
|
|
|
numHirecost = (int)(numHirecost * RebirthUtilities.getDiscount(player));
|
|
//Log.Out("numHirecost: " + numHirecost);
|
|
//Log.Out("flNPCLevel: " + flNPCLevel);
|
|
|
|
if (myEntity != null)
|
|
{
|
|
int minClass = 1;
|
|
|
|
if (myEntity.EntityClass.Properties.Values.ContainsKey("PlayerLevelRestriction"))
|
|
{
|
|
minClass = int.Parse(myEntity.EntityClass.Properties.Values["PlayerLevelRestriction"]);
|
|
//Log.Out("XUiC_HireNPCPopupRebirth-OnOpen minClass: " + minClass);
|
|
}
|
|
|
|
string restrictiveHire = RebirthVariables.customRestrictHires;
|
|
|
|
//Log.Out("XUiC_HireNPCPopupRebirth-OnOpen restrictiveHire: " + restrictiveHire);
|
|
|
|
bool canHire = true;
|
|
|
|
if (restrictiveHire == "default" || restrictiveHire == "playerLevel")
|
|
{
|
|
//Log.Out("XUiC_HireNPCPopupRebirth-OnOpen 1");
|
|
if (player.Progression.Level < minClass)
|
|
{
|
|
//Log.Out("XUiC_HireNPCPopupRebirth-OnOpen 2");
|
|
canHire = false;
|
|
}
|
|
}
|
|
|
|
//Log.Out("XUiC_HireNPCPopupRebirth-OnOpen canHire: " + canHire);
|
|
|
|
if (canHire)
|
|
{
|
|
hireInformationLabel.Text = string.Format(Localization.Get("ttHireCost"), myEntity.EntityName, numHirecost) +
|
|
EntityUtilities.GetHireCurrency(entityID).ItemClass.GetLocalizedItemName() + "?";
|
|
((XUiC_SimpleButton)hireInformationPanel.Controller.GetChildById("btnConfirm")).ViewComponent.Position = new Vector2i(400, 0);
|
|
}
|
|
else
|
|
{
|
|
hireInformationLabel.Text = string.Format(Localization.Get("ttMinHireLevel"), minClass, myEntity.EntityName);
|
|
((XUiC_SimpleButton)hireInformationPanel.Controller.GetChildById("btnConfirm")).ViewComponent.Position = new Vector2i(-10000, -10000);
|
|
}
|
|
}
|
|
|
|
base.OnOpen();
|
|
}
|
|
|
|
private void BtnConfirmHireInformation_OnPressed(XUiController _sender, int _mouseButton)
|
|
{
|
|
EntityPlayer player = xui.playerUI.entityPlayer;
|
|
|
|
if (myEntity != null)
|
|
{
|
|
var uiforPlayer = LocalPlayerUI.GetUIForPlayer((EntityPlayerLocal)player);
|
|
if (uiforPlayer)
|
|
{
|
|
|
|
int numHirecost = EntityUtilities.GetHireCost(myEntity.entityId);
|
|
int flNPCLevel = (int)myEntity.Buffs.GetCustomVar("$FR_NPC_Level");
|
|
|
|
numHirecost = numHirecost + (500 * flNPCLevel);
|
|
|
|
numHirecost = (int)(numHirecost * RebirthUtilities.getDiscount(player));
|
|
|
|
if (uiforPlayer.xui.PlayerInventory.GetItemCount(EntityUtilities.GetHireCurrency(myEntity.entityId)) >= numHirecost)
|
|
{
|
|
// Create the stack of currency
|
|
var stack = new ItemStack(EntityUtilities.GetHireCurrency(myEntity.entityId), numHirecost);
|
|
//DisplayLog(" Removing Item: " + stack);
|
|
uiforPlayer.xui.PlayerInventory.RemoveItems(new[] { stack });
|
|
|
|
EntityUtilities.SetLeaderAndOwner(myEntity.entityId, player.entityId);
|
|
myEntity.Buffs.AddBuff("buffOrderFollow");
|
|
myEntity.Buffs.AddBuff("FuriousRamsayMaxHealth");
|
|
|
|
myEntity.belongsPlayerId = player.entityId;
|
|
myEntity.LeaderUtils.Owner = player;
|
|
RebirthUtilities.SetLeaderAndOwner(myEntity.entityId, player.entityId);
|
|
myEntity.Buffs.AddBuff("buffNPCModFullControlMode");
|
|
|
|
myEntity.AddNavObject("FuriousRamsayHiredNav", "", "");
|
|
|
|
//Log.Out("XUiC_HireNPCPopupRebirth-BtnConfirmHireInformation_OnPressed SET TO STAY");
|
|
myEntity.Buffs.SetCustomVar("CurrentOrder", (int)EntityUtilities.Orders.Follow);
|
|
|
|
float flMode = player.Buffs.GetCustomVar("varNPCModMode");
|
|
float flHalt = player.Buffs.GetCustomVar("varNPCModStopAttacking");
|
|
|
|
if (flMode == 0)
|
|
{
|
|
myEntity.Buffs.AddBuff("buffNPCModFullControlMode");
|
|
}
|
|
else
|
|
{
|
|
myEntity.Buffs.RemoveBuff("buffNPCModFullControlMode");
|
|
}
|
|
|
|
if (flHalt == 1)
|
|
{
|
|
myEntity.Buffs.AddBuff("buffNPCModStopAttacking");
|
|
}
|
|
else
|
|
{
|
|
myEntity.Buffs.RemoveBuff("buffNPCModStopAttacking");
|
|
}
|
|
|
|
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer && !SingletonMonoBehaviour<ConnectionManager>.Instance.IsSinglePlayer)
|
|
{
|
|
SingletonMonoBehaviour<ConnectionManager>.Instance.SendPackage(NetPackageManager.GetPackage<NetPackageAddCompanion>().Setup(myEntity.entityId, myEntity.belongsPlayerId), false, myEntity.belongsPlayerId, -1, -1, null, 192);
|
|
}
|
|
else
|
|
{
|
|
myEntity.LeaderUtils.AddCompanion();
|
|
}
|
|
|
|
RebirthManager.AddHire(player.entityId,
|
|
myEntity.entityId,
|
|
myEntity.EntityName,
|
|
myEntity.EntityClass.entityClassName,
|
|
myEntity.position,
|
|
myEntity.rotation,
|
|
new Vector3(0, 0, 0),
|
|
new Vector3(0, 0, 0),
|
|
0,
|
|
0,
|
|
0,
|
|
true
|
|
);
|
|
|
|
// If we're going to hire them, they need to wake up.
|
|
if (myEntity.IsSleeping)
|
|
myEntity.ConditionalTriggerSleeperWakeUp();
|
|
}
|
|
else
|
|
{
|
|
Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip((EntityPlayerLocal)player, string.Format(Localization.Get("ttMinHireCost"), numHirecost));
|
|
ItemValue item = ItemClass.GetItem("casinoCoin", false);
|
|
ItemClass itemClass = item.ItemClass;
|
|
ItemStack @is = new ItemStack(new ItemValue(itemClass.Id, false), 0);
|
|
player.AddUIHarvestingItem(@is, true);
|
|
}
|
|
}
|
|
|
|
myEntity.Buffs.RemoveBuff("buffTalkingTo");
|
|
}
|
|
|
|
xui.playerUI.windowManager.Close(windowGroup.ID);
|
|
}
|
|
|
|
private void BtnCancelHireInformation_OnPressed(XUiController _sender, int _mouseButton)
|
|
{
|
|
myEntity.Buffs.RemoveBuff("buffTalkingTo");
|
|
|
|
hireInformationPanel.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();
|
|
}
|
|
} |