Beispiel #1
0
        public static bool CanCastHackInRange(WoWSpell spell, WoWUnit unit)
        {
            if (unit != null && !spell.IsSelfOnlySpell && !unit.IsMe)
            {
#if USE_LUA_RANGECHECK
                // will exercise the IsSpellInRange LUA if it can easily
                // .. derive a UnitID for the target

                string sTarget = null;

                if (unit.Guid == Me.CurrentTargetGuid)
                    sTarget = "target";
                else if (unit.IsPlayer && unit.ToPlayer().IsInMyPartyOrRaid())
                    sTarget = unit.Name;
                else if (unit.IsPet && unit.OwnedByUnit != null && unit.OwnedByUnit.IsPlayer && unit.OwnedByUnit.ToPlayer().IsInMyPartyOrRaid())
                    sTarget = unit.OwnedByUnit.Name + "-pet";
                else if (Me.GotAlivePet)
                {
                    if (unit.Guid == Me.Pet.Guid)
                        sTarget = "pet";
                    else if (unit.Guid == Me.Pet.CurrentTargetGuid)
                        sTarget = "pettarget";
                }

                if (sTarget != null)
                {
                    // 
                    string lua = string.Format("return IsSpellInRange(\"{0}\",\"{1}\")", spell.Name, sTarget);
                    string inRange = Lua.GetReturnVal<string>(lua, 0);
                    if (inRange != "1")
                    {
                        if (SingularSettings.DebugSpellCanCast)
                            Logger.WriteFile( "CanCast[{0}]: target @ {1:F1} yds failed IsSpellInRange() = {2}", spell.Name, unit.Distance, inRange);
                        return false;
                    }
                }
                else 
#endif
                {
                    if (spell.IsMeleeSpell && !unit.IsWithinMeleeRange)
                    {
                        if (SingularSettings.DebugSpellCasting)
                            Logger.WriteFile( "CanCast[{0}]: target @ {1:F1} yds not in melee range", spell.Name, unit.Distance);
                        return false;
                    }
                    else if (spell.HasRange)
                    {
                        if (unit.Distance > spell.ActualMaxRange(unit))
                        {
                            if (SingularSettings.DebugSpellCasting)
                                Logger.WriteFile( "CanCast[{0}]: out of range - further than {1:F1}", spell.Name, spell.ActualMaxRange(unit));
                            return false;
                        }
                        if (unit.Distance < spell.ActualMinRange(unit))
                        {
                            if (SingularSettings.DebugSpellCasting)
                                Logger.WriteFile( "CanCast[{0}]: out of range - closer than {1:F1}", spell.Name, spell.ActualMinRange(unit));
                            return false;
                        }
                    }
                }

                if (!unit.InLineOfSpellSight)
                {
                    if (SingularSettings.DebugSpellCasting)
                        Logger.WriteFile( "CanCast[{0}]: not in spell line of {1}", spell.Name, unit.SafeName());
                    return false;
                }
            }

            return true;
        }