Пример #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);
        }
Пример #2
0
 public RoomInfo(RoomInfoEntity entity)
 {
     this.Name       = entity.Name;
     this.Size       = entity.Size;
     this.Attr       = entity.Attr;
     this.CreateDate = entity.CreateDate;
     this.HomeX      = entity.HomeX;
     this.HomeY      = entity.HomeY;
     this.EntranceX  = entity.EntranceX;
     this.EntranceY  = entity.EntranceY;
 }
Пример #3
0
        private static void updateRoomHome(string name)
        {
            RoomInfoEntity entity = RoomStore.GetRoom(name);

            if (entity != null)
            {
                int num_of_paths = DrawingStore.GetNumberOfPaths(entity.HomeX, entity.HomeY);
                if (num_of_paths < Config.MOVE_HOME_THRESHOLD)
                {
                    return;
                }

#if GO_SLOWER
                num_of_paths = DrawingStore.GetNumberOfPaths(entity.HomeX, entity.HomeY + 1);
                if (num_of_paths < Config.MOVE_HOME_THRESHOLD)
                {
                    return;
                }

                num_of_paths = DrawingStore.GetNumberOfPaths(entity.HomeX, entity.HomeY - 1);
                if (num_of_paths < Config.MOVE_HOME_THRESHOLD)
                {
                    return;
                }
#endif
                if (entity.HomeX < 0)
                {
                    if (entity.HomeY < 0)
                    {
                        entity.HomeX--;
                    }
                    else
                    {
                        entity.HomeY++;
                    }
                }
                else
                if (entity.HomeY < 0)
                {
                    entity.HomeY--;
                }
                else
                {
                    entity.HomeX++;
                }

                Warehouse.RoomsTable.Execute(TableOperation.Replace(entity));                      // Throws StorageException ((412) Precondition Failed) if the entity is modified in between.

                RoomsPond.Notify(name);
            }
        }
Пример #4
0
        private static RoomInfo insertNew(string key, string name)
        {
            RoomInfoEntity entity = RoomStore.GetRoom(name);                            // if concurrency happens, this will be done more than once.

            if (entity != null)
            {
                RoomInfo obj = new RoomInfo(entity);

                HttpRuntime.Cache.Insert(key, obj, null, DateTime.Now.AddSeconds(Config.DEFAULT_CACHE_SECONDS),
                                         Cache.NoSlidingExpiration, CacheItemPriority.Default, removedCallback);
                return(obj);
            }
            // expires after some time for multi-node synchronization (unreliable).
            return(null);
        }