Ejemplo n.º 1
0
        protected SpellInabilityReason CanLaunchSpellOn(int spellId, int characterCellId, int cellId,
                                                        bool withMove = false)
        {
            if (!withMove)
            {
                var canLaunchSpell = CanLaunchSpell(spellId);
                if (canLaunchSpell != SpellInabilityReason.None)
                {
                    return(canLaunchSpell);
                }
            }
            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>(/*spellId */ id);

            if (spellLevelsData == null)
            {
                return(SpellInabilityReason.Unknown);
            }
            if (spellId == 0)
            {
                return(SpellInabilityReason.UnknownSpell);
            }
            var characterPoint   = new MapPoint(characterCellId);
            var targetPoint      = new MapPoint(cellId);
            var distanceToTarget = characterPoint.DistanceToCell(targetPoint);
            var minRange         = spellLevelsData.MinRange;

            if (spellId != 0 && spellLevelsData.CastInDiagonal)
            {
                minRange = minRange * 2;
            }
            if (minRange < 0)
            {
                minRange = 0;
            }
            var maxRange = spellId != 0
                ? spellLevelsData.Range + (spellLevelsData.RangeCanBeBoosted
                      ? Account.Character.Stats.Range.ObjectsAndMountBonus
                      : 0)
                : spellLevelsData.Range;

            if (spellId != 0 && spellLevelsData.CastInDiagonal)
            {
                maxRange = maxRange * 2;
            }
            if (maxRange < 0)
            {
                maxRange = 0;
            }
            if (distanceToTarget < minRange)
            {
                return(SpellInabilityReason.MinRange);
            }
            if (distanceToTarget > maxRange)
            {
                return(SpellInabilityReason.MaxRange);
            }
            if (spellId != 0 && spellLevelsData.CastInLine &&
                characterPoint.X != targetPoint.X &&
                characterPoint.Y != targetPoint.Y)
            {
                return(SpellInabilityReason.NotInLine);
            }
            if (spellId != 0 && spellLevelsData.CastInDiagonal)
            {
                var list = Dofus1Line.GetLine(characterPoint.X, characterPoint.Y, targetPoint.X, targetPoint.Y);
                var i    = 0;
                while (i < list.Count - 1)
                {
                    var actualPoint = (Dofus1Line.Point)list[i];
                    var nextPoint   = (Dofus1Line.Point)list[i + 1];
                    i += 1;
                    if (actualPoint.X == nextPoint.X + 1 && actualPoint.Y == nextPoint.Y + 1)
                    {
                        continue;
                    }
                    if (actualPoint.X == nextPoint.X - 1 && actualPoint.Y == nextPoint.Y - 1)
                    {
                        continue;
                    }
                    if (actualPoint.X == nextPoint.X + 1 && actualPoint.Y == nextPoint.Y - 1)
                    {
                        continue;
                    }
                    if (actualPoint.X == nextPoint.X - 1 && actualPoint.Y == nextPoint.Y + 1)
                    {
                        continue;
                    }
                    return(SpellInabilityReason.NotInDiagonal);
                }
            }
            if (spellId != 0 && spellLevelsData.CastTestLos && distanceToTarget > 1)
            {
                var list = Dofus1Line.GetLine(characterPoint.X, characterPoint.Y, targetPoint.X, targetPoint.Y);
                var i    = 0;
                while (i < list.Count - 1)
                {
                    var point3 = (Dofus1Line.Point)list[i];
                    var point4 = new MapPoint((int)Math.Round(Math.Floor(point3.X)),
                                              (int)Math.Round(Math.Floor(point3.Y)));
                    if (!IsFreeCell(point4.CellId) || !Account.Character.Map.Data.IsLineOfSight(point4.CellId))
                    {
                        return(SpellInabilityReason.LineOfSight);
                    }
                    i += 1;
                }
            }
            if (TotalLaunchByCellBySpell.ContainsKey(spellId) &&
                TotalLaunchByCellBySpell[spellId].ContainsKey(targetPoint.CellId) &&
                TotalLaunchByCellBySpell[spellId][targetPoint.CellId] >= spellLevelsData.MaxCastPerTarget &&
                spellLevelsData.MaxCastPerTarget > 0)
            {
                return(SpellInabilityReason.TooManyLaunchOnCell);
            }
            if (IsFreeCell(cellId))
            {
                if (spellLevelsData.NeedTakenCell)
                {
                    return(SpellInabilityReason.NeedTakenCell);
                }
            }
            else if (spellLevelsData.NeedFreeCell)
            {
                return(SpellInabilityReason.NeedFreeCell);
            }
            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);
            }
        }