Ejemplo n.º 1
0
        protected SpellInabilityReason CanLaunchSpell(int spellId)
        {
            short spellLevel;

            try
            {
                spellLevel = Account.Character.Spells.First(s => s.SpellId == spellId).SpellLevel;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(SpellInabilityReason.UnknownSpell);
            }

            var spell           = ObjectDataManager.Instance.Get <API.Datacenter.Spell>(spellId);
            var id              = Convert.ToInt32(spell.SpellLevels[spellLevel - 1]);
            var spellLevelsData = ObjectDataManager.Instance.Get <SpellLevel>(id);

            if (spellLevelsData == null)
            {
                return(SpellInabilityReason.Unknown);
            }
            if (spellId != 0 && Fighter.ActionPoints < spellLevelsData.ApCost)
            {
                return(SpellInabilityReason.ActionPoints);
            }
            if (TotalLaunchBySpell.ContainsKey(spellId) &&
                TotalLaunchBySpell[spellId] >= spellLevelsData.MaxCastPerTurn && spellLevelsData.MaxCastPerTurn > 0)
            {
                return(SpellInabilityReason.TooManyLaunch);
            }
            lock (CheckLock)
            {
                if (LastTurnLaunchBySpell.ContainsKey(spellId))
                {
                    return(SpellInabilityReason.Cooldown);
                }
            }
            var listEffects = spellLevelsData.Effects;

            if (listEffects != null && listEffects.Count > 0 && listEffects[0].EffectId == 181)
            {
                var stats = Account.Character.Stats;
                var total = stats.SummonableCreaturesBoost.Base + stats.SummonableCreaturesBoost.ObjectsAndMountBonus +
                            stats.SummonableCreaturesBoost.AlignGiftBonus + stats.SummonableCreaturesBoost.ContextModif;
                if (GetInvokationNumber() >= total)
                {
                    return(SpellInabilityReason.TooManyInvocations);
                }
            }
            lock (CheckLock)
            {
                var listOfStates = spellLevelsData.StatesRequired;
                if (listOfStates.Any(state => !DurationByEffect.ContainsKey(state)))
                {
                    return(SpellInabilityReason.RequiredState);
                }
                listOfStates = spellLevelsData.StatesForbidden;
                if (listOfStates.Any(state => DurationByEffect.ContainsKey(state)))
                {
                    return(SpellInabilityReason.ForbiddenState);
                }
            }
            return(SpellInabilityReason.None);
        }
Ejemplo n.º 2
0
        private void HandleGameActionFightSpellCastMessage(IAccount account, GameActionFightSpellCastMessage message)
        {
            var fighter = (Fighter)GetFighter(message.SourceId);

            if (fighter == null || Fighter == null || fighter.Id != Fighter.Id)
            {
                return;
            }
            var spellLevel = -1;
            var spell      = Account.Character.Spells.FirstOrDefault(s => s.SpellId == message.SpellId);

            if (spell != null)
            {
                spellLevel = spell.SpellLevel;
            }

            if (spellLevel == -1)
            {
                return;
            }
            var spellData = ObjectDataManager.Instance.Get <API.Datacenter.Spell>(message.SpellId);

            if (spellData == null)
            {
                return;
            }
            var spellLevelId   = spellData.SpellLevels[spellLevel - 1];
            var spellLevelData = ObjectDataManager.Instance.Get <SpellLevel>(spellLevelId);

            if (spellLevelData == null)
            {
                return;
            }
            if (spellLevelData.MinCastInterval > 0 &&
                !LastTurnLaunchBySpell.ContainsKey(message.SpellId))
            {
                LastTurnLaunchBySpell.Add(message.SpellId, (int)spellLevelData.MinCastInterval);
            }

            if (TotalLaunchBySpell.ContainsKey(message.SpellId))
            {
                TotalLaunchBySpell[message.SpellId] += 1;
            }
            else
            {
                TotalLaunchBySpell.Add(message.SpellId, 1);
            }

            if (TotalLaunchByCellBySpell.ContainsKey(message.SpellId))
            {
                if (TotalLaunchByCellBySpell[message.SpellId].ContainsKey(message.DestinationCellId))
                {
                    TotalLaunchByCellBySpell[message.SpellId][message.DestinationCellId] += 1;
                }
                else
                {
                    TotalLaunchByCellBySpell[message.SpellId].Add(message.DestinationCellId, 1);
                }
            }
            else
            {
                var tempdico = new Dictionary <int, int> {
                    { message.DestinationCellId, 1 }
                };
                TotalLaunchByCellBySpell.Add(message.SpellId, tempdico);
            }
        }