コード例 #1
0
ファイル: DeferredEntity.cs プロジェクト: ViWinfii/UltimaXNA
 public DeferredEntity(AEntity entity, Vector3 drawPosition, int z)
     : base(entity.Serial, entity.Map)
 {
     m_BaseView     = GetBaseView(entity);
     m_DrawPosition = drawPosition;
     m_Z            = z;
 }
コード例 #2
0
        public Overhead(AEntity parent, MessageType msgType, string text)
            : base(parent.Serial, parent.Map)
        {
            Parent      = parent;
            MessageType = msgType;
            Text        = text;

            m_TimePersist = 5000;
        }
コード例 #3
0
ファイル: DeferredEntity.cs プロジェクト: ViWinfii/UltimaXNA
 private AEntityView GetBaseView(AEntity entity)
 {
     if (entity is Mobile)
     {
         return((MobileView)entity.GetView());
     }
     else if (entity is LightningEffect)
     {
         return((LightningEffectView)entity.GetView());
     }
     else if (entity is AnimatedItemEffect)
     {
         return((AnimatedItemEffectView)entity.GetView());
     }
     else if (entity is MovingEffect)
     {
         return((MovingEffectView)entity.GetView());
     }
     else
     {
         Core.Diagnostics.Logger.Fatal("Cannot defer this type of object.");
     }
     return(null);
 }
コード例 #4
0
 public MobileMovement(AEntity entity)
 {
     m_entity     = entity;
     m_moveEvents = new MoveEvents();
 }
コード例 #5
0
 public void SaveLastParent()
 {
     m_lastParent = Parent;
 }
コード例 #6
0
        private static void getStartZ(AEntity m, Map map, Position3D loc, List <Item> itemList, out int zLow, out int zTop)
        {
            int xCheck = (int)loc.X, yCheck = (int)loc.Y;

            MapTile mapTile = map.GetMapTile(xCheck, yCheck);

            if (mapTile == null)
            {
                zLow = int.MinValue;
                zTop = int.MinValue;
            }

            bool landBlocks = mapTile.Ground.LandData.IsImpassible; //(TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Impassable) != 0;

            // if (landBlocks && m.CanSwim && (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Wet) != 0)
            //     landBlocks = false;
            // else if (m.CantWalk && (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Wet) == 0)
            //     landBlocks = true;

            int landLow = 0, landCenter = 0, landTop = 0;

            landCenter = map.GetAverageZ(xCheck, yCheck, ref landLow, ref landTop);

            bool considerLand = !mapTile.Ground.IsIgnored;

            int  zCenter = zLow = zTop = 0;
            bool isSet   = false;

            if (considerLand && !landBlocks && loc.Z >= landCenter)
            {
                zLow    = landLow;
                zCenter = landCenter;

                if (!isSet || landTop > zTop)
                {
                    zTop = landTop;
                }

                isSet = true;
            }

            StaticItem[] staticTiles = mapTile.GetStatics().ToArray();

            for (int i = 0; i < staticTiles.Length; ++i)
            {
                StaticItem tile = staticTiles[i];

                int calcTop = ((int)tile.Z + tile.ItemData.CalcHeight);

                if ((!isSet || calcTop >= zCenter) && ((tile.ItemData.Flags & TileFlag.Surface) != 0) && loc.Z >= calcTop)
                {
                    //  || (m.CanSwim && (id.Flags & TileFlag.Wet) != 0)
                    // if (m.CantWalk && (id.Flags & TileFlag.Wet) == 0)
                    //     continue;

                    zLow    = (int)tile.Z;
                    zCenter = calcTop;

                    int top = (int)tile.Z + tile.ItemData.Height;

                    if (!isSet || top > zTop)
                    {
                        zTop = top;
                    }

                    isSet = true;
                }
            }

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

                UltimaData.ItemData id = item.ItemData;

                int calcTop = item.Z + id.CalcHeight;

                if ((!isSet || calcTop >= zCenter) && ((id.Flags & TileFlag.Surface) != 0) && loc.Z >= calcTop)
                {
                    //  || (m.CanSwim && (id.Flags & TileFlag.Wet) != 0)
                    // if (m.CantWalk && (id.Flags & TileFlag.Wet) == 0)
                    //     continue;

                    zLow    = item.Z;
                    zCenter = calcTop;

                    int top = item.Z + id.Height;

                    if (!isSet || top > zTop)
                    {
                        zTop = top;
                    }

                    isSet = true;
                }
            }

            if (!isSet)
            {
                zLow = zTop = (int)loc.Z;
            }
            else if (loc.Z > zTop)
            {
                zTop = (int)loc.Z;
            }
        }
コード例 #7
0
        public static bool CheckMovement(Mobile m, Position3D loc, Direction d, out int newZ, bool forceOK = false)
        {
            Map map = m.Map;

            if (map == null)
            {
                newZ = 0;
                return(true);
            }

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

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

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

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

            int startZ, startTop;

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

            TileFlag reqFlags = ImpassableSurface;

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

            if (checkDiagonals)
            {
                MapTile tileStart   = map.GetMapTile(xStart, yStart);
                MapTile tileForward = map.GetMapTile(xForward, yForward);
                MapTile tileLeft    = map.GetMapTile(xLeft, yLeft);
                MapTile tileRight   = map.GetMapTile(xRight, yRight);
                if ((tileForward == null) || (tileStart == null) || (tileLeft == null) || (tileRight == null))
                {
                    newZ = (int)loc.Z;
                    return(false);
                }

                List <MapTile> tiles = new List <MapTile>(); //m_Sectors;

                tiles.Add(tileStart);
                tiles.Add(tileForward);
                tiles.Add(tileLeft);
                tiles.Add(tileRight);

                for (int i = 0; i < tiles.Count; ++i)
                {
                    MapTile tile = tiles[i];

                    for (int j = 0; j < tile.Entities.Count; ++j)
                    {
                        AEntity entity = tile.Entities[j]; //Item item = sector.Items[j];

                        // if (ignoreMovableImpassables && item.Movable && item.ItemData.Impassable)
                        //     continue;

                        if (entity is Item)
                        {
                            Item item = (Item)entity;

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

                            if (tile == tileStart && item.AtWorldPoint(xStart, yStart) && item.ItemID < 0x4000)
                            {
                                itemsStart.Add(item);
                            }
                            else if (tile == tileForward && item.AtWorldPoint(xForward, yForward) && item.ItemID < 0x4000)
                            {
                                itemsForward.Add(item);
                            }
                            else if (tile == tileLeft && item.AtWorldPoint(xLeft, yLeft) && item.ItemID < 0x4000)
                            {
                                itemsLeft.Add(item);
                            }
                            else if (tile == tileRight && item.AtWorldPoint(xRight, yRight) && item.ItemID < 0x4000)
                            {
                                itemsRight.Add(item);
                            }
                        }
                    }
                }
            }
            else
            {
                MapTile tileStart   = map.GetMapTile(xStart, yStart);
                MapTile tileForward = map.GetMapTile(xForward, yForward);
                if ((tileForward == null) || (tileStart == null))
                {
                    newZ = (int)loc.Z;
                    return(false);
                }

                if (tileStart == tileForward)
                {
                    for (int i = 0; i < tileStart.Entities.Count; ++i)
                    {
                        AEntity entity = tileStart.Entities[i]; // Item item = sectorStart.Items[i];

                        if (entity is Item)
                        {
                            Item item = (Item)entity;

                            // if (ignoreMovableImpassables && item.Movable && item.ItemData.Impassable)
                            //     continue;

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

                            if (item.AtWorldPoint(xStart, yStart) && item.ItemID < 0x4000)
                            {
                                itemsStart.Add(item);
                            }
                            else if (item.AtWorldPoint(xForward, yForward) && item.ItemID < 0x4000)
                            {
                                itemsForward.Add(item);
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < tileForward.Entities.Count; ++i)
                    {
                        AEntity entity = tileForward.Entities[i]; // Item item = sectorForward.Items[i];

                        if (entity is Item)
                        {
                            Item item = (Item)entity;

                            // if (ignoreMovableImpassables && item.Movable && item.ItemData.Impassable)
                            //     continue;

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

                            if (item.AtWorldPoint(xForward, yForward) && item.ItemID < 0x4000)
                            {
                                itemsForward.Add(item);
                            }
                        }
                    }

                    for (int i = 0; i < tileStart.Entities.Count; ++i)
                    {
                        AEntity entity = tileStart.Entities[i]; // Item item = sectorStart.Items[i];

                        if (entity is Item)
                        {
                            Item item = (Item)entity;

                            // if (ignoreMovableImpassables && item.Movable && item.ItemData.Impassable)
                            //     continue;

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

                            if (item.AtWorldPoint(xStart, yStart) && item.ItemID < 0x4000)
                            {
                                itemsStart.Add(item);
                            }
                        }
                    }
                }
            }

            getStartZ(m, map, loc, itemsStart, out startZ, out startTop);

            bool moveIsOk = check(map, m, itemsForward, xForward, yForward, startTop, startZ, out newZ) | forceOK;

            if (moveIsOk && checkDiagonals)
            {
                int hold;

                if (!check(map, m, itemsLeft, xLeft, yLeft, startTop, startZ, out hold) && !check(map, m, itemsRight, xRight, yRight, startTop, startZ, out hold))
                {
                    moveIsOk = false;
                }
            }

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

            if (!moveIsOk)
            {
                newZ = startZ;
            }

            return(moveIsOk);
        }