예제 #1
0
        public int GetCustomEffectLevel(NWCreature creature, CustomEffectType customEffectType)
        {
            int effectLevel = 0;

            if (creature.IsNPC)
            {
                var effect = _cache.NPCEffects.SingleOrDefault(x => x.Key.Target.Equals(creature) && x.Key.CustomEffectID == (int)customEffectType);

                if (effect.Key != null)
                {
                    effectLevel = effect.Key.EffectiveLevel;
                }
            }
            else if (creature.IsPlayer)
            {
                PCCustomEffect dbEffect = _data.SingleOrDefault <PCCustomEffect>(x => x.PlayerID == creature.GlobalID && x.CustomEffectID == (int)customEffectType);
                if (dbEffect != null)
                {
                    if (!_cache.PCEffectsForRemoval.Contains(dbEffect.ID))
                    {
                        effectLevel = dbEffect.EffectiveLevel;
                    }
                }
            }
            else
            {
                return(0);
            }
            return(effectLevel);
        }
예제 #2
0
        private void HandleStances()
        {
            DamageData data          = _nwnxDamage.GetDamageEventData();
            NWPlayer   damager       = data.Damager.Object;
            NWItem     damagerWeapon = _.GetLastWeaponUsed(damager);

            if (damager.IsPlayer)
            {
                CustomEffectType stance = _customEffect.GetCurrentStanceType(damager);

                switch (stance)
                {
                case CustomEffectType.ShieldOath:
                    data.AdjustAllByPercent(-0.30f);
                    break;

                case CustomEffectType.PrecisionTargeting:

                    if (damagerWeapon.CustomItemType == CustomItemType.BlasterPistol ||
                        damagerWeapon.CustomItemType == CustomItemType.BlasterRifle)
                    {
                        data.AdjustAllByPercent(0.20f);
                    }
                    break;
                }
            }

            _nwnxDamage.SetDamageEventData(data);
        }
예제 #3
0
        public static int GetCustomEffectLevel(NWCreature creature, CustomEffectType customEffectType)
        {
            int effectLevel = 0;

            if (creature.IsNPC)
            {
                var effect = AppCache.NPCEffects.SingleOrDefault(x => x.Key.Target.Equals(creature) && x.Key.CustomEffectID == (int)customEffectType);

                if (effect.Key != null)
                {
                    effectLevel = effect.Key.EffectiveLevel;
                }
            }
            else if (creature.IsPlayer)
            {
                PCCustomEffect dbEffect = DataService.PCCustomEffect.GetByPlayerIDAndCustomEffectIDOrDefault(creature.GlobalID, (int)customEffectType);
                if (dbEffect != null)
                {
                    if (!AppCache.PCEffectsForRemoval.Contains(dbEffect.ID))
                    {
                        effectLevel = dbEffect.EffectiveLevel;
                    }
                }
            }
            else
            {
                return(0);
            }
            return(effectLevel);
        }
예제 #4
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);
            }
        }
예제 #5
0
        private void HandleStances()
        {
            DamageData data          = _nwnxDamage.GetDamageEventData();
            NWPlayer   damager       = data.Damager.Object;
            NWPlayer   receiver      = Object.OBJECT_SELF;
            NWItem     damagerWeapon = _.GetLastWeaponUsed(damager);

            if (damager.IsPlayer)
            {
                CustomEffectType stance = _customEffect.GetCurrentStanceType(damager);

                switch (stance)
                {
                case CustomEffectType.ShieldOath:
                    data.AdjustAllByPercent(-0.30f);
                    break;

                case CustomEffectType.SwordOath:

                    if (_item.MeleeWeaponTypes.Contains(damagerWeapon.BaseItemType))
                    {
                        data.AdjustAllByPercent(0.20f);
                    }
                    break;
                }
            }

            if (receiver.IsPlayer)
            {
                CustomEffectType stance = _customEffect.GetCurrentStanceType(receiver);
            }

            _nwnxDamage.SetDamageEventData(data);
        }
예제 #6
0
        public static ICustomEffectHandler GetCustomEffectHandler(CustomEffectType type)
        {
            if (!_customEffectHandlers.ContainsKey(type))
            {
                throw new Exception("Unable to locate a ICustomEffectBehavior implementation for type " + type);
            }

            return(_customEffectHandlers[type]);
        }
예제 #7
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);
            }
        }
예제 #8
0
 public void RemovePCCustomEffect(NWPlayer oPC, CustomEffectType customEffectType)
 {
     RemovePCCustomEffect(oPC, (int)customEffectType);
 }
예제 #9
0
 public bool DoesPCHaveCustomEffect(NWPlayer oPC, CustomEffectType customEffectType)
 {
     return(DoesPCHaveCustomEffect(oPC, (int)customEffectType));
 }
예제 #10
0
 public void ApplyCustomEffect(NWCreature caster, NWCreature target, CustomEffectType effectType, int ticks, int level, string data)
 {
     ApplyCustomEffect(caster, target, (int)effectType, ticks, level, data);
 }
예제 #11
0
        public void ApplyStance(NWPlayer player, CustomEffectType customEffect, PerkType perkType, int effectiveLevel, string data)
        {
            var dbEffect       = _data.Single <Data.Entity.CustomEffect>(x => x.ID == (int)customEffect);
            var pcStanceEffect = _data.SingleOrDefault <PCCustomEffect>(x =>
            {
                var ce = _data.Get <Data.Entity.CustomEffect>(x.CustomEffectID);
                return(x.PlayerID == player.GlobalID &&
                       ce.CustomEffectCategoryID == (int)CustomEffectCategoryType.Stance);
            });
            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
            };
            _data.SubmitDataChange(pcStanceEffect, DatabaseActionType.Insert);

            App.ResolveByInterface <ICustomEffect>("CustomEffect." + dbEffect.ScriptHandler, handler =>
            {
                if (string.IsNullOrWhiteSpace(data))
                {
                    data = handler?.Apply(player, player, effectiveLevel);
                }

                var stanceCustomEffect = _data.Get <Data.Entity.CustomEffect>(pcStanceEffect.CustomEffectID);
                if (!string.IsNullOrWhiteSpace(stanceCustomEffect.StartMessage))
                {
                    player.SendMessage(stanceCustomEffect.StartMessage);
                }

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

                // Was already queued for removal, but got cast again. Take it out of the list to be removed.
                if (_cache.PCEffectsForRemoval.Contains(pcStanceEffect.ID))
                {
                    _cache.PCEffectsForRemoval.Remove(pcStanceEffect.ID);
                }
            });
        }
예제 #12
0
 public int GetActiveEffectLevel(NWObject target, CustomEffectType effectType)
 {
     return(GetActiveEffectLevel(target, (int)effectType));
 }
예제 #13
0
        public static ICustomEffectHandler GetCustomEffectHandler(int typeID)
        {
            CustomEffectType type = (CustomEffectType)typeID;

            return(GetCustomEffectHandler(type));
        }