internal class XUiC_TradeAmmoRebirth : XUiController { private static float uiCheck = 0f; public float uiTick = 0.5f; public float barterPerc = 0f; public XUiV_Label LabelTotal; private XUiC_ComboBoxList cbxTargetAmmoType; public XUiC_ComboBoxInt combo9mm; public XUiC_ComboBoxInt combo762; public XUiC_ComboBoxInt combo44; public XUiC_ComboBoxInt comboShell; public XUiV_Label Resource; public XUiV_Label ResourceMultiplier; public XUiV_Label GatherType; public XUiV_Label LabelDescription; public XUiV_Panel Panel; public XUiV_Sprite spriteAmmoImage; public override void Init() { //Log.Out("XUiC_TradeAmmoRebirth-Init START"); 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; spriteAmmoImage = (XUiV_Sprite)GetChildById("AmmoImage").ViewComponent; LabelTotal = (XUiV_Label)Panel.Controller.GetChildById("lblTotal").ViewComponent; LabelDescription = (XUiV_Label)Panel.Controller.GetChildById("lblDescription").ViewComponent; LabelTotal.Enabled = false; this.cbxTargetAmmoType = (base.GetChildById("cbxAmmoType") as XUiC_ComboBoxList); if (this.cbxTargetAmmoType != null) { this.cbxTargetAmmoType.Elements.Add("9mm"); this.cbxTargetAmmoType.Elements.Add(".44"); this.cbxTargetAmmoType.Elements.Add("762"); this.cbxTargetAmmoType.Elements.Add("Shell"); this.cbxTargetAmmoType.OnValueChanged += this.cbxTargetAmmoType_OnValueChanged; } combo9mm = GetChildById("cbx9mm").GetChildByType(); combo762 = GetChildById("cbx762").GetChildByType(); combo44 = GetChildById("cbx44").GetChildByType(); comboShell = GetChildById("cbxShell").GetChildByType(); this.combo9mm.OnValueChanged += new XUiC_ComboBox.XUiEvent_ValueChanged(this.combo9mm_OnValueChanged); this.combo762.OnValueChanged += new XUiC_ComboBox.XUiEvent_ValueChanged(this.combo762_OnValueChanged); this.combo44.OnValueChanged += new XUiC_ComboBox.XUiEvent_ValueChanged(this.combo44_OnValueChanged); this.comboShell.OnValueChanged += new XUiC_ComboBox.XUiEvent_ValueChanged(this.comboShell_OnValueChanged); } private void combo9mm_OnValueChanged(XUiController _sender, long _oldValue, long _newValue) { CalculateAmmoTotal(); } private void combo762_OnValueChanged(XUiController _sender, long _oldValue, long _newValue) { CalculateAmmoTotal(); } private void combo44_OnValueChanged(XUiController _sender, long _oldValue, long _newValue) { CalculateAmmoTotal(); } private void comboShell_OnValueChanged(XUiController _sender, long _oldValue, long _newValue) { CalculateAmmoTotal(); } private void cbxTargetAmmoType_OnValueChanged(XUiController _sender, string _oldValue, string _newValue) { EntityPlayer player = xui.playerUI.entityPlayer; //Log.Out("XUiC_TradeAmmoRebirth-XUiC_TradeAmmoRebirth cbxTargetAmmoType: " + cbxTargetAmmoType.Value); ResetAmmoCount(player, cbxTargetAmmoType.Value); } public override void Update(float _dt) { base.Update(_dt); if ((Time.time - uiCheck) > uiTick) { uiCheck = Time.time; //Log.Out("XUiC_TradeAmmoRebirth-Update 1"); } } public override void OnOpen() { //Log.Out("XUiC_TradeAmmoRebirth-OnOpen START"); EntityPlayer player = xui.playerUI.entityPlayer; var entityID = 0; if (player.Buffs.HasCustomVar("CurrentNPC")) { entityID = (int)player.Buffs.GetCustomVar("CurrentNPC"); //Log.Out("XUiC_TradeAmmoRebirth-OnOpen 1, entityID: " + entityID); } if (entityID == 0) { //Log.Out("XUiC_TradeAmmoRebirth-OnOpen 2"); return; } float progressionLevel = 0; ProgressionValue progressionValue = player.Progression.GetProgressionValue("perkBetterBarter"); if (progressionValue != null) { progressionLevel = RebirthUtilities.GetCalculatedLevel(player, progressionValue); } barterPerc = 0.5f + (progressionLevel * 0.05f); LabelDescription.Text = Localization.Get("xuiTradeAmmoDescription").Replace("{0}", ((int)(barterPerc * 100)).ToString() + "%"); //combo9mm.Value = 0; cbxTargetAmmoType.SelectedIndex = 0; ResetAmmoCount(player, "9mm"); base.OnOpen(); } private void CalculateAmmoTotal() { float total = 0; string ammoType = cbxTargetAmmoType.Value; combo9mm.Enabled = true; combo762.Enabled = true; combo44.Enabled = true; comboShell.Enabled = true; if (ammoType == "9mm") { combo9mm.Max = 0; combo9mm.Value = 0; combo9mm.Enabled = false; total = (combo762.Value * barterPerc * 2090 + combo44.Value * barterPerc * 1740 + comboShell.Value * barterPerc * 1500) / 1590; } if (ammoType == "762") { combo762.Max = 0; combo762.Value = 0; combo762.Enabled = false; total = (combo9mm.Value * barterPerc * 1590 + combo44.Value * barterPerc * 1740 + comboShell.Value * barterPerc * 1500) / 2090; } if (ammoType == ".44") { combo44.Max = 0; combo44.Value = 0; combo44.Enabled = false; total = (combo762.Value * barterPerc * 2090 + combo9mm.Value * barterPerc * 1590 + comboShell.Value * barterPerc * 1500) / 1740; } if (ammoType == "Shell") { comboShell.Max = 0; comboShell.Value = 0; comboShell.Enabled = false; total = (combo762.Value * barterPerc * 2090 + combo44.Value * barterPerc * 1740 + combo9mm.Value * barterPerc * 1590) / 1500; } LabelTotal.Text = ((int)total).ToString(); } private void ResetAmmoCount(EntityPlayer player, string ammoType) { combo9mm.Max = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("ammo9mmBulletBall", false), player); combo762.Max = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("ammo762mmBulletBall", false), player); combo44.Max = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("ammo44MagnumBulletBall", false), player); comboShell.Max = RebirthUtilities.GetNonProtectedBagItemCount(ItemClass.GetItem("ammoShotgunShell", false), player); if (ammoType == "9mm") { combo9mm.Max = 0; } if (ammoType == "762") { combo762.Max = 0; } if (ammoType == ".44") { combo44.Max = 0; } if (ammoType == "Shell") { comboShell.Max = 0; } combo9mm.Value = combo9mm.Max; combo762.Value = combo762.Max; combo44.Value = combo44.Max; comboShell.Value = comboShell.Max; CalculateAmmoTotal(); string iconName = ""; if (ammoType == "9mm") { iconName = "ammo9mmBulletBall"; } if (ammoType == "762") { iconName = "ammo762mmBulletBall"; } if (ammoType == ".44") { iconName = "ammo44MagnumBulletBall"; } if (ammoType == "Shell") { iconName = "ammoShotgunShell"; } spriteAmmoImage.SpriteName = "ui_game_symbol_" + iconName; } private void BtnConfirm_OnPressed(XUiController _sender, int _mouseButton) { //Log.Out("XUiC_TradeAmmoRebirth-BtnConfirm_OnPressed START"); int totalReceived = Int32.Parse(LabelTotal.Text); if (totalReceived == 0) { return; } EntityPlayer player = xui.playerUI.entityPlayer; string ammoType = cbxTargetAmmoType.Value; //Log.Out("XUiC_TradeAmmoRebirth-BtnConfirm_OnPressed ammoType: " + ammoType); int num9mm = (int)combo9mm.Value; if (num9mm > 0 && ammoType != "9mm") { //Log.Out("XUiC_TradeAmmoRebirth-BtnConfirm_OnPressed dec 9mm"); RebirthUtilities.DecBagItem(ItemClass.GetItem("ammo9mmBulletBall", false), num9mm, player); } int num762 = (int)combo762.Value; if (num762 > 0 && ammoType != "762") { //Log.Out("XUiC_TradeAmmoRebirth-BtnConfirm_OnPressed dec 762"); RebirthUtilities.DecBagItem(ItemClass.GetItem("ammo762mmBulletBall", false), num762, player); } int num44 = (int)combo44.Value; if (num44 > 0 && ammoType != ".44") { //Log.Out("XUiC_TradeAmmoRebirth-BtnConfirm_OnPressed dec .44"); RebirthUtilities.DecBagItem(ItemClass.GetItem("ammo44MagnumBulletBall", false), num44, player); } int numShell = (int)comboShell.Value; if (numShell > 0 && ammoType != "Shell") { //Log.Out("XUiC_TradeAmmoRebirth-BtnConfirm_OnPressed dec Shell"); RebirthUtilities.DecBagItem(ItemClass.GetItem("ammoShotgunShell", false), numShell, player); } string itemTradeFor = ""; if (ammoType == "9mm") { itemTradeFor = "ammo9mmBulletBall"; } if (ammoType == "762") { itemTradeFor = "ammo762mmBulletBall"; } if (ammoType == ".44") { itemTradeFor = "ammo44MagnumBulletBall"; } if (ammoType == "Shell") { itemTradeFor = "ammoShotgunShell"; } ItemValue itemReceived = ItemClass.GetItem(itemTradeFor, false); RebirthUtilities.addToPlayerInventory(itemReceived, player, totalReceived); xui.playerUI.windowManager.Close(windowGroup.ID); } private void BtnCancel_OnPressed(XUiController _sender, int _mouseButton) { //Log.Out("XUiC_TradeAmmoRebirth-BtnCancel_OnPressed START"); Panel.IsVisible = false; xui.playerUI.windowManager.Close(windowGroup.ID); } public override void OnClose() { //Log.Out("XUiC_TradeAmmoRebirth-OnClose START"); if (xui.playerUI.windowManager.HasWindow("dialog") && xui.playerUI.windowManager.IsWindowOpen("dialog")) xui.playerUI.windowManager.Close("dialog"); base.OnClose(); } }