public void OnPlayerHeartbeat(NWPlayer oPC) { List <PCCustomEffect> effects = _db.PCCustomEffects.Where(x => x.PlayerID == oPC.GlobalID).ToList(); string areaResref = oPC.Area.Resref; foreach (PCCustomEffect effect in effects) { if (oPC.CurrentHP <= -11 || areaResref == "death_realm") { RemovePCCustomEffect(oPC, effect.CustomEffectID); return; } PCCustomEffect result = RunPCCustomEffectProcess(oPC, effect); if (result == null) { string message = effect.CustomEffect.WornOffMessage; string scriptHandler = effect.CustomEffect.ScriptHandler; oPC.SendMessage(message); oPC.DeleteLocalInt("CUSTOM_EFFECT_ACTIVE_" + effect.CustomEffectID); _db.PCCustomEffects.Remove(effect); _db.SaveChanges(); ICustomEffect handler = App.ResolveByInterface <ICustomEffect>("CustomEffect." + scriptHandler); handler?.WearOff(null, oPC); } else { _db.SaveChanges(); } } }
public void OnModuleHeartbeat() { foreach (var entry in _state.NPCEffects) { CasterSpellVO casterModel = entry.Key; _state.NPCEffects[entry.Key] = entry.Value - 1; Data.Entities.CustomEffect entity = _db.CustomEffects.Single(x => x.CustomEffectID == casterModel.CustomEffectID); ICustomEffect handler = App.ResolveByInterface <ICustomEffect>("CustomEffect." + entity.ScriptHandler); try { handler?.Tick(casterModel.Caster, casterModel.Target); } catch (Exception ex) { _error.LogError(ex, "OnModuleHeartbeat was unable to run specific effect script: " + entity.ScriptHandler); } // Kill the effect if it has expired, target is invalid, or target is dead. if (entry.Value <= 0 || !casterModel.Target.IsValid || casterModel.Target.CurrentHP <= -11) { _state.EffectsToRemove.Add(entry.Key); handler?.WearOff(casterModel.Caster, casterModel.Target); if (casterModel.Caster.IsValid && casterModel.Caster.IsPlayer) { casterModel.Caster.SendMessage("Your effect '" + casterModel.EffectName + "' has worn off of " + casterModel.Target.Name); } casterModel.Target.DeleteLocalInt("CUSTOM_EFFECT_ACTIVE_" + casterModel.CustomEffectID); } } foreach (CasterSpellVO entry in _state.EffectsToRemove) { _state.NPCEffects.Remove(entry); } _state.EffectsToRemove.Clear(); }