Files
7d2dXG/Mods/zzz_REBIRTH__Utils/Scripts/MinEvents/MinEventActionModifyVariableRebirth.cs
Nathaniel Cosford e06f2bd282 Add All Mods
2025-05-29 23:33:28 +09:30

603 lines
29 KiB
C#

using System.Globalization;
using System.Xml.Linq;
using UnityEngine.Scripting;
[Preserve]
public class MinEventActionModifyVariableRebirth : MinEventActionTargetedBase
{
public string cvarName { get; private set; }
public override void Execute(MinEventParams _params)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute START");
if (_params.Self.isEntityRemote && !_params.IsLocal)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 1");
return;
}
for (int i = 0; i < this.targets.Count; i++)
{
if (this.cvarRef)
{
if (this.refVariable == 1)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute cvarRef, " + this.refCvarName + ": " + RebirthVariables.localVariables[this.refCvarName]);
this.value = RebirthVariables.localVariables[this.refCvarName];
}
else
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute cvarRef, " + this.refCvarName + ": " + RebirthVariables.localConstants[this.refCvarName]);
this.value = RebirthVariables.localConstants[this.refCvarName];
}
}
else if (this.rollType == MinEventActionModifyVariableRebirth.RandomRollTypes.randomInt)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 2");
this.value = Mathf.Clamp((float)_params.Self.rand.RandomRange((int)this.minValue, (int)this.maxValue + 1), this.minValue, this.maxValue);
}
else if (this.rollType == MinEventActionModifyVariableRebirth.RandomRollTypes.randomFloat)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 3");
this.value = Mathf.Clamp(_params.Self.rand.RandomRange(this.minValue, this.maxValue + 1f), this.minValue, this.maxValue);
}
float num = 0;
if (setConstant == 1)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute SOURCE: localConstants");
num = RebirthVariables.localConstants[this.cvarName];
}
else
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute SOURCE: localVariables");
num = RebirthVariables.localVariables[this.cvarName];
}
//Log.Out("MinEventActionModifyVariableRebirth-Execute num: " + num);
//Log.Out("MinEventActionModifyVariableRebirth-Execute this.value: " + this.value);
int isClass = 0;
string keyName = "";
float value = this.value;
float classID = 0;
float activeClassID = this.targets[i].Buffs.GetCustomVar("$ActiveClass_FR");
if (this.cvarName.Contains("PercUnit"))
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute cvarName.Contains(PercUnit)");
if (RebirthUtilities.HasGeneticsKey(this.cvarName))
{
foreach (var key in RebirthVariables.localGenetics.Keys)
{
if (this.cvarName.Contains(key))
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute Genetics A BEFORE value: " + value);
float geneticsMultiplierOption = float.Parse(RebirthVariables.customGeneticsXPMultiplier) / 100;
//Log.Out("MinEventActionModifyVariableRebirth-Execute Class geneticsMultiplierOption: " + geneticsMultiplierOption);
keyName = key;
value *= geneticsMultiplierOption;
//Log.Out("MinEventActionModifyVariableRebirth-Execute Genetics A AFTER value: " + value);
break;
}
}
}
else
{
foreach (var key in RebirthVariables.localClasses.Keys)
{
if (this.cvarName.Contains(key))
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute Class B BEFORE value: " + value);
float classMultiplierOption = float.Parse(RebirthVariables.customClassXPMultiplier) / 100;
//Log.Out("MinEventActionModifyVariableRebirth-Execute Class classMultiplierOption: " + classMultiplierOption);
isClass = 1;
keyName = key;
value *= classMultiplierOption;
//Log.Out("MinEventActionModifyVariableRebirth-Execute Class B AFTER value: " + value);
break;
}
}
if (isClass == 0)
{
foreach (var key in RebirthVariables.localExpertise.Keys)
{
if (this.cvarName.Contains(key))
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise key: " + key);
string pipeWeapon = "";
string starterMeleeWeapon = "";
if (key == "LongRangeRifles")
{
pipeWeapon = "PipeRifle";
}
else if (key == "Shotguns")
{
pipeWeapon = "PipeShotgun";
}
else if (key == "AssaultRifles" ||
key == "MachineGuns" ||
key == "SubmachineGuns" ||
key == "TacticalRifles"
)
{
pipeWeapon = "PipeMachinegun";
}
else if (key == "Revolvers" ||
key == "Pistols" ||
key == "HeavyHandguns"
)
{
pipeWeapon = "PipePistol";
}
else
{
starterMeleeWeapon = key;
}
if (starterMeleeWeapon != "" && key.ToLower() != "melee")
{
this.cvarName = "$varFuriousRamsay" + key + "PercUnit";
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise this.cvarName: " + this.cvarName);
float categoryValue = RebirthUtilities.GetDirectCraftingPerksCategoryValue(key, 50);
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise categoryValue: " + categoryValue);
if (RebirthVariables.localVariables[this.cvarName] < categoryValue)
{
RebirthVariables.localVariables[this.cvarName] = categoryValue;
RebirthUtilities.ProcessAttribute(this.targets[i], this.cvarName);
return;
}
}
if (pipeWeapon != "")
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise pipeWeapon: " + pipeWeapon);
ProgressionValue craftingProgressionValue = this.targets[i].Progression.GetProgressionValue("FuriousRamsayCrafting" + pipeWeapon);
int craftingProgressionLevel = craftingProgressionValue.Level;
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise craftingProgressionLevel: " + craftingProgressionLevel);
if (craftingProgressionLevel < 50)
{
this.cvarName = "$varFuriousRamsay" + pipeWeapon + "PercUnit";
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise this.cvarName: " + this.cvarName);
float categoryValue = RebirthUtilities.GetDirectCraftingPerksCategoryValue(pipeWeapon, 50);
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise categoryValue: " + categoryValue);
RebirthVariables.localVariables[this.cvarName] = categoryValue;
RebirthUtilities.ProcessAttribute(this.targets[i], this.cvarName);
craftingProgressionValue.Level = 50;
this.cvarName = "$varFuriousRamsay" + key + "PercUnit";
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise this.cvarName: " + this.cvarName);
categoryValue = RebirthUtilities.GetDirectCraftingPerksCategoryValue(key, 50);
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise categoryValue: " + categoryValue);
RebirthVariables.localVariables[this.cvarName] = categoryValue;
RebirthUtilities.ProcessAttribute(this.targets[i], this.cvarName);
return;
}
else
{
this.cvarName = "$varFuriousRamsay" + key + "PercUnit";
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise this.cvarName: " + this.cvarName);
float categoryValue = RebirthUtilities.GetDirectCraftingPerksCategoryValue(key, 50);
//Log.Out("MinEventActionModifyVariableRebirth-Execute Expertise categoryValue: " + categoryValue);
if (RebirthVariables.localVariables[this.cvarName] < categoryValue)
{
RebirthVariables.localVariables[this.cvarName] = categoryValue;
RebirthUtilities.ProcessAttribute(this.targets[i], this.cvarName);
return;
}
}
}
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise BEFORE value: " + value);
int currentValue = (int)RebirthVariables.localVariables[this.cvarName];
float classMultiplierOption = float.Parse(RebirthVariables.customClassXPMultiplier) / 100;
//Log.Out("MinEventActionModifyVariableRebirth-Execute Class classMultiplierOption: " + classMultiplierOption);
keyName = key;
isClass = 2;
value *= classMultiplierOption;
if (isPerc == 1)
{
float categoryFloor = RebirthUtilities.GetCategoryFloorFromXP(key, RebirthVariables.localVariables[this.cvarName]);
float categoryCeiling = RebirthUtilities.GetCategoryCeilingFromXP(key, RebirthVariables.localVariables[this.cvarName]);
value = (categoryCeiling - categoryFloor) * this.value;
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise Current XP: " + RebirthVariables.localVariables[this.cvarName]);
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise categoryFloor: " + categoryFloor);
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise categoryCeiling: " + categoryCeiling);
}
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise AFTER value: " + value);
int newValue = (int)(RebirthVariables.localVariables[this.cvarName] + value);
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise currentValue: " + currentValue);
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise newValue: " + newValue);
string className = RebirthUtilities.GetClassFromPerk(key);
classID = RebirthUtilities.GetIDFromClassName(className);
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise className: " + className);
int classValue = (int)RebirthVariables.localVariables["$varFuriousRamsay" + className + "PercUnit"];
if (newValue > currentValue)
{
float residual = (RebirthVariables.localVariables[this.cvarName] + value) - newValue;
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise residual: " + residual);
if (newValue < (int)classValue)
{
residual = 0;
}
RebirthVariables.localVariables[this.cvarName] = newValue;
RebirthUtilities.ProcessAttribute(this.targets[i], this.cvarName);
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise classID: " + classID);
if (perkLevel > 0 && activeClassID == classID)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute C Expertise perkLevel > 0");
RebirthVariables.localConstants["$varFuriousRamsayPerk" + perkLevel + "PercUnit"] = newValue;
}
int currentClassValue = (int)RebirthVariables.localVariables["$varFuriousRamsay" + className + "PercUnit"];
float projectedValue = RebirthVariables.localVariables["$varFuriousRamsay" + className + "PercUnit"] + (residual * 3f);
int newClassValue = (int)projectedValue;
if (newClassValue > currentClassValue)
{
projectedValue = newClassValue;
}
RebirthVariables.localVariables["$varFuriousRamsay" + className + "PercUnit"] = projectedValue;
RebirthUtilities.ProcessAttribute(this.targets[i], "$varFuriousRamsay" + className + "PercUnit");
return;
}
else if (currentValue == classValue)
{
RebirthVariables.localVariables[this.cvarName] = newValue;
RebirthUtilities.ProcessAttribute(this.targets[i], this.cvarName);
//Log.Out("MinEventActionModifyVariableRebirth-Execute D Expertise classID: " + classID);
if (perkLevel > 0 && activeClassID == classID)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute D Expertise perkLevel > 0");
RebirthVariables.localConstants["$varFuriousRamsayPerk" + perkLevel + "PercUnit"] = newValue;
}
int currentClassValue = (int)RebirthVariables.localVariables["$varFuriousRamsay" + className + "PercUnit"];
//Log.Out("MinEventActionModifyVariableRebirth-Execute D Expertise currentClassValue: " + currentClassValue);
float projectedValue = RebirthVariables.localVariables["$varFuriousRamsay" + className + "PercUnit"] + (value * 3f);
if (projectedValue > currentClassValue + 1)
{
projectedValue = currentClassValue + 1;
}
if (activeClassID == 10)
{
if (projectedValue > 15)
{
projectedValue = 15;
}
}
else
{
if (projectedValue > 10)
{
projectedValue = 10;
}
}
//Log.Out("MinEventActionModifyVariableRebirth-Execute D Expertise projectedValue: " + projectedValue);
int newClassValue = (int)projectedValue;
//Log.Out("MinEventActionModifyVariableRebirth-Execute D Expertise newClassValue: " + newClassValue);
if (newClassValue > currentClassValue)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute D Expertise newClassValue > currentClassValue");
projectedValue = newClassValue;
}
RebirthVariables.localVariables["$varFuriousRamsay" + className + "PercUnit"] = projectedValue;
RebirthUtilities.ProcessAttribute(this.targets[i], "$varFuriousRamsay" + className + "PercUnit");
return;
}
break;
}
}
}
}
}
switch (this.operation)
{
case MinEventActionModifyVariableRebirth.OperationTypes.set:
case MinEventActionModifyVariableRebirth.OperationTypes.setvalue:
num = value;
break;
case MinEventActionModifyVariableRebirth.OperationTypes.add:
num += value;
break;
case MinEventActionModifyVariableRebirth.OperationTypes.subtract:
num -= value;
break;
case MinEventActionModifyVariableRebirth.OperationTypes.multiply:
num *= value;
break;
case MinEventActionModifyVariableRebirth.OperationTypes.divide:
num /= ((value == 0f) ? 0.0001f : value);
break;
}
if (this.maxValue > 0f && num > this.maxValue)
{
num = this.maxValue;
}
if (setConstant == 1)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 1, num: " + num);
RebirthVariables.localConstants[this.cvarName] = num;
}
else
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 2");
if (this.cvarName.Contains("PercUnit"))
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 3");
if (RebirthUtilities.HasGeneticsKey(this.cvarName))
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 4");
RebirthUtilities.GetMaxGeneticsProgression(ref num, keyName);
}
else
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 7");
if (isClass == 1)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 8");
int maxProgression = 10;
foreach (var classKey in RebirthVariables.localClassProgressionMax.Keys)
{
if (classKey == keyName)
{
maxProgression = RebirthVariables.localClassProgressionMax[classKey];
break;
}
}
if (num > maxProgression)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 9");
RebirthVariables.localVariables[this.cvarName] = maxProgression;
num = maxProgression;
}
}
else if (isClass == 2)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 11");
int maxProgression = 10;
//Log.Out("MinEventActionModifyVariableRebirth-Execute " + this.cvarName + ": " + RebirthVariables.localVariables[this.cvarName]);
//Log.Out("MinEventActionModifyVariableRebirth-Execute num: " + num);
foreach (var classKey in RebirthVariables.localExpertise.Keys)
{
if (classKey == keyName)
{
maxProgression = RebirthVariables.localExpertise[classKey];
break;
}
}
//Log.Out("MinEventActionModifyVariableRebirth-Execute maxProgression: " + maxProgression);
if (num > maxProgression)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 12");
RebirthVariables.localVariables[this.cvarName] = maxProgression;
num = maxProgression;
}
}
}
}
//Log.Out("MinEventActionModifyVariableRebirth-Execute 15");
RebirthVariables.localVariables[this.cvarName] = num;
}
//Log.Out("MinEventActionModifyVariableRebirth-Execute Z classID: " + classID);
if (perkLevel > 0 && activeClassID == classID)
{
RebirthVariables.localConstants["$varFuriousRamsayPerk" + perkLevel + "PercUnit"] = num;
//Log.Out("MinEventActionModifyCVarLBD-Execute $varFuriousRamsayPerk" + perkLevel + "PercUnit: " + RebirthVariables.localConstants["$varFuriousRamsayPerk" + perkLevel + "PercUnit"]);
}
if (processAttribute == 1)
{
//Log.Out("MinEventActionModifyVariableRebirth-Execute 16");
RebirthUtilities.ProcessAttribute(this.targets[i], this.cvarName);
}
//Log.Out("MinEventActionModifyVariableRebirth-Execute " + this.cvarName + ": " + RebirthVariables.localVariables[this.cvarName]);
}
}
public override bool ParseXmlAttribute(XAttribute _attribute)
{
bool flag = base.ParseXmlAttribute(_attribute);
if (!flag)
{
string localName = _attribute.Name.LocalName;
if (localName == "cvar")
{
this.cvarName = _attribute.Value;
return true;
}
if (localName == "operation")
{
this.operation = EnumUtils.Parse<MinEventActionModifyVariableRebirth.OperationTypes>(_attribute.Value, true);
return true;
}
if (localName == "processAttribute")
{
this.processAttribute = int.Parse(_attribute.Value);
return true;
}
if (localName == "refVariable")
{
this.refVariable = int.Parse(_attribute.Value);
return true;
}
if (localName == "setConstant")
{
this.setConstant = int.Parse(_attribute.Value);
return true;
}
if (localName == "maxValue")
{
this.maxValue = int.Parse(_attribute.Value);
return true;
}
if (localName == "perkLevel")
{
this.perkLevel = int.Parse(_attribute.Value);
return true;
}
if (localName == "isPerc")
{
this.isPerc = int.Parse(_attribute.Value);
return true;
}
if (localName == "value")
{
//Log.Out("MinEventActionModifyVariableRebirth-ParseXmlAttribute 1");
this.rollType = MinEventActionModifyVariableRebirth.RandomRollTypes.none;
this.cvarRef = false;
if (_attribute.Value.StartsWith("randomint", StringComparison.OrdinalIgnoreCase))
{
//Log.Out("MinEventActionModifyVariableRebirth-ParseXmlAttribute 2");
Vector2 vector = StringParsers.ParseVector2(_attribute.Value.Substring(_attribute.Value.IndexOf('(') + 1, _attribute.Value.IndexOf(')') - (_attribute.Value.IndexOf('(') + 1)));
this.minValue = (float)((int)vector.x);
this.maxValue = (float)((int)vector.y);
this.rollType = MinEventActionModifyVariableRebirth.RandomRollTypes.randomInt;
}
else if (_attribute.Value.StartsWith("randomfloat", StringComparison.OrdinalIgnoreCase))
{
//Log.Out("MinEventActionModifyVariableRebirth-ParseXmlAttribute 3");
Vector2 vector2 = StringParsers.ParseVector2(_attribute.Value.Substring(_attribute.Value.IndexOf('(') + 1, _attribute.Value.IndexOf(')') - (_attribute.Value.IndexOf('(') + 1)));
this.minValue = vector2.x;
this.maxValue = vector2.y;
this.rollType = MinEventActionModifyVariableRebirth.RandomRollTypes.randomFloat;
}
else if (_attribute.Value.StartsWith("@"))
{
//Log.Out("MinEventActionModifyVariableRebirth-ParseXmlAttribute 4");
this.cvarRef = true;
this.refCvarName = _attribute.Value.Substring(1);
}
else
{
this.value = StringParsers.ParseFloat(_attribute.Value, 0, -1, NumberStyles.Any);
//Log.Out("MinEventActionModifyVariableRebirth-ParseXmlAttribute 5, this.value: " + this.value);
}
return true;
}
if (localName == "seed_type")
{
this.seedType = EnumUtils.Parse<MinEventActionModifyVariableRebirth.SeedType>(_attribute.Value, true);
return true;
}
}
return flag;
}
private MinEventActionModifyVariableRebirth.SeedType seedType;
private MinEventActionModifyVariableRebirth.OperationTypes operation;
private float value;
private float minValue;
private float maxValue;
private int processAttribute = 1;
private int refVariable = 0;
private int setConstant = 0;
private bool cvarRef;
private int perkLevel = 0;
private int isPerc = 0;
private string refCvarName = string.Empty;
private MinEventActionModifyVariableRebirth.RandomRollTypes rollType;
private enum OperationTypes
{
set,
setvalue,
add,
subtract,
multiply,
divide
}
private enum SeedType
{
Item,
Player,
Random
}
private enum RandomRollTypes : byte
{
none,
randomInt,
randomFloat
}
}