Beispiel #1
0
 public ItemDefinition(uint Id, uint SpriteId, string Name, ItemType Type, ItemBehavior Behavior, int BehaviorData,
     ItemStackingBehavior StackingBehavior, ItemWalkableMode Walkable, int RoomLimit, int SizeX, int SizeY, float Height,
     bool AllowRecycle, bool AllowTrade, bool AllowSell, bool AllowGift, bool AllowInventoryStack)
 {
     mId = Id;
     mSpriteId = SpriteId;
     mName = Name;
     mType = Type;
     mBehavior = Behavior;
     mBehaviorData = BehaviorData;
     mStackingBehavior = StackingBehavior;
     mWalkable = Walkable;
     mRoomLimit = RoomLimit;
     mSizeX = SizeX;
     mSizeY = SizeY;
     mHeight = Height;
     mAllowRecycle = AllowRecycle;
     mAllowTrade = AllowTrade;
     mAllowSell = AllowSell;
     mAllowGift = AllowGift;
     mAllowInventoryStack = AllowInventoryStack;
 }
Beispiel #2
0
 public ItemDefinition(uint Id, uint SpriteId, string Name, ItemType Type, ItemBehavior Behavior, int BehaviorData,
                       ItemStackingBehavior StackingBehavior, ItemWalkableMode Walkable, int RoomLimit, int SizeX, int SizeY, float Height,
                       bool AllowRecycle, bool AllowTrade, bool AllowSell, bool AllowGift, bool AllowInventoryStack)
 {
     mId                  = Id;
     mSpriteId            = SpriteId;
     mName                = Name;
     mType                = Type;
     mBehavior            = Behavior;
     mBehaviorData        = BehaviorData;
     mStackingBehavior    = StackingBehavior;
     mWalkable            = Walkable;
     mRoomLimit           = RoomLimit;
     mSizeX               = SizeX;
     mSizeY               = SizeY;
     mHeight              = Height;
     mAllowRecycle        = AllowRecycle;
     mAllowTrade          = AllowTrade;
     mAllowSell           = AllowSell;
     mAllowGift           = AllowGift;
     mAllowInventoryStack = AllowInventoryStack;
 }
Beispiel #3
0
        public double GetItemPlacementHeight(Item Item, List <Vector2> AffectedTiles, bool RotateOnly)
        {
            lock (mItemSyncRoot)
            {
                // Collect a list of tiles we need to watch
                double RootFloorHeight = -1;
                double HighestStack    = 0;

                double[,] TempStackHeights = new double[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];

                // Check if all tiles are valid
                foreach (Vector2 AffectedTile in AffectedTiles)
                {
                    if (!IsValidPosition(AffectedTile) || mTileStates[AffectedTile.X, AffectedTile.Y] == TileState.Door)
                    {
                        return(-1);
                    }

                    if (RootFloorHeight == -1)
                    {
                        RootFloorHeight = mCachedModel.Heightmap.FloorHeight[AffectedTile.X, AffectedTile.Y];
                    }

                    if (RootFloorHeight != mCachedModel.Heightmap.FloorHeight[AffectedTile.X, AffectedTile.Y])
                    {
                        return(-1); // inconsistent floor height
                    }

                    TempStackHeights[AffectedTile.X, AffectedTile.Y] = RootFloorHeight;
                    HighestStack = RootFloorHeight;

                    if (Item.Definition.StackingBehavior != ItemStackingBehavior.Ignore)
                    {
                        bool CanRotateIntoActors = (Item.Definition.Behavior == ItemBehavior.Seat ||
                                                    Item.Definition.Behavior == ItemBehavior.Bed || Item.Definition.Behavior ==
                                                    ItemBehavior.LoveShuffler || Item.Definition.Behavior == ItemBehavior.Teleporter ||
                                                    Item.Definition.Behavior == ItemBehavior.Roller);

                        if ((!RotateOnly || !CanRotateIntoActors) && GetActorsOnPosition(AffectedTile).Count > 0)
                        {
                            return(-1);
                        }
                    }
                }

                // If this is an IGNORE item, all we need to know is that we're on a valid position etc
                if (Item.Definition.StackingBehavior == ItemStackingBehavior.Ignore)
                {
                    return(RootFloorHeight);
                }

                // Loop items & build temp information for validation later
                ItemStackingBehavior[,] TempStackBehaviors = new ItemStackingBehavior[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
                int[,] InitiatorLimitations = new int[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];

                foreach (Item StackItem in mItems.Values)
                {
                    if (StackItem.Id == Item.Id || StackItem.Definition.StackingBehavior == ItemStackingBehavior.Ignore)
                    {
                        continue; // skip - we do not process ourselves/ignores
                    }

                    Vector2        MatchedTile = null;
                    List <Vector2> ItemTiles   = CalculateAffectedTiles(StackItem, StackItem.RoomPosition.GetVector2(), StackItem.RoomRotation);

                    foreach (Vector2 AffectedTile in AffectedTiles)
                    {
                        foreach (Vector2 ItemTile in ItemTiles)
                        {
                            if (ItemTile.X == AffectedTile.X && ItemTile.Y == AffectedTile.Y)
                            {
                                MatchedTile = AffectedTile;

                                if (StackItem.Definition.Behavior == ItemBehavior.Roller &&
                                    (Item.Definition.SizeX != 1 || Item.Definition.SizeY != 1))
                                {
                                    return(-1);
                                }

                                double ItemTotalHeight = StackItem.RoomPosition.Z + StackItem.Definition.Height;

                                if (ItemTotalHeight >= TempStackHeights[MatchedTile.X, MatchedTile.Y])
                                {
                                    TempStackHeights[MatchedTile.X, MatchedTile.Y]   = ItemTotalHeight;
                                    TempStackBehaviors[MatchedTile.X, MatchedTile.Y] = StackItem.Definition.StackingBehavior;
                                }

                                if (StackItem.Definition.StackingBehavior != ItemStackingBehavior.Ignore)
                                {
                                    InitiatorLimitations[MatchedTile.X, MatchedTile.Y]++;
                                }

                                if (ItemTotalHeight >= HighestStack)
                                {
                                    HighestStack = ItemTotalHeight;
                                }
                            }
                        }
                    }
                }

                if ((HighestStack + Item.Definition.Height) >= (int)ConfigManager.GetValue("rooms.limit.stacking"))
                {
                    return(-1);
                }

                foreach (Vector2 AffectedTile in AffectedTiles)
                {
                    if (((Item.Definition.StackingBehavior == ItemStackingBehavior.Initiator || Item.Definition.StackingBehavior ==
                          ItemStackingBehavior.InitiateAndTerminate) && InitiatorLimitations[AffectedTile.X, AffectedTile.Y] > 0) ||
                        (TempStackBehaviors[AffectedTile.X, AffectedTile.Y] == ItemStackingBehavior.Terminator ||
                         TempStackBehaviors[AffectedTile.X, AffectedTile.Y] == ItemStackingBehavior.InitiateAndTerminate))
                    {
                        return(-1);
                    }
                }

                return(HighestStack);
            }
        }
Beispiel #4
0
        public double GetItemPlacementHeight(Item Item, List<Vector2> AffectedTiles, bool RotateOnly, bool roller = false)
        {
            lock (mItemSyncRoot)
            {
                // Collect a list of tiles we need to watch
                double RootFloorHeight = -1;
                double HighestStack = 0;

                double[,] TempStackHeights = new double[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];

                // Check if all tiles are valid
                foreach (Vector2 AffectedTile in AffectedTiles)
                {
                    if (!roller)
                    {
                        if (!IsValidPosition(AffectedTile) || mTileStates[AffectedTile.X, AffectedTile.Y] == TileState.Door)
                        {
                            return -1;
                        }
                    }

                    if (RootFloorHeight == -1)
                    {
                        RootFloorHeight = mCachedModel.Heightmap.FloorHeight[AffectedTile.X, AffectedTile.Y];
                    }

                    if (RootFloorHeight != mCachedModel.Heightmap.FloorHeight[AffectedTile.X, AffectedTile.Y])
                    {
                        return -1; // inconsistent floor height
                    }

                    TempStackHeights[AffectedTile.X, AffectedTile.Y] = RootFloorHeight;
                    HighestStack = RootFloorHeight;

                    if (Item.Definition.StackingBehavior != ItemStackingBehavior.Ignore)
                    {
                        bool CanRotateIntoActors = (Item.Definition.Behavior == ItemBehavior.Seat ||
                            Item.Definition.Behavior == ItemBehavior.Bed || Item.Definition.Behavior ==
                            ItemBehavior.LoveShuffler || Item.Definition.Behavior == ItemBehavior.Teleporter ||
                            Item.Definition.Behavior == ItemBehavior.Roller);

                        if ((!RotateOnly || !CanRotateIntoActors) && GetActorsOnPosition(AffectedTile).Count > 0)
                        {
                            return -1;
                        }
                    }
                }

                // If this is an IGNORE item, all we need to know is that we're on a valid position etc
                if (Item.Definition.StackingBehavior == ItemStackingBehavior.Ignore)
                {
                    return RootFloorHeight;
                }

                // Loop items & build temp information for validation later
                ItemStackingBehavior[,] TempStackBehaviors = new ItemStackingBehavior[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
                int[,] InitiatorLimitations = new int[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];

                foreach (Item StackItem in mItems.Values)
                {
                    if (StackItem.Id == Item.Id || StackItem.Definition.StackingBehavior == ItemStackingBehavior.Ignore)
                    {
                        continue; // skip - we do not process ourselves/ignores
                    }

                    Vector2 MatchedTile = null;
                    List<Vector2> ItemTiles = CalculateAffectedTiles(StackItem, StackItem.RoomPosition.GetVector2(), StackItem.RoomRotation);

                    foreach (Vector2 AffectedTile in AffectedTiles)
                    {
                        foreach (Vector2 ItemTile in ItemTiles)
                        {
                            if (ItemTile.X == AffectedTile.X && ItemTile.Y == AffectedTile.Y)
                            {
                                MatchedTile = AffectedTile;

                                if (StackItem.Definition.Behavior == ItemBehavior.Roller &&
                                    (Item.Definition.SizeX != 1 || Item.Definition.SizeY != 1))
                                {
                                    return -1;
                                }

                                double ItemTotalHeight = StackItem.RoomPosition.Z + StackItem.Definition.Height;

                                if (ItemTotalHeight >= TempStackHeights[MatchedTile.X, MatchedTile.Y])
                                {
                                    TempStackHeights[MatchedTile.X, MatchedTile.Y] = ItemTotalHeight;
                                    TempStackBehaviors[MatchedTile.X, MatchedTile.Y] = StackItem.Definition.StackingBehavior;
                                }

                                if (StackItem.Definition.StackingBehavior != ItemStackingBehavior.Ignore)
                                {
                                    InitiatorLimitations[MatchedTile.X, MatchedTile.Y]++;
                                }

                                if (ItemTotalHeight >= HighestStack)
                                {
                                    HighestStack = ItemTotalHeight;
                                }
                            }
                        }
                    }
                }

                if ((HighestStack + Item.Definition.Height) >= (int)ConfigManager.GetValue("rooms.limit.stacking"))
                {
                    return -1;
                }

                foreach (Vector2 AffectedTile in AffectedTiles)
                {
                    if (!roller)
                    {
                        if (((Item.Definition.StackingBehavior == ItemStackingBehavior.Initiator || Item.Definition.StackingBehavior ==
                            ItemStackingBehavior.InitiateAndTerminate) && InitiatorLimitations[AffectedTile.X, AffectedTile.Y] > 0) ||
                            (TempStackBehaviors[AffectedTile.X, AffectedTile.Y] == ItemStackingBehavior.Terminator ||
                            TempStackBehaviors[AffectedTile.X, AffectedTile.Y] == ItemStackingBehavior.InitiateAndTerminate))
                        {
                            return -1;
                        }
                    }
                }

                return HighestStack;
            }
        }
Beispiel #5
0
        public static void Initialize(SqlDatabaseClient MySqlClient)
        {
            mDefinitions = new Dictionary <uint, ItemDefinition>();

            int Count  = 0;
            int Failed = 0;

            DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM item_definitions");

            foreach (DataRow Row in Table.Rows)
            {
                ItemStackingBehavior Behavior = ItemStackingBehavior.Normal;

                switch (Row["stacking_behavior"].ToString().ToLower())
                {
                case "terminator":

                    Behavior = ItemStackingBehavior.Terminator;
                    break;

                case "initiator":

                    Behavior = ItemStackingBehavior.Initiator;
                    break;

                case "ignore":

                    Behavior = ItemStackingBehavior.Ignore;
                    break;

                case "disable":

                    Behavior = ItemStackingBehavior.InitiateAndTerminate;
                    break;
                }

                ItemWalkableMode WMode = ItemWalkableMode.Never;

                switch (Row["walkable"].ToString())
                {
                case "1":

                    WMode = ItemWalkableMode.Limited;
                    break;

                case "2":

                    WMode = ItemWalkableMode.Always;
                    break;
                }

                mDefinitions.Add((uint)Row["id"], new ItemDefinition((uint)Row["id"], (uint)Row["sprite_id"],
                                                                     (string)Row["name"], GetTypeFromString(Row["type"].ToString()),
                                                                     ItemBehaviorUtil.FromString((Row["behavior"].ToString())), (int)Row["behavior_data"], Behavior,
                                                                     WMode, (int)Row["room_limit"], (int)Row["size_x"], (int)Row["size_y"], (float)Row["height"],
                                                                     (Row["allow_recycling"].ToString() == "1"), (Row["allow_trading"].ToString() == "1"),
                                                                     (Row["allow_selling"].ToString() == "1"), (Row["allow_gifting"].ToString() == "1"),
                                                                     (Row["allow_inventory_stacking"].ToString() == "1")));

                Count++;
            }

            Output.WriteLine("Loaded " + Count + " item definition(s)" + (Failed > 0 ? " (" + Failed + " skipped due to errors)" : "") + ".", OutputLevel.DebugInformation);
        }