Esempio n. 1
0
        public void AddGameObject(GameObject obj)
        {
            short priorityZ = obj.Position.Z;

            switch (obj)
            {
            case Land tile:

                if (tile.IsStretched)
                {
                    priorityZ = (short)(tile.AverageZ - 1);
                }
                else
                {
                    priorityZ--;
                }

                break;

            case Mobile _:
                priorityZ++;

                break;

            case Item item when item.IsCorpse:
                priorityZ++;

                break;

            case GameEffect _:
                priorityZ += 2;

                break;

            default:

            {
                IDynamicItem dyn1 = (IDynamicItem)obj;

                if (TileData.IsBackground(dyn1.ItemData.Flags))
                {
                    priorityZ--;
                }

                if (dyn1.ItemData.Height > 0)
                {
                    priorityZ++;
                }
            }

            break;
            }

            obj.PriorityZ = priorityZ;

            Add(obj);

            TileSorter.Sort(FirstNode);
        }
Esempio n. 2
0
        private static bool IsOK(bool ignoreDoors, int ourZ, int ourTop, List <Static> tiles, List <IDynamicItem> items)
        {
            for (int i = 0; i < tiles.Count; ++i)
            {
                Static item = tiles[i];

                if ((item.ItemData.Flags & IMPASSABLE_SURFACE) != 0) // Impassable || Surface
                {
                    int checkZ   = item.Position.Z;
                    int checkTop = checkZ + ((item.ItemData.Flags & 0x00000400) != 0 ? item.ItemData.Height / 2 : item.ItemData.Height);

                    if (checkTop > ourZ && ourTop > checkZ)
                    {
                        return(false);
                    }
                }
            }

            for (int i = 0; i < items.Count; ++i)
            {
                IDynamicItem item     = items[i];
                int          itemID   = item.Graphic & FileManager.GraphicMask;
                StaticTiles  itemData = TileData.StaticData[itemID];
                ulong        flags    = itemData.Flags;

                if ((flags & IMPASSABLE_SURFACE) != 0) // Impassable || Surface
                {
                    if (ignoreDoors && (TileData.IsDoor((long)flags) || itemID == 0x692 || itemID == 0x846 || itemID == 0x873 || itemID >= 0x6F5 && itemID <= 0x6F6))
                    {
                        continue;
                    }
                    int checkZ   = item.Position.Z;
                    int checkTop = checkZ + ((item.ItemData.Flags & 0x00000400) != 0 ? item.ItemData.Height / 2 : item.ItemData.Height);

                    if (checkTop > ourZ && ourTop > checkZ)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public void InterfaceTest()
        {
            //Assign
            using (var database = new Db
            {
                new DbItem("Target")
                {
                    new DbField("DateTime")
                    {
                        Value = SimpleRenderField.ReplacementKey + "20120204T150015"
                    },
                    new DbField("SingleLineText")
                    {
                        Value = "some awesome dynamic content"
                    },
                    new DbItem("Child1"),
                    new DbItem("Child2"),
                    new DbItem("Child3")
                }
            })
            {
                Item item = database.GetItem("/sitecore/content/Target");

                using (new Sitecore.Sites.SiteContextSwitcher(new FakeSiteContext("Test")))
                {
                    dynamic      d = new DynamicItem(item);
                    IDynamicItem i = d as IDynamicItem;


                    //Act
                    string result = d.DateTime;
                    string path   = i.Path;

                    //Assert
                    Assert.AreEqual(SimpleRenderField.ReplacementValue + "20120204T150015", result);
                    Assert.AreEqual(item.Paths.Path, path);
                }
            }
        }
        public void InterfaceTest()
        {
            //Assign
            Item item = _db.GetItem(TargetPath);

            using (new ItemEditing(item, true))
            {
                item["DateTime"]       = "20120204T150015";
                item["SingleLineText"] = "some awesome dynamic content";
            }

            dynamic      d = new DynamicItem(item);
            IDynamicItem i = d as IDynamicItem;



            //Act
            string result = d.DateTime;
            string path   = i.Path;

            //Assert
            Assert.AreEqual("04/02/2012 15:00:15", result);
            Assert.AreEqual(item.Paths.Path, path);
        }
Esempio n. 5
0
        public void AddGameObject(GameObject obj)
        {
            if (obj is IDynamicItem dyn)
            {
                for (int i = 0; i < _objectsOnTile.Count; i++)
                {
                    if (_objectsOnTile[i] is IDynamicItem dynComp)
                    {
                        if (dynComp.Graphic == dyn.Graphic && dynComp.Position.Z == dyn.Position.Z)
                        {
                            _objectsOnTile.RemoveAt(i--);
                        }
                    }
                }
            }
#if ORIONSORT
            short priorityZ = obj.Position.Z;

            switch (obj)
            {
            case Tile tile:
                if (tile.IsStretched)
                {
                    priorityZ = (short)(tile.AverageZ - 1);
                }
                else
                {
                    priorityZ--;
                }

                break;

            case Mobile _:
                priorityZ++;

                break;

            case Item item when item.IsCorpse:
                priorityZ++;

                break;

            case GameEffect _:
                priorityZ += 2;

                break;

            default:

            {
                IDynamicItem dyn1 = (IDynamicItem)obj;

                if (IO.Resources.TileData.IsBackground((long)dyn1.ItemData.Flags))
                {
                    priorityZ--;
                }

                if (dyn1.ItemData.Height > 0)
                {
                    priorityZ++;
                }
            }

            break;
            }

            obj.PriorityZ = priorityZ;
#endif
            _objectsOnTile.Add(obj);
            _needSort = true;
        }
Esempio n. 6
0
        private static bool Check(Mobile m, List <IDynamicItem> items, int x, int y, int startTop, sbyte startZ, out sbyte newZ)
        {
            newZ = 0;
            Tile mapTile = World.Map.GetTile(x, y);

            if (mapTile == null)
            {
                return(false);
            }
            LandTiles     id = mapTile.TileData;
            List <Static> tiles = mapTile.GetStatics();
            bool          landBlocks = (id.Flags & 0x00000040) != 0;
            bool          considerLand = !mapTile.IsIgnored;
            sbyte         landCenter = 0;
            sbyte         landLow = 0, landTop = 0;

            landCenter = (sbyte)World.Map.GetAverageZ((short)x, (short)y, ref landLow, ref landTop);
            bool moveIsOk = false;
            int  stepTop  = startTop + STEP_HEIGHT;
            int  checkTop = startZ + PERSON_HEIGHT;
            bool ignoreDoors = m.IsDead || m.Graphic == 0x3DB;

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

                if ((tile.ItemData.Flags & IMPASSABLE_SURFACE) == 0x00000200) //  || (canSwim && (flags & TileFlag.Wet) != 0) Surface && !Impassable
                {
                    // if (cantWalk && (flags & TileFlag.Wet) == 0)
                    //     continue;
                    int   itemZ   = tile.Position.Z;
                    int   itemTop = itemZ;
                    sbyte ourZ    = (sbyte)(itemZ + ((tile.ItemData.Flags & 0x00000400) != 0 ? tile.ItemData.Height / 2 : tile.ItemData.Height));
                    int   ourTop  = ourZ + PERSON_HEIGHT;
                    int   testTop = checkTop;

                    if (moveIsOk)
                    {
                        int cmp = Math.Abs(ourZ - m.Position.Z) - Math.Abs(newZ - m.Position.Z);

                        if (cmp > 0 || cmp == 0 && ourZ > newZ)
                        {
                            continue;
                        }
                    }

                    if (ourZ + PERSON_HEIGHT > testTop)
                    {
                        testTop = ourZ + PERSON_HEIGHT;
                    }
                    if ((tile.ItemData.Flags & 0x00000400) == 0)
                    {
                        itemTop += tile.ItemData.Height;
                    }

                    if (stepTop >= itemTop)
                    {
                        int landCheck = itemZ;

                        if (tile.ItemData.Height >= STEP_HEIGHT)
                        {
                            landCheck += STEP_HEIGHT;
                        }
                        else
                        {
                            landCheck += tile.ItemData.Height;
                        }

                        if (considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landLow)
                        {
                            continue;
                        }

                        if (IsOK(ignoreDoors, ourZ, testTop, tiles, items))
                        {
                            newZ     = ourZ;
                            moveIsOk = true;
                        }
                    }
                }
            }

            for (int i = 0; i < items.Count; ++i)
            {
                IDynamicItem item     = items[i];
                StaticTiles  itemData = item.ItemData;
                ulong        flags    = itemData.Flags;

                if ((flags & IMPASSABLE_SURFACE) == 0x00000200) // Surface && !Impassable && !Movable
                {
                    //  || (m.CanSwim && (flags & TileFlag.Wet) != 0))
                    // !item.Movable &&
                    // if (cantWalk && (flags & TileFlag.Wet) == 0)
                    //     continue;
                    int   itemZ   = item.Position.Z;
                    int   itemTop = itemZ;
                    sbyte ourZ    = (sbyte)(itemZ + ((item.ItemData.Flags & 0x00000400) != 0 ? item.ItemData.Height / 2 : item.ItemData.Height));
                    int   ourTop  = ourZ + PERSON_HEIGHT;
                    int   testTop = checkTop;

                    if (moveIsOk)
                    {
                        int cmp = Math.Abs(ourZ - m.Position.Z) - Math.Abs(newZ - m.Position.Z);

                        if (cmp > 0 || cmp == 0 && ourZ > newZ)
                        {
                            continue;
                        }
                    }

                    if (ourZ + PERSON_HEIGHT > testTop)
                    {
                        testTop = ourZ + PERSON_HEIGHT;
                    }
                    if ((itemData.Flags & 0x00000400) == 0)
                    {
                        itemTop += itemData.Height;
                    }

                    if (stepTop >= itemTop)
                    {
                        int landCheck = itemZ;

                        if (itemData.Height >= STEP_HEIGHT)
                        {
                            landCheck += STEP_HEIGHT;
                        }
                        else
                        {
                            landCheck += itemData.Height;
                        }

                        if (considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landLow)
                        {
                            continue;
                        }

                        if (IsOK(ignoreDoors, ourZ, testTop, tiles, items))
                        {
                            newZ     = ourZ;
                            moveIsOk = true;
                        }
                    }
                }
            }

            if (considerLand && !landBlocks && stepTop >= landLow)
            {
                sbyte ourZ    = landCenter;
                int   ourTop  = ourZ + PERSON_HEIGHT;
                int   testTop = checkTop;
                if (ourZ + PERSON_HEIGHT > testTop)
                {
                    testTop = ourZ + PERSON_HEIGHT;
                }
                bool shouldCheck = true;

                if (moveIsOk)
                {
                    int cmp = Math.Abs(ourZ - m.Position.Z) - Math.Abs(newZ - m.Position.Z);
                    if (cmp > 0 || cmp == 0 && ourZ > newZ)
                    {
                        shouldCheck = false;
                    }
                }

                if (shouldCheck && IsOK(ignoreDoors, ourZ, testTop, tiles, items))
                {
                    newZ     = ourZ;
                    moveIsOk = true;
                }
            }

            return(moveIsOk);
        }
Esempio n. 7
0
        private static void GetStartZ(GameObject e, Position loc, List <IDynamicItem> itemList, out sbyte zLow, out sbyte zTop)
        {
            int  xCheck = loc.X, yCheck = loc.Y;
            Tile mapTile = World.Map.GetTile(xCheck, yCheck);

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

                return;
            }

            bool  landBlocks = TileData.IsImpassable((long)mapTile.TileData.Flags);
            sbyte landLow = 0, landTop = 0;
            int   landCenter = World.Map.GetAverageZ((short)xCheck, (short)yCheck, ref landLow, ref landTop);

            bool considerLand = !mapTile.IsIgnored;
            int  zCenter      = 0;

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

            if (considerLand && !landBlocks && loc.Z >= landCenter)
            {
                zLow    = landLow;
                zCenter = landCenter;
                if (!isSet || landTop > zTop)
                {
                    zTop = landTop;
                }
                isSet = true;
            }

            List <Static> staticTiles = mapTile.GetStatics();

            for (int i = 0; i < staticTiles.Count; i++)
            {
                Static      tile    = staticTiles[i];
                StaticTiles id      = tile.ItemData;
                int         calcTop = tile.Position.Z + ((id.Flags & 0x00000400) != 0 ? id.Height / 2 : id.Height);

                if ((!isSet || calcTop >= zCenter) && (id.Flags & 0x00000200) != 0 && loc.Z >= calcTop)
                {
                    //  || (m.CanSwim && (id.Flags & TileFlag.Wet) != 0)
                    // if (m.CantWalk && (id.Flags & TileFlag.Wet) == 0)
                    //     continue;
                    zLow    = tile.Position.Z;
                    zCenter = calcTop;
                    sbyte top = (sbyte)(tile.Position.Z + id.Height);
                    if (!isSet || top > zTop)
                    {
                        zTop = top;
                    }
                    isSet = true;
                }
            }

            for (int i = 0; i < itemList.Count; i++)
            {
                IDynamicItem item    = itemList[i];
                StaticTiles  id      = item.ItemData;
                int          calcTop = item.Position.Z + ((id.Flags & 0x00000400) != 0 ? id.Height / 2 : id.Height);

                if ((!isSet || calcTop >= zCenter) && (id.Flags & 0x00000200) != 0 && loc.Z >= calcTop)
                {
                    //  || (m.CanSwim && (id.Flags & TileFlag.Wet) != 0)
                    // if (m.CantWalk && (id.Flags & TileFlag.Wet) == 0)
                    //     continue;
                    zLow    = item.Position.Z;
                    zCenter = calcTop;
                    sbyte top = (sbyte)(item.Position.Z + id.Height);
                    if (!isSet || top > zTop)
                    {
                        zTop = top;
                    }
                    isSet = true;
                }
            }

            if (!isSet)
            {
                zLow = zTop = loc.Z;
            }
            else if (loc.Z > zTop)
            {
                zTop = loc.Z;
            }
        }