using System.Globalization; using System.Xml.Linq; using UnityEngine.Scripting; [Preserve] public class MinEventActionModifyCVarRebirth : MinEventActionTargetedBase { public string cvarName { get; private set; } public override void Execute(MinEventParams _params) { //Log.Out("MinEventActionModifyCVarRebirth-Execute START"); if (_params.Self.isEntityRemote && !_params.IsLocal) { //Log.Out("MinEventActionModifyCVarRebirth-Execute 1"); return; } for (int i = 0; i < this.targets.Count; i++) { //Log.Out("MinEventActionModifyCVarRebirth-Execute 2"); if (this.cvarRef) { //Log.Out("MinEventActionModifyCVarRebirth-Execute 3 BEFORE this.value: " + this.value); this.value = this.targets[i].Buffs.GetCustomVar(this.refCvarName, 0f); //Log.Out("MinEventActionModifyCVarRebirth-Execute 3 AFTER this.value: " + this.value); } else if (this.rollType == MinEventActionModifyCVarRebirth.RandomRollTypes.randomInt) { //Log.Out("MinEventActionModifyCVarRebirth-Execute 4 BEFORE this.value: " + this.value); this.value = Mathf.Clamp((float)_params.Self.rand.RandomRange((int)this.minValue, (int)this.maxValue + 1), this.minValue, this.maxValue); //Log.Out("MinEventActionModifyCVarRebirth-Execute 4 AFTER this.value: " + this.value); } else if (this.rollType == MinEventActionModifyCVarRebirth.RandomRollTypes.randomFloat) { //Log.Out("MinEventActionModifyCVarRebirth-Execute 5 BEFORE this.value: " + this.value); this.value = Mathf.Clamp(_params.Self.rand.RandomRange(this.minValue, this.maxValue + 1f), this.minValue, this.maxValue); //Log.Out("MinEventActionModifyCVarRebirth-Execute 5 AFTER this.value: " + this.value); } float num = this.targets[i].Buffs.GetCustomVar(this.cvarName, 0f); switch (this.operation) { case MinEventActionModifyCVarRebirth.OperationTypes.set: case MinEventActionModifyCVarRebirth.OperationTypes.setvalue: num = this.value; //Log.Out("MinEventActionModifyCVarRebirth-Execute 6, num: " + num); break; case MinEventActionModifyCVarRebirth.OperationTypes.add: num += this.value; //Log.Out("MinEventActionModifyCVarRebirth-Execute 7, num: " + num); break; case MinEventActionModifyCVarRebirth.OperationTypes.subtract: num -= this.value; //Log.Out("MinEventActionModifyCVarRebirth-Execute 8, num: " + num); break; case MinEventActionModifyCVarRebirth.OperationTypes.multiply: num *= this.value; //Log.Out("MinEventActionModifyCVarRebirth-Execute 9, num: " + num); break; case MinEventActionModifyCVarRebirth.OperationTypes.divide: num /= ((this.value == 0f) ? 0.0001f : this.value); //Log.Out("MinEventActionModifyCVarRebirth-Execute 10, num: " + num); break; } //Log.Out("MinEventActionModifyCVarRebirth-Execute 11, num: " + num); this.targets[i].Buffs.SetCustomVar(this.cvarName, num, (this.targets[i].isEntityRemote && !_params.Self.isEntityRemote) || _params.IsLocal); } } 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(_attribute.Value, true); return true; } if (localName == "value") { this.rollType = MinEventActionModifyCVarRebirth.RandomRollTypes.none; this.cvarRef = false; if (_attribute.Value.StartsWith("randomint", StringComparison.OrdinalIgnoreCase)) { 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 = MinEventActionModifyCVarRebirth.RandomRollTypes.randomInt; } else if (_attribute.Value.StartsWith("randomfloat", StringComparison.OrdinalIgnoreCase)) { 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 = MinEventActionModifyCVarRebirth.RandomRollTypes.randomFloat; } else if (_attribute.Value.StartsWith("@")) { this.cvarRef = true; this.refCvarName = _attribute.Value.Substring(1); } else { this.value = StringParsers.ParseFloat(_attribute.Value, 0, -1, NumberStyles.Any); } return true; } if (localName == "seed_type") { this.seedType = EnumUtils.Parse(_attribute.Value, true); return true; } } return flag; } public override bool CanExecute(MinEventTypes _eventType, MinEventParams _params) { if (this.cvarName != null && this.cvarName.StartsWith("_")) { Log.Out("CVar '{0}' is readonly", new object[] { this.cvarName }); return false; } return base.CanExecute(_eventType, _params); } public float GetValueForDisplay() { if (this.operation == MinEventActionModifyCVarRebirth.OperationTypes.add) { return this.value; } if (this.operation == MinEventActionModifyCVarRebirth.OperationTypes.subtract) { return -this.value; } return 0f; } private MinEventActionModifyCVarRebirth.SeedType seedType; private MinEventActionModifyCVarRebirth.OperationTypes operation; private float value; private float minValue; private float maxValue; private bool cvarRef; private string refCvarName = string.Empty; private MinEventActionModifyCVarRebirth.RandomRollTypes rollType; private enum OperationTypes { set, setvalue, add, subtract, multiply, divide } private enum SeedType { Item, Player, Random } private enum RandomRollTypes : byte { none, randomInt, randomFloat } }