Files
zzz_REBIRTH__Utils/Scripts/XUIC/XUiC_RandomItemRebirth.cs
2025-06-04 16:44:53 +09:30

522 lines
24 KiB
C#

using Audio;
using static RebirthVariables;
using static vp_Timer;
internal class XUiC_RandomItemRebirth : XUiController
{
private static float uiCheck = 1f;
public float uiTick = 0.5f;
public float barterPerc = 0f;
public float durabilityThreshold = 0.5f;
public float multiplierCash = 3f;
public float multiplierBlueprint = 1.5f;
public float tierMultiplier = 0.35f;
public float barterPercUnit = 0.04f;
public bool cannotTrade = false;
public ItemValue currentItem = null;
public XUiV_Label LabelTotal;
private XUiC_ComboBoxList<string> cbxRandomWeapon;
public XUiV_Label LabelDescription;
public XUiV_Panel Panel;
public XUiV_Label lblNameLabel;
public XUiV_Label lblName;
public XUiV_Label lblEntityDamageLabel;
public XUiV_Label lblEntityDamage;
public XUiV_Label lblBlockDamageLabel;
public XUiV_Label lblBlockDamage;
public XUiV_Label lblRoundsPerMinuteLabel;
public XUiV_Label lblRoundsPerMinute;
public XUiV_Label lblAttacksPerMinuteLabel;
public XUiV_Label lblAttacksPerMinute;
public XUiV_Label lblDamageFalloffRangeLabel;
public XUiV_Label lblDamageFalloffRange;
public XUiV_Label lblStaminaLossLabel;
public XUiV_Label lblStaminaLoss;
public XUiV_Label lblMagazineSizeLabel;
public XUiV_Label lblMagazineSize;
public XUiV_Label lblDegradationMaxLabel;
public XUiV_Label lblDegradationMax;
public XUiV_Label lblModSlotsLabel;
public XUiV_Label lblModSlots;
public XUiV_Label lblBonusLabel;
public XUiV_Label lblBonus;
public XUiV_Label lblTotalCash;
public XUiV_Label lblTotalBlueprints;
public XUiV_Label lblPurchaseCost;
public XUiV_Label lblRefreshCost;
public XUiV_Label lblRefreshTime;
public XUiV_Sprite spriteItemImage;
public XUiV_Sprite spriteBonusTypeIcon;
public XUiV_Sprite cashImage;
public XUiV_Sprite blueprintImage;
public XUiV_Sprite refreshImage;
public override void Init()
{
base.Init();
Panel = (XUiV_Panel)GetChildById("Popup").ViewComponent;
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnPurchase")).OnPressed += BtnPurchase_OnPressed;
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnRefresh")).OnPressed += BtnRefresh_OnPressed;
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnCancel")).OnPressed += BtnCancel_OnPressed;
LabelDescription = (XUiV_Label)Panel.Controller.GetChildById("lblDescription").ViewComponent;
lblNameLabel = (XUiV_Label)Panel.Controller.GetChildById("lblNameLabel").ViewComponent;
lblName = (XUiV_Label)Panel.Controller.GetChildById("lblName").ViewComponent;
lblEntityDamageLabel = (XUiV_Label)Panel.Controller.GetChildById("lblEntityDamageLabel").ViewComponent;
lblEntityDamage = (XUiV_Label)Panel.Controller.GetChildById("lblEntityDamage").ViewComponent;
lblBlockDamageLabel = (XUiV_Label)Panel.Controller.GetChildById("lblBlockDamageLabel").ViewComponent;
lblBlockDamage = (XUiV_Label)Panel.Controller.GetChildById("lblBlockDamage").ViewComponent;
lblRoundsPerMinuteLabel = (XUiV_Label)Panel.Controller.GetChildById("lblRoundsPerMinuteLabel").ViewComponent;
lblRoundsPerMinute = (XUiV_Label)Panel.Controller.GetChildById("lblRoundsPerMinute").ViewComponent;
lblAttacksPerMinuteLabel = (XUiV_Label)Panel.Controller.GetChildById("lblAttacksPerMinuteLabel").ViewComponent;
lblAttacksPerMinute = (XUiV_Label)Panel.Controller.GetChildById("lblAttacksPerMinute").ViewComponent;
lblDamageFalloffRangeLabel = (XUiV_Label)Panel.Controller.GetChildById("lblDamageFalloffRangeLabel").ViewComponent;
lblDamageFalloffRange = (XUiV_Label)Panel.Controller.GetChildById("lblDamageFalloffRange").ViewComponent;
lblStaminaLossLabel = (XUiV_Label)Panel.Controller.GetChildById("lblStaminaLossLabel").ViewComponent;
lblStaminaLoss = (XUiV_Label)Panel.Controller.GetChildById("lblStaminaLoss").ViewComponent;
lblMagazineSizeLabel = (XUiV_Label)Panel.Controller.GetChildById("lblMagazineSizeLabel").ViewComponent;
lblMagazineSize = (XUiV_Label)Panel.Controller.GetChildById("lblMagazineSize").ViewComponent;
lblDegradationMaxLabel = (XUiV_Label)Panel.Controller.GetChildById("lblDegradationMaxLabel").ViewComponent;
lblDegradationMax = (XUiV_Label)Panel.Controller.GetChildById("lblDegradationMax").ViewComponent;
lblModSlotsLabel = (XUiV_Label)Panel.Controller.GetChildById("lblModSlotsLabel").ViewComponent;
lblModSlots = (XUiV_Label)Panel.Controller.GetChildById("lblModSlots").ViewComponent;
lblBonusLabel = (XUiV_Label)Panel.Controller.GetChildById("lblBonusLabel").ViewComponent;
lblBonus = (XUiV_Label)Panel.Controller.GetChildById("lblBonus").ViewComponent;
lblTotalCash = (XUiV_Label)Panel.Controller.GetChildById("lblTotalCash").ViewComponent;
lblTotalBlueprints = (XUiV_Label)Panel.Controller.GetChildById("lblTotalBlueprints").ViewComponent;
lblPurchaseCost = (XUiV_Label)Panel.Controller.GetChildById("lblPurchaseCost").ViewComponent;
lblRefreshCost = (XUiV_Label)Panel.Controller.GetChildById("lblRefreshCost").ViewComponent;
lblRefreshTime = (XUiV_Label)Panel.Controller.GetChildById("lblRefreshTime").ViewComponent;
spriteItemImage = (XUiV_Sprite)GetChildById("itemImage").ViewComponent;
spriteBonusTypeIcon = (XUiV_Sprite)GetChildById("bonusTypeIcon").ViewComponent;
cashImage = (XUiV_Sprite)GetChildById("CashImage").ViewComponent;
blueprintImage = (XUiV_Sprite)GetChildById("BlueprintImage").ViewComponent;
refreshImage = (XUiV_Sprite)GetChildById("RefreshImage").ViewComponent;
this.cbxRandomWeapon = (base.GetChildById("cbxItem") as XUiC_ComboBoxList<string>);
if (this.cbxRandomWeapon != null)
{
this.cbxRandomWeapon.OnValueChanged += this.cbxRandomWeapon_OnValueChanged;
}
}
public override void Update(float _dt)
{
base.Update(_dt);
if ((Time.time - uiCheck) > uiTick)
{
uiCheck = Time.time;
lblRefreshTime.Text = Localization.Get("xuiExpiresIn") + ": [c98181]" + RebirthUtilities.GetTimeRemainingMS(RebirthVariables.randomWeaponUpdateTick, RebirthVariables.randomWeaponUpdateCheck) + "[-]";
lblRefreshTime.isDirty = true;
if (RebirthVariables.refreshRandomWeapons)
{
RebirthVariables.refreshRandomWeapons = false;
Reset();
updateItem();
}
}
}
private void cbxRandomWeapon_OnValueChanged(XUiController _sender, string _oldValue, string _newValue)
{
updateItem();
}
private void updateItem()
{
EntityPlayer player = xui.playerUI.entityPlayer;
int questTier = player.QuestJournal.GetCurrentFactionTier((byte)1);
string purchaseCost = Localization.Get("xuiPurchaseItemExchange");
currentItem = null;
if (RebirthVariables.randomWeapons.Count > 0)
{
//Log.Out("XUiC_RandomItemRebirth-OnOpen cbxRandomWeapon.SelectedIndex:" + cbxRandomWeapon.SelectedIndex);
RandomWeapon randomWeapon = RebirthVariables.randomWeapons[cbxRandomWeapon.SelectedIndex];
if (randomWeapon.Weapon != null)
{
ItemValue itemValue = randomWeapon.Weapon;
currentItem = itemValue;
int entityDamage = (int)EffectManager.GetValue(PassiveEffects.EntityDamage, itemValue);
int blockDamage = (int)EffectManager.GetValue(PassiveEffects.BlockDamage, itemValue);
int staminaLoss = (int)EffectManager.GetValue(PassiveEffects.StaminaLoss, itemValue);
if (randomWeapon.Type == WeaponType.Melee)
{
// MELEE
lblRoundsPerMinuteLabel.IsVisible = false;
lblRoundsPerMinute.IsVisible = false;
lblDamageFalloffRangeLabel.IsVisible = false;
lblDamageFalloffRange.IsVisible = false;
lblMagazineSizeLabel.IsVisible = false;
lblMagazineSize.IsVisible = false;
lblBlockDamageLabel.IsVisible = true;
lblBlockDamage.IsVisible = true;
lblAttacksPerMinuteLabel.IsVisible = true;
lblAttacksPerMinute.IsVisible = true;
lblStaminaLossLabel.IsVisible = true;
lblStaminaLoss.IsVisible = true;
int entityDamagePrimary = (int)EffectManager.GetValue(PassiveEffects.EntityDamage, itemValue, 0, player, null, FastTags<TagGroup.Global>.Parse("primary"));
int entityDamageSecondary = (int)EffectManager.GetValue(PassiveEffects.EntityDamage, itemValue, 0, player, null, FastTags<TagGroup.Global>.Parse("secondary"));
if (entityDamagePrimary == 0)
{
lblEntityDamage.Text = $"{entityDamage}";
}
else
{
if (entityDamagePrimary == entityDamageSecondary)
{
lblEntityDamage.Text = $"{entityDamagePrimary}";
}
else
{
lblEntityDamage.Text = $"{entityDamagePrimary} ({entityDamageSecondary})";
}
}
lblEntityDamage.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen EntityDamage (Primary):" + (int)EffectManager.GetValue(PassiveEffects.EntityDamage, itemValue, 0, player, null, FastTags<TagGroup.Global>.Parse("primary")));
//Log.Out("XUiC_RandomItemRebirth-OnOpen EntityDamage (Secondary):" + (int)EffectManager.GetValue(PassiveEffects.EntityDamage, itemValue, 0, player, null, FastTags<TagGroup.Global>.Parse("secondary")));
lblBlockDamageLabel.IsVisible = true;
int blockDamagePrimary = (int)EffectManager.GetValue(PassiveEffects.BlockDamage, itemValue, 0, player, null, FastTags<TagGroup.Global>.Parse("primary"));
int blockDamageSecondary = (int)EffectManager.GetValue(PassiveEffects.BlockDamage, itemValue, 0, player, null, FastTags<TagGroup.Global>.Parse("secondary"));
if (blockDamagePrimary == 0)
{
lblBlockDamage.Text = $"{blockDamage}";
}
else
{
if (blockDamagePrimary == blockDamageSecondary)
{
lblBlockDamage.Text = $"{blockDamagePrimary}";
}
else
{
lblBlockDamage.Text = $"{blockDamagePrimary} ({blockDamageSecondary})";
}
}
lblBlockDamage.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen BlockDamage (Primary):" + blockDamagePrimary);
//Log.Out("XUiC_RandomItemRebirth-OnOpen BlockDamage (Secondary):" + blockDamageSecondary);
lblAttacksPerMinuteLabel.IsVisible = true;
lblAttacksPerMinute.Text = $"{(int)EffectManager.GetValue(PassiveEffects.AttacksPerMinute, itemValue)}";
lblAttacksPerMinute.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen AttacksPerMinute:" + (int)EffectManager.GetValue(PassiveEffects.AttacksPerMinute, itemValue));
lblStaminaLossLabel.IsVisible = true;
int staminaLossPrimary = (int)EffectManager.GetValue(PassiveEffects.StaminaLoss, itemValue, 0, player, null, FastTags<TagGroup.Global>.Parse("primary"));
int staminaLossSecondary = (int)EffectManager.GetValue(PassiveEffects.StaminaLoss, itemValue, 0, player, null, FastTags<TagGroup.Global>.Parse("secondary"));
if (staminaLossPrimary == 0)
{
lblStaminaLoss.Text = $"{staminaLoss}";
}
else
{
if (staminaLossPrimary == staminaLossSecondary)
{
lblStaminaLoss.Text = $"{staminaLossPrimary}";
}
else
{
lblStaminaLoss.Text = $"{staminaLossPrimary} ({staminaLossSecondary})";
}
}
lblStaminaLoss.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen StaminaLoss (Primary):" + staminaLossPrimary);
//Log.Out("XUiC_RandomItemRebirth-OnOpen StaminaLoss (Secondary):" + staminaLossSecondary);
}
else if (randomWeapon.Type == WeaponType.Ranged)
{
// RANGED
lblBlockDamageLabel.IsVisible = false;
lblBlockDamage.IsVisible = false;
lblAttacksPerMinuteLabel.IsVisible = false;
lblAttacksPerMinute.IsVisible = false;
lblStaminaLossLabel.IsVisible = false;
lblStaminaLoss.IsVisible = false;
lblRoundsPerMinuteLabel.IsVisible = true;
lblRoundsPerMinute.IsVisible = true;
lblDamageFalloffRangeLabel.IsVisible = true;
lblDamageFalloffRange.IsVisible = true;
lblMagazineSizeLabel.IsVisible = true;
lblMagazineSize.IsVisible = true;
lblEntityDamage.Text = $"{entityDamage}";
lblEntityDamage.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen EntityDamage (Primary):" + entityDamage);
lblRoundsPerMinuteLabel.IsVisible = true;
lblRoundsPerMinute.Text = $"{(int)EffectManager.GetValue(PassiveEffects.RoundsPerMinute, itemValue)}";
lblRoundsPerMinute.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen RoundsPerMinute:" + (int)EffectManager.GetValue(PassiveEffects.RoundsPerMinute, itemValue));
lblDamageFalloffRangeLabel.IsVisible = true;
lblDamageFalloffRange.Text = $"{(int)EffectManager.GetValue(PassiveEffects.DamageFalloffRange, itemValue)}";
lblDamageFalloffRange.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen DamageFalloffRange:" + (int)EffectManager.GetValue(PassiveEffects.DamageFalloffRange, itemValue));
lblMagazineSizeLabel.IsVisible = true;
lblMagazineSize.Text = $"{(int)EffectManager.GetValue(PassiveEffects.MagazineSize, itemValue)}";
lblMagazineSize.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen MagazineSize:" + (int)EffectManager.GetValue(PassiveEffects.MagazineSize, itemValue));
}
// COMMON
lblName.Text = Localization.Get(itemValue.ItemClass.Name);
lblName.IsDirty = true;
lblDegradationMax.Text = $"{(int)EffectManager.GetValue(PassiveEffects.DegradationMax, itemValue)}";
lblDegradationMax.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen DegradationMax:" + (int)EffectManager.GetValue(PassiveEffects.DegradationMax, itemValue));
lblModSlots.Text = $"{(int)EffectManager.GetValue(PassiveEffects.ModSlots, itemValue)}";
lblModSlots.IsDirty = true;
//Log.Out("XUiC_RandomItemRebirth-OnOpen ModSlots:" + (int)EffectManager.GetValue(PassiveEffects.ModSlots, itemValue));
lblBonus.Text = $"{Localization.Get("xui" + (string)itemValue.GetMetadata("bonus"))} [c9c7c7]([-]{Localization.Get("ttLevelFull")} [e0dcab]{(int)itemValue.GetMetadata("level")}[-][c9c7c7])[-]";
lblBonus.IsDirty = true;
spriteItemImage.SpriteName = "ui_game_symbol_" + itemValue.ItemClass.GetIconName();
spriteItemImage.IsDirty = true;
spriteBonusTypeIcon.SpriteName = "ui_game_symbol_" + (string)itemValue.GetMetadata("bonus");
spriteBonusTypeIcon.IsDirty = true;
cannotTrade = false;
float durability = 1 - itemValue.UseTimes;
float multiplier = 1 + ((float)(RebirthUtilities.GetTier(itemValue.ItemClass) * tierMultiplier));
int numBlueprints = (int)(0.16 * (durability * 100 * multiplier) * (1 - barterPerc) * multiplierBlueprint);
int cash = (int)(9 * (durability * 100 * multiplier) * (1 - barterPerc) * multiplierCash);
string cashColor = "[ffffff]";
string blueprintColor = "[ffffff]";
string blueprint = RebirthUtilities.GetBlueprint(itemValue.ItemClass);
//Log.Out("XUiC_RandomItemRebirth-OnOpen blueprint:" + blueprint);
int totalCash = RebirthUtilities.numItems(ItemClass.GetItem("casinoCoin"), player);
int totalBlueprints = RebirthUtilities.numItems(ItemClass.GetItem("geneticBlueprint" + blueprint), player);
if (totalCash < cash)
{
cashColor = "[c79595]";
cannotTrade = true;
}
if (totalBlueprints < numBlueprints)
{
blueprintColor = "[c79595]";
cannotTrade = true;
}
lblTotalCash.Text = cashColor + cash.ToString() + "[-]";
lblTotalBlueprints.Text = blueprintColor + numBlueprints.ToString() + "[-]";
if (cannotTrade)
{
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnPurchase")).Enabled = false;
}
else
{
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnPurchase")).Enabled = true;
}
cashImage.spriteName = "ui_game_symbol_oldCash";
blueprintImage.spriteName = "ui_game_symbol_FR_Blueprint" + blueprint;
blueprintImage.isDirty = true;
lblPurchaseCost.Text = Localization.Get("xuiPurchaseItemExchange");
}
}
else
{
lblName.Text = "-";
lblEntityDamage.Text = "-";
lblBlockDamage.Text = "-";
lblAttacksPerMinute.Text = "-";
lblStaminaLoss.Text = "-";
lblRoundsPerMinute.Text = "-";
lblDamageFalloffRange.Text = "-";
lblMagazineSize.Text = "-";
lblDegradationMax.Text = "-";
lblModSlots.Text = "-";
lblBonus.Text = "-";
spriteItemImage.spriteName = "";
spriteBonusTypeIcon.spriteName = "";
cashImage.spriteName = "";
blueprintImage.spriteName = "";
spriteItemImage.isDirty = true;
spriteBonusTypeIcon.isDirty = true;
cashImage.isDirty = true;
blueprintImage.isDirty = true;
lblTotalCash.Text = "";
lblTotalBlueprints.Text = "";
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnPurchase")).Enabled = false;
lblPurchaseCost.Text = Localization.Get("xuiPurchaseItemNothingExchange");
}
int charismaBlueprints = RebirthUtilities.numItems(ItemClass.GetItem("geneticBlueprintCharisma"), player);
int multiplierRefresh = (int)(1 + ((questTier - 1) * 0.75));
int numCharismaBlueprints = (int)(15 * (1 - barterPerc) * multiplierRefresh);
if (charismaBlueprints >= numCharismaBlueprints)
{
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnRefresh")).Enabled = true;
lblRefreshCost.Text = numCharismaBlueprints.ToString();
refreshImage.spriteName = "ui_game_symbol_FR_BlueprintCharisma";
refreshImage.isDirty = true;
}
else
{
((XUiC_SimpleButton)Panel.Controller.GetChildById("btnRefresh")).Enabled = false;
lblRefreshCost.Text = "[c79595]" + numCharismaBlueprints.ToString() + "[-]";
refreshImage.spriteName = "ui_game_symbol_FR_BlueprintCharisma";
refreshImage.isDirty = true;
}
}
public void Reset()
{
cbxRandomWeapon.Elements.Clear();
if (RebirthVariables.randomWeapons.Count > 0)
{
for (int i = 1; i < RebirthVariables.randomWeapons.Count + 1; i++)
{
this.cbxRandomWeapon.Elements.Add(i.ToString());
}
cbxRandomWeapon.SelectedIndex = 0;
}
}
public override void OnOpen()
{
base.OnOpen();
EntityPlayer player = xui.playerUI.entityPlayer;
float progressionLevel = 0;
ProgressionValue progressionValue = player.Progression.GetProgressionValue("perkBetterBarter");
if (progressionValue != null)
{
progressionLevel = RebirthUtilities.GetCalculatedLevel(player, progressionValue);
}
barterPerc = progressionLevel * barterPercUnit;
LabelDescription.Text = Localization.Get("xuiItemsToPurchaseDescription").Replace("{0}", ((int)(barterPerc * 100)).ToString() + "%");
Reset();
updateItem();
}
private void BtnCancel_OnPressed(XUiController _sender, int _mouseButton)
{
//Log.Out("XUiC_RandomItemRebirth-BtnCancel_OnPressed START");
Panel.IsVisible = false;
xui.playerUI.windowManager.Close(windowGroup.ID);
}
private void BtnRefresh_OnPressed(XUiController _sender, int _mouseButton)
{
//Log.Out("XUiC_RandomItemRebirth-BtnRefresh_OnPressed currentTrackedItem.Slot: " + currentTrackedItem.Slot);
EntityPlayer player = xui.playerUI.entityPlayer;
RebirthUtilities.useInventoryBagItem(player, "geneticBlueprintCharisma", 15);
RebirthUtilities.RefreshRandomWeapons((EntityPlayerLocal)player);
RebirthVariables.randomWeaponUpdateCheck = Time.time;
Reset();
updateItem();
}
private void BtnPurchase_OnPressed(XUiController _sender, int _mouseButton)
{
//Log.Out("XUiC_RandomItemRebirth-BtnPurchase_OnPressed currentTrackedItem.Slot: " + currentTrackedItem.Slot);
EntityPlayer player = xui.playerUI.entityPlayer;
currentItem.SetMetadata("active", 1, TypedMetadataValue.TypeTag.Integer);
RebirthUtilities.addToPlayerBag(currentItem, player, 1);
float durability = 1 - currentItem.UseTimes;
float multiplier = 1 + ((float)(RebirthUtilities.GetTier(currentItem.ItemClass) * tierMultiplier));
int numBlueprints = (int)(0.16 * (durability * 100 * multiplier) * (1 - barterPerc) * multiplierBlueprint);
int cash = (int)(9 * (durability * 100 * multiplier) * (1 - barterPerc) * multiplierCash);
string blueprint = RebirthUtilities.GetBlueprint(currentItem.ItemClass);
RebirthUtilities.useInventoryBagItem(player, "casinoCoin", cash);
RebirthUtilities.useInventoryBagItem(player, "geneticBlueprint" + blueprint, numBlueprints);
RebirthVariables.randomWeapons.RemoveAt(cbxRandomWeapon.SelectedIndex);
Reset();
updateItem();
}
public override void OnClose()
{
//Log.Out("XUiC_RandomItemRebirth-OnClose START");
if (xui.playerUI.windowManager.HasWindow("dialog") && xui.playerUI.windowManager.IsWindowOpen("dialog"))
xui.playerUI.windowManager.Close("dialog");
base.OnClose();
}
}