Exemple #1
0
        public bool CheckMovement(Mobile m, Map map, Point3D loc, Direction d, out int newZ)
        {
            if (map == null || map == Map.Internal)
            {
                newZ = 0;
                return(false);
            }

            int xStart = loc.X;
            int yStart = loc.Y;
            int xForward = xStart, yForward = yStart;
            int xRight = xStart, yRight = yStart;
            int xLeft = xStart, yLeft = yStart;

            bool checkDiagonals = ((int)d & 0x1) == 0x1;

            Offset(d, ref xForward, ref yForward);
            Offset((Direction)((int)d - 1 & 0x7), ref xLeft, ref yLeft);
            Offset((Direction)((int)d + 1 & 0x7), ref xRight, ref yRight);

            if (xForward < 0 || yForward < 0 || xForward >= map.Width || yForward >= map.Height)
            {
                newZ = 0;
                return(false);
            }

            List <Item> itemsStart   = m_Pools[0];
            List <Item> itemsForward = m_Pools[1];
            List <Item> itemsLeft    = m_Pools[2];
            List <Item> itemsRight   = m_Pools[3];

            bool     ignoreMovableImpassables = IgnoreMovableImpassables;
            TileFlag reqFlags = ImpassableSurface;

            if (m.CanSwim)
            {
                reqFlags |= TileFlag.Wet;
            }

            List <Mobile> mobsForward = m_MobPools[0];
            List <Mobile> mobsLeft    = m_MobPools[1];
            List <Mobile> mobsRight   = m_MobPools[2];

            BaseCreature bc = m as BaseCreature;

            bool checkMobs = bc?.Controlled == false &&
                             (xForward != Goal.X || yForward != Goal.Y);

            if (checkDiagonals)
            {
                Sector sectorStart   = map.GetSector(xStart, yStart);
                Sector sectorForward = map.GetSector(xForward, yForward);
                Sector sectorLeft    = map.GetSector(xLeft, yLeft);
                Sector sectorRight   = map.GetSector(xRight, yRight);

                List <Sector> sectors = m_Sectors;

                sectors.Add(sectorStart);

                if (!sectors.Contains(sectorForward))
                {
                    sectors.Add(sectorForward);
                }

                if (!sectors.Contains(sectorLeft))
                {
                    sectors.Add(sectorLeft);
                }

                if (!sectors.Contains(sectorRight))
                {
                    sectors.Add(sectorRight);
                }

                for (int i = 0; i < sectors.Count; ++i)
                {
                    Sector sector = sectors[i];

                    for (int j = 0; j < sector.Items.Count; ++j)
                    {
                        Item item = sector.Items[j];

                        if (ignoreMovableImpassables && item.Movable && (item.ItemData.Flags & ImpassableSurface) != 0)
                        {
                            continue;
                        }

                        if ((item.ItemData.Flags & reqFlags) == 0)
                        {
                            continue;
                        }

                        if (!(item is BaseMulti))
                        {
                            if (sector == sectorStart && item.AtWorldPoint(xStart, yStart) &&
                                item.ItemID <= TileData.MaxItemValue)
                            {
                                itemsStart.Add(item);
                            }
                            else if (sector == sectorForward && item.AtWorldPoint(xForward, yForward) &&
                                     item.ItemID <= TileData.MaxItemValue)
                            {
                                itemsForward.Add(item);
                            }
                            else if (sector == sectorLeft && item.AtWorldPoint(xLeft, yLeft) &&
                                     item.ItemID <= TileData.MaxItemValue)
                            {
                                itemsLeft.Add(item);
                            }
                            else if (sector == sectorRight && item.AtWorldPoint(xRight, yRight) &&
                                     item.ItemID <= TileData.MaxItemValue)
                            {
                                itemsRight.Add(item);
                            }
                        }
                    }

                    if (checkMobs)
                    {
                        for (int j = 0; j < sector.Mobiles.Count; ++j)
                        {
                            Mobile mob = sector.Mobiles[j];

                            if (sector == sectorForward && mob.X == xForward && mob.Y == yForward)
                            {
                                mobsForward.Add(mob);
                            }
                            else if (sector == sectorLeft && mob.X == xLeft && mob.Y == yLeft)
                            {
                                mobsLeft.Add(mob);
                            }
                            else if (sector == sectorRight && mob.X == xRight && mob.Y == yRight)
                            {
                                mobsRight.Add(mob);
                            }
                        }
                    }
                }

                if (m_Sectors.Count > 0)
                {
                    m_Sectors.Clear();
                }
            }
            else
            {
                Sector sectorStart   = map.GetSector(xStart, yStart);
                Sector sectorForward = map.GetSector(xForward, yForward);

                if (sectorStart == sectorForward)
                {
                    for (int i = 0; i < sectorStart.Items.Count; ++i)
                    {
                        Item item = sectorStart.Items[i];

                        if (ignoreMovableImpassables && item.Movable && (item.ItemData.Flags & ImpassableSurface) != 0)
                        {
                            continue;
                        }

                        if ((item.ItemData.Flags & reqFlags) == 0)
                        {
                            continue;
                        }

                        if (!(item is BaseMulti))
                        {
                            if (item.AtWorldPoint(xStart, yStart) &&
                                item.ItemID <= TileData.MaxItemValue)
                            {
                                itemsStart.Add(item);
                            }
                            else if (item.AtWorldPoint(xForward, yForward) &&
                                     item.ItemID <= TileData.MaxItemValue)
                            {
                                itemsForward.Add(item);
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < sectorForward.Items.Count; ++i)
                    {
                        Item item = sectorForward.Items[i];

                        if (ignoreMovableImpassables && item.Movable && (item.ItemData.Flags & ImpassableSurface) != 0)
                        {
                            continue;
                        }

                        if ((item.ItemData.Flags & reqFlags) == 0)
                        {
                            continue;
                        }

                        if (item.AtWorldPoint(xForward, yForward) && !(item is BaseMulti) &&
                            item.ItemID <= TileData.MaxItemValue)
                        {
                            itemsForward.Add(item);
                        }
                    }

                    for (int i = 0; i < sectorStart.Items.Count; ++i)
                    {
                        Item item = sectorStart.Items[i];

                        if (ignoreMovableImpassables && item.Movable && (item.ItemData.Flags & ImpassableSurface) != 0)
                        {
                            continue;
                        }

                        if ((item.ItemData.Flags & reqFlags) == 0)
                        {
                            continue;
                        }

                        if (item.AtWorldPoint(xStart, yStart) && !(item is BaseMulti) &&
                            item.ItemID <= TileData.MaxItemValue)
                        {
                            itemsStart.Add(item);
                        }
                    }
                }

                if (checkMobs)
                {
                    for (int i = 0; i < sectorForward.Mobiles.Count; ++i)
                    {
                        Mobile mob = sectorForward.Mobiles[i];

                        if (mob.X == xForward && mob.Y == yForward)
                        {
                            mobsForward.Add(mob);
                        }
                    }
                }
            }

            GetStartZ(m, map, loc, itemsStart, out int startZ, out int startTop);

            bc?.DebugSay("My Z/Top is {0} {1}", startZ, startTop);

            bool moveIsOk = Check(map, m, itemsForward, mobsForward, xForward, yForward, startTop, startZ, m.CanSwim,
                                  m.CantWalk, out newZ);

            bc?.DebugSay("Can I move? {0} {1}", moveIsOk, newZ);

            if (moveIsOk && checkDiagonals)
            {
                if (m.Player && m.AccessLevel < AccessLevel.GameMaster)
                {
                    if (!(Check(map, m, itemsLeft, mobsLeft, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk,
                                out _) && Check(map, m, itemsRight, mobsRight, xRight, yRight, startTop, startZ, m.CanSwim,
                                                m.CantWalk, out _)))
                    {
                        moveIsOk = false;
                    }
                }
                else
                {
                    if (!(Check(map, m, itemsLeft, mobsLeft, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk,
                                out _) || Check(map, m, itemsRight, mobsRight, xRight, yRight, startTop, startZ, m.CanSwim,
                                                m.CantWalk, out _)))
                    {
                        moveIsOk = false;
                    }
                }

                bc?.DebugSay("Can I still move? {0} {1}", moveIsOk, newZ);
            }

            for (int i = 0; i < (checkDiagonals ? 4 : 2); ++i)
            {
                if (m_Pools[i].Count != 0)
                {
                    m_Pools[i].Clear();
                }
            }

            for (int i = 0; i < (checkDiagonals ? 3 : 1); ++i)
            {
                if (m_MobPools[i].Count != 0)
                {
                    m_MobPools[i].Clear();
                }
            }

            if (!moveIsOk)
            {
                newZ = startZ;
            }

            return(moveIsOk);
        }
        public override bool CheckCast()
        {
            if (Caster is BaseCreature)
            {
                BaseCreature bc = Caster as BaseCreature;
                bc.DebugSay("Blue Spell: CheckCast is returning base");
                return(base.CheckCast());
            }
            else if (Caster.AccessLevel == AccessLevel.Counselor)
            {
                // Counselors are blocked becuase counselors are not meant to have leet god powers. Lock the level down like you're supposed to and you can hire the position out as the advice giving only position as it's supposed to be.
                Caster.SendMessage("You are blocked from these spells.");
                return(false);
            }
            else if (Caster is PlayerMobile && !BlueMageControl.IsBlueMage(Caster) && Caster.AccessLevel == AccessLevel.Player)
            {
                Caster.SendMessage("Only a blue mage can cast this spell.");
                return(false);
            }

            // Not a real class system, because class systems suck, but you can't use higher levels of spells as part of an intended balence.
            if (BlueMageControl.SkillLock && Caster.AccessLevel == AccessLevel.Player)
            {
                if (Caster.Skills[SkillName.Magery].Base > 50.0)
                {
                    //Caster.SendMessage( "You study true magic and cannot mimic such a choatic spell." );
                    Caster.Skills[SkillName.Magery].Base = 50.0;
                }
                if (Caster.Skills[SkillName.Chivalry].Base > 50.0)
                {
                    //Caster.SendMessage( "Your oath prevents you from using such a dishonorable spell." );
                    Caster.Skills[SkillName.Chivalry].Base = 50.0;
                }
                if (Caster.Skills[SkillName.Necromancy].Base > 50.0)
                {
                    //Caster.SendMessage( "Your dark power prevents you from casting this spell." );
                    Caster.Skills[SkillName.Necromancy].Base = 50.0;
                }
                if (Caster.Skills[SkillName.AnimalTaming].Base > 0.0)
                {
                    //Caster.SendMessage( "You refuse to cast the spell, you believe monsters should be used, not studied." );
                    Caster.Skills[SkillName.AnimalTaming].Base = 0.0;
                }
                else if (Caster.Skills[SkillName.Spellweaving].Base > 50.0)
                {
                    Caster.Skills[SkillName.Spellweaving].Base = 50.0;
                }
                else if (Caster.Skills[SkillName.Mysticism].Base > 50.0)
                {
                    Caster.Skills[SkillName.Mysticism].Base = 50.0;
                }

                if (Caster is PlayerMobile && !BlueMageControl.CheckKnown(Caster, this, false))
                {
                    Caster.SendMessage("You do not know this spell");
                    return(false);
                }
            }

            if (!base.CheckCast())               //|| !base.CheckSequence() )
            {
                return(false);
            }
            else
            {
                //Caster.PublicOverheadMessage( MessageType.Regular, 1365, false, this.type.toString() );
                BaseAnimation();
                return(true);
            }
        }