204 lines
7.7 KiB
C#
204 lines
7.7 KiB
C#
internal class XUiC_GoMineRebirth : XUiController
|
|
{
|
|
public XUiV_Label Label;
|
|
public XUiV_Label Resource;
|
|
public XUiV_Label ResourceMultiplier;
|
|
public XUiV_Label GatherType;
|
|
public XUiV_Panel Panel;
|
|
public float flSubLevels = 0.1f;
|
|
public bool bDifferentBiome = false;
|
|
public string strDuration = "10";
|
|
|
|
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;
|
|
Resource = (XUiV_Label)Panel.Controller.GetChildById("Resource").ViewComponent;
|
|
ResourceMultiplier = (XUiV_Label)Panel.Controller.GetChildById("ResourceMultiplier").ViewComponent;
|
|
GatherType = (XUiV_Label)Panel.Controller.GetChildById("GatherType").ViewComponent;
|
|
}
|
|
|
|
public override void OnOpen()
|
|
{
|
|
EntityPlayer player = xui.playerUI.entityPlayer;
|
|
|
|
var entityID = 0;
|
|
if (player.Buffs.HasCustomVar("CurrentNPC"))
|
|
entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
|
|
|
|
if (entityID == 0)
|
|
return;
|
|
|
|
var myEntity = player.world.GetEntity(entityID) as EntityNPCRebirth;
|
|
|
|
string strProperty = RebirthUtilities.GetEntityPropertyValue(entityID, "MiningCost");
|
|
float numCost = 0f;
|
|
float numMultiplier = 1f;
|
|
|
|
if (strProperty != "")
|
|
{
|
|
numCost = int.Parse(strProperty);
|
|
}
|
|
|
|
strProperty = ResourceMultiplier.Text;
|
|
if (strProperty != "")
|
|
{
|
|
numMultiplier = float.Parse(strProperty);
|
|
}
|
|
|
|
numCost = numCost * numMultiplier;
|
|
|
|
numCost = (int)(numCost * RebirthUtilities.getDiscount(player));
|
|
|
|
BiomeDefinition biomeStandingOn = player.biomeStandingOn;
|
|
string text = "BIOME";
|
|
|
|
text = RebirthUtilities.GetBiomeName(player);
|
|
|
|
if (text != "desert" && (Resource.Text == "Sand" || Resource.Text == "Shale"))
|
|
{
|
|
bDifferentBiome = true;
|
|
strDuration = "20";
|
|
}
|
|
|
|
if (myEntity != null)
|
|
{
|
|
Label.Text = "";
|
|
if (text != "desert" && (Resource.Text == "Sand" || Resource.Text == "Shale"))
|
|
{
|
|
Label.Text = string.Format(Localization.Get("ttMiningPremium"), myEntity.EntityName, Localization.Get("biome_desert"));
|
|
numCost = numCost * 1.25f;
|
|
}
|
|
|
|
if (GatherType.Text.ToLower() == "mining")
|
|
{
|
|
Label.Text = Label.Text + Localization.Get("ttMiningBetter");
|
|
|
|
Label.Text = string.Format(Localization.Get("ttSendToMine"), myEntity.EntityName, Resource.Text, (int)numCost) +
|
|
string.Format(Localization.Get("ttMiningCostDuration"), EntityUtilities.GetHireCurrency(entityID).ItemClass.GetLocalizedItemName(), strDuration) +
|
|
Label.Text;
|
|
}
|
|
else
|
|
{
|
|
Label.Text = string.Format(Localization.Get("ttSendToGather"), myEntity.EntityName, Resource.Text, (int)numCost) +
|
|
string.Format(Localization.Get("ttMiningCostDuration"), EntityUtilities.GetHireCurrency(entityID).ItemClass.GetLocalizedItemName(), strDuration) +
|
|
Label.Text;
|
|
}
|
|
}
|
|
|
|
base.OnOpen();
|
|
}
|
|
|
|
private void BtnConfirm_OnPressed(XUiController _sender, int _mouseButton)
|
|
{
|
|
//Log.Out("XUiC_AddSecondClassPopupRebirth-BtnConfirm_OnPressed START");
|
|
EntityPlayer player = xui.playerUI.entityPlayer;
|
|
|
|
var entityID = 0;
|
|
if (player.Buffs.HasCustomVar("CurrentNPC"))
|
|
entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
|
|
|
|
if (entityID == 0)
|
|
{
|
|
//Log.Out("XUiC_AddSecondClassPopupRebirth-BtnConfirm_OnPressed 1");
|
|
return;
|
|
}
|
|
|
|
var myEntity = player.world.GetEntity(entityID) as EntityNPCRebirth;
|
|
if (myEntity == null)
|
|
{
|
|
//Log.Out("XUiC_AddSecondClassPopupRebirth-BtnConfirm_OnPressed 2");
|
|
return;
|
|
}
|
|
|
|
string strProperty = RebirthUtilities.GetEntityPropertyValue(entityID, "MiningCost");
|
|
float numCost = 0f;
|
|
float numMultiplier = 1f;
|
|
|
|
if (strProperty != "")
|
|
{
|
|
numCost = int.Parse(strProperty);
|
|
}
|
|
|
|
strProperty = ResourceMultiplier.Text;
|
|
if (strProperty != "")
|
|
{
|
|
numMultiplier = float.Parse(strProperty);
|
|
}
|
|
|
|
numCost = numCost * numMultiplier;
|
|
|
|
BiomeDefinition biomeStandingOn = player.biomeStandingOn;
|
|
string text = "BIOME";
|
|
if (biomeStandingOn != null)
|
|
{
|
|
text = biomeStandingOn.m_sBiomeName;
|
|
}
|
|
|
|
if (text != "desert" && (Resource.Text == "Sand" || Resource.Text == "Shale"))
|
|
{
|
|
numCost = numCost * 1.25f;
|
|
}
|
|
|
|
numCost = (int)(numCost * RebirthUtilities.getDiscount(player));
|
|
|
|
var uiforPlayer = LocalPlayerUI.GetUIForPlayer((EntityPlayerLocal)player);
|
|
if (uiforPlayer)
|
|
{
|
|
if (uiforPlayer.xui.PlayerInventory.GetItemCount(EntityUtilities.GetHireCurrency(myEntity.entityId)) >= (int)numCost)
|
|
{
|
|
// Create the stack of currency
|
|
var stack = new ItemStack(EntityUtilities.GetHireCurrency(myEntity.entityId), (int)numCost);
|
|
//DisplayLog(" Removing Item: " + stack);
|
|
uiforPlayer.xui.PlayerInventory.RemoveItems(new[] { stack });
|
|
|
|
if (bDifferentBiome)
|
|
{
|
|
myEntity.Buffs.AddBuff("FuriousRamsayGoMining" + Resource.Text.Replace(" ", "") + "Premium");
|
|
}
|
|
else
|
|
{
|
|
myEntity.Buffs.AddBuff("FuriousRamsayGoMining" + Resource.Text.Replace(" ", ""));
|
|
}
|
|
|
|
int numMiningLevelBefore = (int)myEntity.Buffs.GetCustomVar("$FR_NPC_GoneMiningLevel");
|
|
myEntity.Buffs.SetCustomVar("$FR_NPC_GoneMiningLevel", myEntity.Buffs.GetCustomVar("$FR_NPC_GoneMiningLevel") + flSubLevels);
|
|
int numMiningLevelAfter = (int)myEntity.Buffs.GetCustomVar("$FR_NPC_GoneMiningLevel");
|
|
|
|
float flNPCMiningLevel = myEntity.Buffs.GetCustomVar("$FR_NPC_MiningLevel");
|
|
|
|
if ((numMiningLevelAfter > numMiningLevelBefore) && flNPCMiningLevel < 10)
|
|
{
|
|
myEntity.Buffs.SetCustomVar("$FR_NPC_MiningLevel", flNPCMiningLevel + 1f);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Audio.Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip((EntityPlayerLocal)player, string.Format(Localization.Get("ttCannotAffordMining"), (int)numCost));
|
|
ItemValue item = ItemClass.GetItem("casinoCoin", false);
|
|
ItemClass itemClass = item.ItemClass;
|
|
ItemStack @is = new ItemStack(new ItemValue(itemClass.Id, false), 0);
|
|
player.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();
|
|
}
|
|
} |