private static void ProcessPCCustomEffects() { foreach (var player in NWModule.Get().Players) { if (!player.IsInitializedAsPlayer) { continue; // Ignored to prevent a timing issue where new characters would be included in this processing. } List <PCCustomEffect> effects = DataService.PCCustomEffect.GetAllByPlayerID(player.GlobalID).Where(x => x.StancePerkID == null).ToList(); foreach (var effect in effects) { if (player.CurrentHP <= -11) { CustomEffectService.RemovePCCustomEffect(player, effect.CustomEffectID); return; } PCCustomEffect result = RunPCCustomEffectProcess(player, effect); if (result == null) { ICustomEffectHandler handler = CustomEffectService.GetCustomEffectHandler(effect.CustomEffectID); string message = handler.WornOffMessage; player.SendMessage(message); player.DeleteLocalInt("CUSTOM_EFFECT_ACTIVE_" + effect.CustomEffectID); DataService.SubmitDataChange(effect, DatabaseActionType.Delete); handler.WearOff(null, player, effect.EffectiveLevel, effect.Data); } else { DataService.SubmitDataChange(effect, DatabaseActionType.Update); } } } }
public static bool RemoveStance(NWPlayer player, PCCustomEffect stanceEffect = null, bool sendMessage = true) { if (stanceEffect == null) { stanceEffect = DataService.SingleOrDefault <PCCustomEffect>(x => x.PlayerID == player.GlobalID && x.StancePerkID != null); } if (stanceEffect == null) { return(false); } if (sendMessage) { player.SendMessage("You return to your normal stance."); } int effectiveLevel = stanceEffect.EffectiveLevel; string data = stanceEffect.Data; DataService.SubmitDataChange(stanceEffect, DatabaseActionType.Delete); ICustomEffectHandler handler = GetCustomEffectHandler(stanceEffect.CustomEffectID); handler?.WearOff(player, player, effectiveLevel, data); return(true); }
public static bool RemoveStance(NWCreature creature, PCCustomEffect stanceEffect = null, bool sendMessage = true) { // Can't process NPC stances at the moment. Need to do some more refactoring before this is possible. // todo: handle NPC stances. if (!creature.IsPlayer) { return(false); } if (stanceEffect == null) { stanceEffect = DataService.PCCustomEffect.GetByPlayerStanceOrDefault(creature.GlobalID); } if (stanceEffect == null) { return(false); } if (sendMessage) { creature.SendMessage("You return to your normal stance."); } int effectiveLevel = stanceEffect.EffectiveLevel; string data = stanceEffect.Data; DataService.SubmitDataChange(stanceEffect, DatabaseActionType.Delete); ICustomEffectHandler handler = GetCustomEffectHandler(stanceEffect.CustomEffectID); handler?.WearOff(creature, creature, effectiveLevel, data); return(true); }
private static void ProcessNPCCustomEffects() { for (int index = AppCache.NPCEffects.Count - 1; index >= 0; index--) { var entry = AppCache.NPCEffects.ElementAt(index); CasterSpellVO casterModel = entry.Key; AppCache.NPCEffects[entry.Key] = entry.Value - 1; Data.Entity.CustomEffect entity = DataService.Single <Data.Entity.CustomEffect>(x => x.ID == casterModel.CustomEffectID); ICustomEffectHandler handler = CustomEffectService.GetCustomEffectHandler(casterModel.CustomEffectID); try { handler?.Tick(casterModel.Caster, casterModel.Target, AppCache.NPCEffects[entry.Key], casterModel.EffectiveLevel, casterModel.Data); } catch (Exception ex) { LoggingService.LogError(ex, "CustomEffectService processor was unable to run specific effect script for custom effect ID: " + entity.ID); } // 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) { handler?.WearOff(casterModel.Caster, casterModel.Target, casterModel.EffectiveLevel, casterModel.Data); 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); AppCache.NPCEffects.Remove(entry.Key); } } }