Example #1
0
        public static bool CreateRoom(string name, int size, int attr)
        {
            TableResult        result = Warehouse.RoomsTable.Execute(TableOperation.Retrieve("Rooms", Config.SPECIAL_KEY));
            DynamicTableEntity entity = (DynamicTableEntity)result.Result;

            if (entity == null)
            {
                entity = new DynamicTableEntity("Rooms", Config.SPECIAL_KEY);

                entity["nextid"] = new EntityProperty(0);
                //entity["borderx"] = new EntityProperty(100);
                entity["bordery"] = new EntityProperty(100);

                Warehouse.RoomsTable.Execute(TableOperation.Insert(entity));
            }
            if (!entity.Properties.ContainsKey("borderny"))
            {
                entity["borderny"] = new EntityProperty(-100);
            }

            int next_id = (int)entity["nextid"].Int32Value;

            createRoomNameEntry(next_id, name);                         // let it throw exception if the name already exists.

            entity["nextid"].Int32Value = next_id + 1;

            bool is_private = (attr & (int)RoomAttributes.IS_PRIVATE) != 0;
            int  entrance_x, entrance_y;

            if (is_private)
            {
                entrance_x = Warehouse.Random.Next(1000, 10000);
                entrance_y = Warehouse.Random.Next(-10000, -1000);
            }
            else
            {
                bool ny = (attr & (int)RoomAttributes.CAN_PICTURE) != 0;

                int border_y = (int)entity[ny ? "borderny" : "bordery"].Int32Value;
                int delta_y  = ((int)((size - 1) / 2) + 1) * (ny ? -1 : 1);

                entrance_x = ny ? -100 : 100;
                entrance_y = border_y + delta_y;

                entity[ny ? "borderny" : "bordery"].Int32Value = border_y + 2 * delta_y;
            }
            Warehouse.RoomsTable.Execute(TableOperation.Replace(entity));                  // Throws StorageException ((412) Precondition Failed) if the entity is modified in between.
            //
            RoomInfoEntity ri_entity = new RoomInfoEntity(next_id, name, entrance_x, entrance_y, size, attr);

            Warehouse.RoomsTable.Execute(TableOperation.Insert(ri_entity));                     // StorageException: 遠端伺服器傳回一個錯誤: (409) 衝突。 if the key already exists.
            //
            if (!is_private)
            {
                RoomList.OnNewRoom(name);
            }
            RoomNameGuard.OnNewRoom(name);
            return(true);
        }
Example #2
0
 public string GetRoomList()
 {
     return(RoomList.GetRoomList());
 }