Exemple #1
0
 public static Item CreateFromDatabaseRow(DataRow Row, WiredManager WiredManager = null)
 {
     return new Item((uint)Row["id"], (uint)Row["definition_id"], (uint)Row["user_id"], (uint)Row["room_id"],
         Vector3.FromString((string)Row["room_pos"]), (string)Row["room_wall_pos"], (int)Row["room_rot"],
         (string)Row["flags"], (string)Row["flags_display"], (Row["untradable"].ToString() == "1"),
         (uint)Row["soundmanager_id"], (int)Row["soundmanager_order"], (double)Row["expire_timestamp"], WiredManager);
 }
Exemple #2
0
        public Item(uint Id, uint DefinitionId, uint UserId, uint RoomId, Vector3 RoomPos, string RoomWallPos, int Rotation,
            string Flags, string DisplayFlags, bool Untradable, uint SoundManagerId, int SoundManagerOrder, double ExpireTimestamp, WiredManager WiredManager)
        {
            mId = Id;
            mDefinitionId = DefinitionId;
            mUserId = UserId;
            mRoomId = RoomId;
            mRoomPos = RoomPos;
            mRoomWallPos = RoomWallPos;
            mRoomRot = Rotation;
            mFlags = Flags;
            mDisplayFlags = DisplayFlags;
            mInitialFlags = Flags;
            mUntradable = Untradable;
            mCachedDefinition = ItemDefinitionManager.GetDefinition(mDefinitionId);
            mTmpInteractingUsers = new Dictionary<int, uint>();
            mSoundManagerId = SoundManagerId;
            mSoundManagerOrder = SoundManagerOrder;
            mExpireTimestamp = ExpireTimestamp;

            if (WiredManager != null && (mCachedDefinition.Behavior == ItemBehavior.WiredCondition || mCachedDefinition.Behavior == ItemBehavior.WiredTrigger || mCachedDefinition.Behavior == ItemBehavior.WiredEffect))
            {
                mWiredData = WiredManager.LoadWired(Id, mCachedDefinition.BehaviorData);
                if (mCachedDefinition.Behavior == ItemBehavior.WiredTrigger)
                {
                    switch (WiredTypesUtil.TriggerFromInt(mCachedDefinition.BehaviorData))
                    {
                        case WiredTriggerTypes.periodically:
                            RequestUpdate(mWiredData.Data2);
                            break;
                        case WiredTriggerTypes.walks_on_furni:
                        case WiredTriggerTypes.walks_off_furni:
                            WiredManager.RegisterWalkItems(mId);
                            break;
                    }

                }

            }
        }
Exemple #3
0
        public static Item CreateItem(SqlDatabaseClient MySqlClient, uint DefinitionId, uint UserId, string Flags, string FlagsDisplay, double ExpireTimestamp, bool Untradable = false, WiredManager WiredManager = null)
        {
            MySqlClient.SetParameter("definitionid", DefinitionId);
            MySqlClient.SetParameter("userid", UserId);
            MySqlClient.SetParameter("flags", Flags);
            MySqlClient.SetParameter("flagsd", FlagsDisplay);
            MySqlClient.SetParameter("untradable", Untradable ? "1" : "0");
            MySqlClient.SetParameter("expiretimestamp", ExpireTimestamp);

            string RawId = MySqlClient.ExecuteScalar("INSERT INTO items (definition_id,user_id,flags,flags_display,untradable,expire_timestamp) VALUES (@definitionid,@userid,@flags,@flagsd,@untradable,@expiretimestamp); SELECT LAST_INSERT_ID();").ToString();

            uint Id = 0;
            uint.TryParse(RawId, out Id);

            if (Id == 0)
            {
                return null;
            }

            return new Item(Id, DefinitionId, UserId, 0, new Vector3(), string.Empty, 0, Flags, Flags, Untradable, 0, 0,
                ExpireTimestamp, WiredManager);
        }
Exemple #4
0
        public RoomInstance(uint InstanceId, RoomInfo Info, RoomModel Model)
        {
            mActorSyncRoot = new object();
            mItemSyncRoot = new object();

            mInstanceId = InstanceId;
            mInfo = Info;
            mActors = new Dictionary<uint, RoomActor>();
            mCachedModel = Model;
            mRelativeHeightmap = string.Empty;
            mActorIdGenerator = 1;
            mActorIdGeneratorSyncLock = new object();
            mTileStates = new TileState[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mUsersWithRights = new List<uint>();
            mBannedUsers = new Dictionary<uint, double>();
            mItems = new Dictionary<uint, Item>();
            mStaticObjects = new List<StaticObject>();
            mItemLimitCache = new Dictionary<ItemBehavior, int>();
            mUserGrid = new List<RoomActor>[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mMusicController = new RoomMusicController();
            mTemporaryStickieRights = new Dictionary<uint, uint>();
            mTradeManager = new TradeManager();
            mRollerItems = new List<Item>[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mWiredManager = new WiredManager(this);

            foreach (Bot Bot in BotManager.GenerateBotInstancesForRoom(RoomId))
            {
                AddBotToRoom(Bot);
            }

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                // Items
                MySqlClient.SetParameter("id", RoomId);
                DataTable ItemTable = MySqlClient.ExecuteQueryTable("SELECT * FROM items WHERE room_id = @id");

                foreach (DataRow Row in ItemTable.Rows)
                {
                    Item Item = ItemFactory.CreateFromDatabaseRow(Row, mWiredManager);

                    if (Item.PendingExpiration && Item.ExpireTimeLeft <= 0)
                    {
                        Item.RemovePermanently(MySqlClient);
                        continue;
                    }

                    if (Item.InSoundManager)
                    {
                        continue;
                    }

                    mItems.Add(Item.Id, Item);
                    IncrecementFurniLimitCache(Item.Definition.Behavior);

                    ItemEventDispatcher.InvokeItemEventHandler(null, Item, this, ItemEventType.InstanceLoaded);
                }

                // Static objects
                MySqlClient.SetParameter("id", RoomId);
                DataTable StaticObjectTable = MySqlClient.ExecuteQueryTable("SELECT id,name,position,height,rotation,is_seat FROM static_objects WHERE room_id = @id");

                foreach (DataRow Row in StaticObjectTable.Rows)
                {
                    mStaticObjects.Add(new StaticObject((uint)Row["id"], (string)Row["name"], Vector2.FromString((string)Row["position"]),
                        (int)Row["height"], (int)Row["rotation"], (Row["is_seat"].ToString() == "1")));
                }

                // Rights
                MySqlClient.SetParameter("id", RoomId);
                DataTable RightsTable = MySqlClient.ExecuteQueryTable("SELECT user_id FROM room_rights WHERE room_id = @id");

                foreach (DataRow Row in RightsTable.Rows)
                {
                    mUsersWithRights.Add((uint)Row["user_id"]);
                }

                // Pets
                MySqlClient.SetParameter("id", RoomId);
                DataTable PetsTable = MySqlClient.ExecuteQueryTable("SELECT * FROM pets WHERE room_id = @id");

                foreach (DataRow Row in PetsTable.Rows)
                {
                    Pet PetData = PetFactory.GetPetFromDatabaseRow(Row);

                    AddBotToRoom(BotManager.CreateNewInstance(BotManager.GetHandlerDefinitionForPetType(PetData.Type),
                        RoomId, Vector3.FromString(Row["room_pos"].ToString()), PetData));
                }
            }

            RegenerateRelativeHeightmap();

            mUpdater = new Timer(new TimerCallback(PerformUpdate), null, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));
        }