Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
        private PCCustomEffect RunPCCustomEffectProcess(NWPlayer oPC, PCCustomEffect effect)
        {
            effect.Ticks = effect.Ticks - 1;
            if (effect.Ticks < 0)
            {
                return(null);
            }

            if (!string.IsNullOrWhiteSpace(effect.CustomEffect.ContinueMessage))
            {
                oPC.SendMessage(effect.CustomEffect.ContinueMessage);
            }

            ICustomEffect handler = App.ResolveByInterface <ICustomEffect>("CustomEffect." + effect.CustomEffect.ScriptHandler);

            handler?.Tick(null, oPC);

            return(effect);
        }
Exemplo n.º 3
0
        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();
        }
        public void UpdateColors()
        {
            if (UserSettings.Settings.ActiveDevice == null || _polygons == null)
            {
                return;
            }

            //Run code on main thread since we update the UI
            Dispatcher.Invoke(new Action(() =>
            {
                var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice);

                //Get colors of current effect, we can display colors for nanoleaf effects or custom color effects
                var effectName = orchestrator.GetActiveEffectName();

                ICustomEffect customEffect = null;

                if (effectName != null)
                {
                    customEffect = orchestrator.GetCustomEffectFromName(effectName);
                }

                List <SolidColorBrush> colors = null;

                if (customEffect != null)
                {
                    if (customEffect is CustomColorEffect customColorEffect)
                    {
                        colors = new List <SolidColorBrush>()
                        {
                            new SolidColorBrush(Color.FromArgb(customColorEffect.Color.A, customColorEffect.Color.R, customColorEffect.Color.G, customColorEffect.Color.B))
                        };
                    }
                }
                else
                {
                    var effect = UserSettings.Settings.ActiveDevice.Effects.FirstOrDefault(effect => effect.Name == effectName);

                    //Only retrieve palette if it is not known yet
                    if (effect?.Palette == null)
                    {
                        var client = NanoleafClient.GetClientForDevice(UserSettings.Settings.ActiveDevice);
                        effect     = client.EffectsEndpoint.GetEffectDetails(effectName);

                        if (effect != null)
                        {
                            //Update the effect such that the palette is known in the future
                            UserSettings.Settings.ActiveDevice.UpdateEffect(effect);
                        }
                    }

                    if (effect != null)
                    {
                        colors = effect.Palette.Select(hsb =>
                                                       new SolidColorBrush(
                                                           HsbToRgbConverter.ConvertToMediaColor(hsb.Hue, hsb.Saturation, hsb.Brightness)
                                                           )).ToList();
                    }
                }

                if (colors == null)
                {
                    foreach (var polygon in _polygons)
                    {
                        polygon.Polygon.Fill = Brushes.LightSlateGray;
                    }
                }
                else
                {
                    foreach (var polygon in _polygons)
                    {
                        polygon.Polygon.Fill = colors[_random.Next(colors.Count)];
                    }
                }
            }));
        }
Exemplo n.º 5
0
        public void ApplyCustomEffect(NWCreature oCaster, NWCreature oTarget, int customEffectID, int ticks, int effectLevel)
        {
            // Can't apply the effect if the existing one is stronger.
            int existingEffectLevel = GetActiveEffectLevel(oTarget, customEffectID);

            if (existingEffectLevel > effectLevel)
            {
                oCaster.SendMessage("A more powerful effect already exists on your target.");
                return;
            }

            Data.Entities.CustomEffect effectEntity = _db.CustomEffects.Single(x => x.CustomEffectID == customEffectID);

            // PC custom effects are tracked in the database.
            if (oTarget.IsPlayer)
            {
                PCCustomEffect entity = _db.PCCustomEffects.SingleOrDefault(x => x.PlayerID == oTarget.GlobalID && x.CustomEffectID == customEffectID);

                if (entity == null)
                {
                    entity = new PCCustomEffect
                    {
                        PlayerID       = oTarget.GlobalID,
                        CustomEffectID = customEffectID
                    };

                    _db.PCCustomEffects.Add(entity);
                }

                entity.Ticks = ticks;
                _db.SaveChanges();

                oTarget.SendMessage(effectEntity.StartMessage);
            }
            // NPCs custom effects are tracked in server memory.
            else
            {
                // Look for existing effect.
                foreach (var entry in _state.NPCEffects)
                {
                    CasterSpellVO casterSpellModel = entry.Key;

                    if (casterSpellModel.Caster.Equals(oCaster) &&
                        casterSpellModel.CustomEffectID == customEffectID &&
                        casterSpellModel.Target.Equals(oTarget))
                    {
                        _state.NPCEffects[entry.Key] = ticks;
                        return;
                    }
                }

                // Didn't find an existing effect. Create a new one.
                CasterSpellVO spellModel = new CasterSpellVO
                {
                    Caster         = oCaster,
                    CustomEffectID = customEffectID,
                    EffectName     = effectEntity.Name,
                    Target         = oTarget
                };

                _state.NPCEffects[spellModel] = ticks;
            }

            ICustomEffect handler = App.ResolveByInterface <ICustomEffect>("CustomEffect." + effectEntity.ScriptHandler);

            handler?.Apply(oCaster, oTarget);
            oTarget.SetLocalInt("CUSTOM_EFFECT_ACTIVE_" + customEffectID, effectLevel);
        }
 public void addICustomEffect(ICustomEffect effect)
 {
     Add(new DelegatingEffect(effect));
     lElement.Add(effect);
 }