Ejemplo n.º 1
0
        public static void ApplyStance(NWCreature creature, CustomEffectType customEffect, PerkType perkType, int effectiveLevel, string data)
        {
            // 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;
            }

            var pcStanceEffect = DataService.PCCustomEffect.GetByPlayerStanceOrDefault(creature.GlobalID);
            int customEffectID = (int)customEffect;

            // Player selected to cancel their stance. Cancel it and end.
            if (pcStanceEffect != null && pcStanceEffect.CustomEffectID == customEffectID && pcStanceEffect.EffectiveLevel == effectiveLevel)
            {
                RemoveStance(creature, pcStanceEffect);
                return;
            }
            // Otherwise remove existing stance
            else if (pcStanceEffect != null)
            {
                RemoveStance(creature, pcStanceEffect, false);
            }

            // Player selected to switch stances
            pcStanceEffect = new PCCustomEffect
            {
                PlayerID          = creature.GlobalID,
                Ticks             = -1,
                CustomEffectID    = customEffectID,
                CasterNWNObjectID = _.ObjectToString(creature),
                EffectiveLevel    = effectiveLevel,
                StancePerkID      = (int)perkType
            };
            DataService.SubmitDataChange(pcStanceEffect, DatabaseActionType.Insert);
            ICustomEffectHandler handler = GetCustomEffectHandler(customEffect);

            if (string.IsNullOrWhiteSpace(data))
            {
                data = handler.Apply(creature, creature, effectiveLevel);
            }

            if (!string.IsNullOrWhiteSpace(handler.StartMessage))
            {
                creature.SendMessage(handler.StartMessage);
            }

            if (string.IsNullOrWhiteSpace(data))
            {
                data = string.Empty;
            }
            pcStanceEffect.Data = data;
            DataService.SubmitDataChange(pcStanceEffect, DatabaseActionType.Update);

            // Was already queued for removal, but got cast again. Take it out of the list to be removed.
            if (AppCache.PCEffectsForRemoval.Contains(pcStanceEffect.ID))
            {
                AppCache.PCEffectsForRemoval.Remove(pcStanceEffect.ID);
            }
        }
Ejemplo n.º 2
0
        public static void ApplyStance(NWPlayer player, CustomEffectType customEffect, PerkType perkType, int effectiveLevel, string data)
        {
            var pcStanceEffect = DataService.SingleOrDefault <PCCustomEffect>(x => x.PlayerID == player.GlobalID &&
                                                                              x.StancePerkID != null);
            int customEffectID = (int)customEffect;

            // Player selected to cancel their stance. Cancel it and end.
            if (pcStanceEffect != null && pcStanceEffect.CustomEffectID == customEffectID && pcStanceEffect.EffectiveLevel == effectiveLevel)
            {
                RemoveStance(player, pcStanceEffect);
                return;
            }
            // Otherwise remove existing stance
            else if (pcStanceEffect != null)
            {
                RemoveStance(player, pcStanceEffect, false);
            }

            // Player selected to switch stances
            pcStanceEffect = new PCCustomEffect
            {
                PlayerID          = player.GlobalID,
                Ticks             = -1,
                CustomEffectID    = customEffectID,
                CasterNWNObjectID = _.ObjectToString(player),
                EffectiveLevel    = effectiveLevel,
                StancePerkID      = (int)perkType
            };
            DataService.SubmitDataChange(pcStanceEffect, DatabaseActionType.Insert);
            ICustomEffectHandler handler = GetCustomEffectHandler(customEffect);

            if (string.IsNullOrWhiteSpace(data))
            {
                data = handler.Apply(player, player, effectiveLevel);
            }

            if (!string.IsNullOrWhiteSpace(handler.StartMessage))
            {
                player.SendMessage(handler.StartMessage);
            }

            if (string.IsNullOrWhiteSpace(data))
            {
                data = string.Empty;
            }
            pcStanceEffect.Data = data;
            DataService.SubmitDataChange(pcStanceEffect, DatabaseActionType.Update);

            // Was already queued for removal, but got cast again. Take it out of the list to be removed.
            if (AppCache.PCEffectsForRemoval.Contains(pcStanceEffect.ID))
            {
                AppCache.PCEffectsForRemoval.Remove(pcStanceEffect.ID);
            }
        }
Ejemplo n.º 3
0
        private static void OnModuleEnter()
        {
            NWPlayer player = _.GetEnteringObject();

            if (!player.IsPlayer)
            {
                return;
            }

            var pcEffect = DataService.PCCustomEffect.GetByPlayerStanceOrDefault(player.GlobalID);

            if (pcEffect?.StancePerkID == null)
            {
                return;
            }
            ICustomEffectHandler handler = GetCustomEffectHandler(pcEffect.CustomEffectID);

            handler?.Apply(player, player, pcEffect.EffectiveLevel);
        }
Ejemplo n.º 4
0
        private static void ApplyNPCEffect(NWCreature caster, NWCreature target, int customEffectID, int ticks, int effectiveLevel, string data)
        {
            Data.Entity.CustomEffect effectEntity = DataService.Single <Data.Entity.CustomEffect>(x => x.ID == customEffectID);
            // Look for existing effect.
            var spellModel = AppCache.NPCEffects.SingleOrDefault(x => x.Key.Caster.Equals(caster) &&
                                                                 x.Key.CustomEffectID == customEffectID &&
                                                                 x.Key.Target.Equals(target)).Key;

            if (spellModel == null)
            {
                spellModel = new CasterSpellVO
                {
                    Caster         = caster,
                    CustomEffectID = customEffectID,
                    EffectName     = effectEntity.Name,
                    Target         = target,
                    EffectiveLevel = effectiveLevel
                };

                AppCache.NPCEffects.Add(spellModel, 0);
            }

            if (spellModel.EffectiveLevel > effectiveLevel)
            {
                caster.SendMessage("A more powerful effect already exists on your target.");
                return;
            }
            ICustomEffectHandler handler = GetCustomEffectHandler(customEffectID);

            if (string.IsNullOrWhiteSpace(data))
            {
                data = handler?.Apply(caster, target, effectiveLevel);
            }
            if (string.IsNullOrWhiteSpace(data))
            {
                data = string.Empty;
            }
            spellModel.Data = data;

            AppCache.NPCEffects[spellModel] = ticks;
        }
Ejemplo n.º 5
0
        private static void ApplyPCEffect(NWCreature caster, NWCreature target, int customEffectID, int ticks, int effectiveLevel, string data)
        {
            Data.Entity.CustomEffect customEffect = DataService.Single <Data.Entity.CustomEffect>(x => x.ID == customEffectID);
            PCCustomEffect           pcEffect     = DataService.SingleOrDefault <PCCustomEffect>(x => x.PlayerID == target.GlobalID && x.CustomEffectID == customEffectID);
            ICustomEffectHandler     handler      = GetCustomEffectHandler(customEffectID);
            CustomEffectCategoryType category     = handler.CustomEffectCategoryType;

            if (category == CustomEffectCategoryType.FoodEffect)
            {
                var customEffectPC = DataService.Get <Data.Entity.CustomEffect>(pcEffect.CustomEffectID);
                if (customEffectPC != null)
                {
                    var foodHandler = GetCustomEffectHandler(customEffectPC.ID);
                    if (foodHandler.CustomEffectCategoryType == category)
                    {
                        caster.SendMessage("You are not hungry.");
                    }
                    return;
                }
            }

            DatabaseActionType action = DatabaseActionType.Update;

            if (pcEffect == null)
            {
                pcEffect = new PCCustomEffect {
                    PlayerID = target.GlobalID
                };
                action = DatabaseActionType.Insert;
            }

            if (pcEffect.EffectiveLevel > effectiveLevel)
            {
                caster.SendMessage("A more powerful effect already exists on your target.");
                return;
            }

            pcEffect.CustomEffectID    = customEffectID;
            pcEffect.EffectiveLevel    = effectiveLevel;
            pcEffect.Ticks             = ticks;
            pcEffect.CasterNWNObjectID = _.ObjectToString(caster);
            DataService.SubmitDataChange(pcEffect, action);

            target.SendMessage(handler.StartMessage);
            if (string.IsNullOrWhiteSpace(data))
            {
                data = handler?.Apply(caster, target, effectiveLevel);
            }

            if (string.IsNullOrWhiteSpace(data))
            {
                data = string.Empty;
            }
            pcEffect.Data = data;
            DataService.SubmitDataChange(pcEffect, DatabaseActionType.Update);

            // Was already queued for removal, but got cast again. Take it out of the list to be removed.
            if (AppCache.PCEffectsForRemoval.Contains(pcEffect.ID))
            {
                AppCache.PCEffectsForRemoval.Remove(pcEffect.ID);
            }
        }