public override void RunAction() { var caster = Context.MaybeCaster; if (caster == null) { return; } var unit = Target.Unit; if (unit == null) { return; } var weapon = unit.GetThreatHand()?.Weapon; if (weapon == null) { return; } foreach (var enhance in Enchantments) { var fact = weapon.Enchantments.GetFact(enhance); if (fact != null && fact.IsTemporary) { weapon.RemoveEnchantment(fact); } } // Calculate that weapon's existing enhancement bonus. var rule = Context.TriggerRule(new RuleCalculateWeaponStats(unit, weapon)); // Greater Magic Weapon: // +1 enhancement per 4 caster levels. var casterLevel = Context.Params.CasterLevel; var bonus = Math.Min(Math.Max(1, casterLevel / 4), 5); var delta = bonus - rule.Enhancement; Log.Write($"{GetType().Name} existing bonus {rule.Enhancement} (partial enhancement {rule.EnhancementTotal}), target bonus: {bonus}"); if (delta > 0) { var enchant = Enchantments[delta - 1]; var rounds = DurationValue.Calculate(Context); Log.Write($"Add enchant {enchant} to {weapon} for {rounds} rounds."); weapon.AddEnchantment(enchant, Context, rounds); } }
void RemoveBuff() { if (!concentrating) { return; } concentrating = false; var duration = Duration != null?Duration.Calculate(Buff.Context).Seconds : new TimeSpan(); var remaining = duration.TotalMilliseconds == 0 ? "now" : "in " + BlueprintRoot.Instance.Calendar.GetCompactPeriodString(duration); Helpers.GameLog.AddLogEntry( $"Not concentrating on {Buff.Name}, ends {remaining}.", GameLogStrings.Instance.InitiativeRoll.Color, LogChannel.Combat); Buff.RemoveAfterDelay(duration); }
public override void OnEventDidTrigger(RuleSummonUnit evt) { if (spellbook != null && evt.Context?.SourceAbilityContext?.Ability?.Spellbook?.Blueprint != spellbook) { return; } if (spell_descriptor != SpellDescriptor.None && (evt.Context.SpellDescriptor & spell_descriptor) != 0) { return; } if (school != SpellSchool.None && school != evt.Context.SpellSchool) { return; } Main.logger.Log("Spawn ok"); TimeSpan?duration = !this.IsInfinity ? new TimeSpan?(duration_value.Calculate(this.Fact.MaybeContext).Seconds) : new TimeSpan?(); evt.SummonedUnit.Descriptor.AddBuff(this.buff, evt.Initiator, duration, (AbilityParams)null); }