Exemplo n.º 1
0
 public override void Combine(ComplexTemplParam param, out ComplexTemplParam current)
 {
     if (param is ModifierTemplParam)
     {
         ModifierTemplParam other = param as ModifierTemplParam;
         Attributes |= other.Attributes;
         current     = this;
     }
     else
     {
         base.Combine(param, out current);
     }
 }
Exemplo n.º 2
0
        protected void OutputForStatusEffect(StatusEffectAttributes statusEffect)
        {
            Print($"lifetime: {statusEffect.Lifetime}");
            Print($"duration: {statusEffect.Duration}");
            Print($"stackingBehaviour: {statusEffect.StackingBehaviour}");
            Print($"maxStacks: {statusEffect.MaxStacks}");
            Print($"weaponFireTriggerEndEvent: {statusEffect.WeaponFireTriggerEndEvent}");

            if (statusEffect.UnitTypeBuffsToApply.Length > 0)
            {
                using (BeginScope("unitTypeBuffs"))
                {
                    for (int i = 0; i < statusEffect.UnitTypeBuffsToApply.Length; ++i)
                    {
                        OutputForUnitTypeBuff(statusEffect.UnitTypeBuffsToApply[i]);
                    }
                }
            }

            if (statusEffect.BuffsToApplyToTarget.Length > 0)
            {
                using (BeginScope("buffsToApplyToTarget"))
                {
                    for (int i = 0; i < statusEffect.BuffsToApplyToTarget.Length; ++i)
                    {
                        OutputForUnitTypeBuff(statusEffect.BuffsToApplyToTarget[i]);
                    }
                }
            }

            if (statusEffect.Modifiers.Length > 0)
            {
                using (BeginScope("modifiers"))
                {
                    for (int i = 0; i < statusEffect.Modifiers.Length; ++i)
                    {
                        ModifierAttributes modifier = statusEffect.Modifiers[i];
                        using (BeginScope())
                        {
                            Print($"modifierType: {modifier.ModifierType}");
                            switch (modifier.ModifierType)
                            {
                            case ModifierType.EnableWeapon:
                                Print($"weaponID: {modifier.EnableWeaponAttributes.WeaponID}");
                                break;

                            case ModifierType.SwapWeapons:
                                Print($"swapFromWeaponID: {modifier.SwapWeaponAttributes.SwapFromWeaponID}");
                                Print($"swapToWeaponID: {modifier.SwapWeaponAttributes.SwapToWeaponID}");
                                break;

                            case ModifierType.HealthOverTime:
                                Print($"id: {modifier.HealthOverTimeAttributes.ID}");
                                Print($"tickDurationMS: {modifier.HealthOverTimeAttributes.MSTickDuration}");
                                Print($"damageType: {modifier.HealthOverTimeAttributes.DamageType}");
                                Print($"amount: {modifier.HealthOverTimeAttributes.Amount}");
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
        }
        protected override void Apply(AttributeLoader loader, object wrapperbj)
        {
            if (!(wrapperbj is StatusEffectAttributesWrapper w))
            {
                throw new System.InvalidCastException();
            }

            loader.ApplyPPatch(Duration, () => w.Duration, Fixed64.UnsafeFromDouble);
            loader.ApplyPMultPatch(DurationMult, () => w.Duration);

            loader.ApplyPPatch(MaxStacks, () => w.MaxStacks);
            loader.ApplyPMultPatch(MaxStacksMult, () => w.MaxStacks);

            loader.ApplyPPatch(Lifetime, () => w.Lifetime);
            loader.ApplyPPatch(WeaponFireTriggerEndEvent, () => w.WeaponFireTriggerEndEvent);
            loader.ApplyPPatch(StackingBehaviour, () => w.StackingBehaviour);

            if (BuffsToApplyToTarget != null)
            {
                var l = w.BuffsToApplyToTarget?.Select(x => new UnitTypeBuffWrapper(x)).ToList() ?? new List <UnitTypeBuffWrapper>();
                loader.ApplyLPatch(BuffsToApplyToTarget, l, () => new UnitTypeBuffWrapper(), "BuffsToApplyToTarget");
                w.BuffsToApplyToTarget = l.ToArray();
            }

            if (UnitTypeBuffsToApply != null)
            {
                var l = w.UnitTypeBuffsToApply?.Select(x => new UnitTypeBuffWrapper(x)).ToList() ?? new List <UnitTypeBuffWrapper>();
                loader.ApplyLPatch(UnitTypeBuffsToApply, l, () => new UnitTypeBuffWrapper(), "UnitTypeBuffsToApply");
                w.UnitTypeBuffsToApply = l.ToArray();
            }

            if (Modifiers != null)
            {
                var wrapperModifiers = w.Modifiers?.ToList() ?? new List <ModifierAttributes>();

                var parsed = new Dictionary <int, ModifierAttributesPatch>();

                foreach (var kvp in Modifiers)
                {
                    if (!int.TryParse(kvp.Key, out var index))
                    {
                        loader.logger.Log($"ERROR: Non-integer key: {kvp.Key}");
                        break;
                    }

                    parsed[index] = kvp.Value;
                }

                var toRemove = new Stack <int>();

                foreach (var kvp in parsed.OrderBy(p => p.Key))
                {
                    var index        = kvp.Key;
                    var elementPatch = kvp.Value;

                    using (loader.logger.BeginScope($"Modifiers: {index}"))
                    {
                        var remove = elementPatch.Remove;

                        ModifierAttributes newValue;

                        if (index < wrapperModifiers.Count())
                        {
                            if (remove)
                            {
                                loader.logger.Log("(removed)");
                                toRemove.Push(index);
                                continue;
                            }

                            newValue = wrapperModifiers[index];
                        }
                        else if (index >= wrapperModifiers.Count())
                        {
                            if (remove)
                            {
                                loader.logger.Log("WARNING: Remove flag set for non-existent entry");
                                continue;
                            }

                            loader.logger.BeginScope("(created)").Dispose();

                            newValue = new ModifierAttributes();
                        }
                        else                         // if (index > wrapperModifiers.Count)
                        {
                            loader.logger.Log("ERROR: Non-consecutive index");
                            continue;
                        }

                        loader.ApplyPRefPatch(elementPatch.ModifierType, ref newValue.ModifierType, "ModifierType");
                        loader.ApplyPRefPatch(elementPatch.EnableWeapon_WeaponID, ref newValue.EnableWeaponAttributes.WeaponID, "EnableWeapon_WeaponID");
                        loader.ApplyPRefPatch(elementPatch.SwapFromWeaponID, ref newValue.SwapWeaponAttributes.SwapFromWeaponID, "SwapFromWeaponID");
                        loader.ApplyPRefPatch(elementPatch.SwapToWeaponID, ref newValue.SwapWeaponAttributes.SwapToWeaponID, "SwapToWeaponID");

                        if (elementPatch.HealthOverTimeAttributes != null)
                        {
                            using (loader.logger.BeginScope("HealthOverTimeAttributes:"))
                            {
                                loader.ApplyPRefPatch(elementPatch.HealthOverTimeAttributes.ID, ref newValue.HealthOverTimeAttributes.ID, "ID");
                                loader.ApplyPRefPatch(elementPatch.HealthOverTimeAttributes.Amount, ref newValue.HealthOverTimeAttributes.Amount, "Amount");
                                loader.ApplyPRefPatch(elementPatch.HealthOverTimeAttributes.MSTickDuration, ref newValue.HealthOverTimeAttributes.MSTickDuration, "MSTickDuration");
                                loader.ApplyPRefPatch(elementPatch.HealthOverTimeAttributes.DamageType, ref newValue.HealthOverTimeAttributes.DamageType, "DamageType");
                            }
                        }

                        if (index < wrapperModifiers.Count)
                        {
                            wrapperModifiers[index] = newValue;
                        }
                        else
                        {
                            wrapperModifiers.Add(newValue);
                        }
                    }
                }

                foreach (var v in toRemove)
                {
                    wrapperModifiers.RemoveAt(v);
                }

                w.Modifiers = wrapperModifiers.ToArray();
            }
        }
Exemplo n.º 4
0
 public override void Combine(ComplexTemplParam param, out ComplexTemplParam current)
 {
     if (param is ModifierTemplParam)
     {
         ModifierTemplParam other = param as ModifierTemplParam;
         Attributes |= other.Attributes;
         current = this;
     }
     else
     {
         base.Combine(param, out current);
     }
 }