public void CanAddUserToRoom() { var room = new Room(0, TestHelper.RoomName, new DateTime(2000, 12, 12)); var account1 = TestHelper.AccountMock(); var account2 = TestHelper.AccountMock(); var accountRepository = new AccountRepository(); var roomRepository = new RoomRepository(); roomRepository.Add(room); accountRepository.Add(account1); accountRepository.Add(account2); room.Add(account1); room.Add(account2); roomRepository.Add(room); var roomRepository2 = new RoomRepository(); Room result = roomRepository2.GetRoom(room.Id); Assert.AreEqual(2, result.Users.Count()); var rooms = roomRepository2.GetRooms(account1.Id); Assert.AreEqual(1, rooms.Count()); }
public void CanGetRoomState(AccountType accountType) { _fakeNowProvider = new FakeNowProvider { Now = new DateTime(2000, 12, 12, 12, 12, 0) }; var usersCache = new MockUserStateRepository(); var calc = FakeTimeCalculatorFactory.GetTimeWarpStateCalculator(); _userStateManager = new UserStateManager(calc, usersCache); _testRoom = new Room(2, "testRoom2", new DateTime(2001, 12, 12)); _roomRepository = new MockRoomRepository(); _roomRepository.Add(_testRoom); _roomStateController = new RoomStateController(_userStateManager, _roomRepository, new RoomRemovalPolicy(), _fakeNowProvider); var newAccount = new Account(0, TestHelper.NameMock, TestHelper.EmailAddressMock + 1, accountType); _testRoom.Add(newAccount); usersCache.Add(new TimeWarpUserState(0, newAccount, TimeWarpState.Resting, _fakeNowProvider.Now, TimeSpan.FromSeconds(1), 0, 1)); var oldAccount = new Account(1, TestHelper.NameMock, TestHelper.EmailAddressMock + 2, accountType); _testRoom.Add(oldAccount); usersCache.Add(new TimeWarpUserState(1, oldAccount, TimeWarpState.Resting, _fakeNowProvider.Now.Subtract(TimeSpan.FromDays(100)), TimeSpan.FromSeconds(1), 0, 1)); var state = _roomStateController.Get(2); Assert.AreEqual(1, state.Count()); Assert.AreEqual(0, state.Single().AccountId); }
public void Init() { World.PlayMusic("Music/dungeon1"); _player = new Player(new Vector2(TileSize.Int * 7, TileSize.Int * 12)); //_player = new Player(new Vector2(0, 0)); _room = new Room(); _room.Add(new TileWalker(0, 16, 0, 16).Get(x => new Tile("tile1", x, Rotation.Up, false))); //_room.Add(new TileWalker(0, 1, 0, 20).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(0, 28, 0, 1).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(17, 11, 0, 20).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(0, 28, 17, 3).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(7, 1, 4, 1).Get(x => new Wall(Rotation.Up, x))); _room.Add(new TileWalker(4, 1, 4, 1).Get(x => new WallCorner(Rotation.Up, x))); //_room.Add(new TileWalker(4, 1, 7, 1).Get(x => new Wall(Rotation.Left, x))); _room.Add(new TileWalker(4, 1, 10, 1).Get(x => new WallCorner(Rotation.Left, x))); //_room.Add(new TileWalker(7, 1, 10, 1).Get(x => new Wall(Rotation.Down, x))); _room.Add(new TileWalker(10, 1, 10, 1).Get(x => new WallCorner(Rotation.Down, x))); //_room.Add(new TileWalker(10, 1, 7, 1).Get(x => new Wall(Rotation.Right, x))); _room.Add(new TileWalker(10, 1, 4, 1).Get(x => new WallCorner(Rotation.Right, x))); _room.Add(new TileWalker(6, 4, 4, 1).Get(x => new Wall(Rotation.Up, x))); _room.Add(new TileWalker(4, 1, 6, 4).Get(x => new Wall(Rotation.Left, x))); _room.Add(new TileWalker(6, 4, 10, 1).Get(x => new Wall(Rotation.Down, x))); _room.Add(new TileWalker(10, 1, 6, 4).Get(x => new Wall(Rotation.Right, x))); //_room.Add(new TileWalker(0, 1, 0, 1).Get(x => new WallCorner(Rotation.Up, x))); //_room.Add(new TileWalker(0, 1, 14, 1).Get(x => new WallCorner(Rotation.Left, x))); //_room.Add(new TileWalker(14, 1, 0, 1).Get(x => new WallCorner(Rotation.Right, x))); //_room.Add(new TileWalker(14, 1, 14, 1).Get(x => new WallCorner(Rotation.Down, x))); }
static void Main(string[] args) { var player = World.Instance.Create <GameObject>(); World.Instance.TryAdd <PlayerBehavior>(player); World.Instance.TryAdd <SightBehavior>(player); World.Instance.TryAdd <PlayerHearingBehavior>(player); World.Instance.TryAdd <SayBehavior>(player); World.Instance.TryAdd <InventoryBehavior>(player); player.Title = "Ivan"; player.Description = "Ugly traveler"; var amulet = World.Instance.Create <GameObject>(); amulet.Title = "Amulet"; amulet.Description = "Dirty"; var hobo = World.Instance.Create <GameObject>(); World.Instance.TryAdd <SayBehavior>(hobo); World.Instance.TryAdd <HoboIdleBehavior>(hobo); World.Instance.TryAdd <HoboHearingBehavior>(hobo); World.Instance.TryAdd <InventoryBehavior>(hobo); hobo.Title = "Hobo"; hobo.Description = "Handsome homeless man"; hobo.TryGet <InventoryBehavior>(out InventoryBehavior behavior); behavior.Add(amulet); behavior.Gold = 100; var sword = World.Instance.Create <GameObject>(); sword.Title = "Sword"; sword.Description = "Rusty sword"; var room = new Room() { Title = "Road", Description = "Old town road" }; room.Add(player); room.Add(hobo); room.Add(sword); World.Instance.AddRoom(room); World.Instance.Update(); World.Instance.Update(); World.Instance.Update(); World.Instance.Update(); }
public void CallByNameTest() { //expected Dog dog = new Dog("Вовкодав", "ч"); Dog dog1 = new Dog("Диктатор", "ч"); Dog dog2 = new Dog("Диктатор", "ч"); Room room = new Room(); room.Add(dog); room.Add(dog1); room.Add(dog2); RoomStub roomStub = new RoomStub(); room.room = roomStub; string expexted = "expexted"; List <string> expectedList = new List <string>() { "expectedList" }; Mock.Arrange(() => dog1.Voice()).Returns(expexted); Mock.Arrange(() => dog2.Voice()).Returns(expexted); Mock.Arrange(() => roomStub.Call(Arg.IsAny <string>())).Returns(expectedList); // actual List <string> list = room.Call("Диктатор"); Assert.AreEqual(expexted, list[0]); Assert.AreEqual(expexted, list[1]); Assert.AreEqual(expectedList[0], list[2]); Assert.AreEqual(3, list.Count); // Кімната для тестування виклику з вольєра. Room room1 = new Room(); Volary volary = new Volary(); room1.volary = volary; List <string> expectedVolary = new List <string>() { "expectedVolary" }; Mock.Arrange(() => volary.Call(Arg.IsAny <string>())).Returns(expectedVolary); List <string> actualList = room1.Call("AnyName"); Assert.AreEqual(expectedVolary[0], actualList[0]); }
public ActionResult Create(FormCollection collection, Room room) { try { if (string.IsNullOrEmpty(room.Name)) { // do nothing } else { var response = room.Add(SessionInfo.UserIDLogged); if (response.ReturnCode < 0000) { ModelState.AddModelError("Error", response.Message); return(View()); } } return(RedirectToAction("Index")); } catch { return(View()); } }
/// <summary> /// 加入房间 /// </summary> /// <param name="self"></param> /// <param name="room"></param> /// <param name="matcher"></param> public static async void JoinRoom(this MatchComponent self, Room room, Matcher matcher) { //玩家加入房间,移除匹配队列 self.Playing.Add(matcher.UserID, room.Id); self.MatchSuccessQueue.Enqueue(matcher); room.Add(EntityFactory.CreateWithId <Gamer, long>(matcher.PlayerID, matcher.UserID)); //发送获取加入房间密匙消息 ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(room.Id); GetJoinRoomKey_RE playerJoinRoomRE = await actorProxy.Call <GetJoinRoomKey_RE>(new GetJoinRoomKey_RT() { PlayerID = matcher.PlayerID, UserID = matcher.UserID, GateSeesionID = matcher.GateSessionID }); //发送匹配成功消息 string gateAddress = Game.Scene.GetComponent <StartConfigComponent>().Get(matcher.GateAppID).GetComponent <InnerConfig>().Address; Session gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(gateAddress); gateSession.Send(new MatchSuccess() { PlayerID = matcher.PlayerID, RoomID = room.Id, Key = playerJoinRoomRE.Key }); }
/// <summary> /// 加入房间 /// </summary> /// <param name="self"></param> /// <param name="room"></param> /// <param name="matcher"></param> public static async void JoinRoom(this MatchComponent self, Room room, Matcher matcher) { //玩家加入房间,移除匹配队列 self.Playing[matcher.UserID] = room.Id; self.MatchSuccessQueue.Enqueue(matcher); //向房间服务器发送玩家进入请求 ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(room.Id); Actor_PlayerEnterRoom_Ack actor_PlayerEnterRoom_Ack = await actorProxy.Call(new Actor_PlayerEnterRoom_Req() { PlayerID = matcher.PlayerID, UserID = matcher.UserID, SessionID = matcher.GateSessionID }) as Actor_PlayerEnterRoom_Ack; Gamer gamer = GamerFactory.Create(matcher.PlayerID, matcher.UserID, actor_PlayerEnterRoom_Ack.GamerID); room.Add(gamer); //向玩家发送匹配成功消息 ActorProxyComponent actorProxyComponent = Game.Scene.GetComponent <ActorProxyComponent>(); ActorProxy gamerActorProxy = actorProxyComponent.Get(gamer.PlayerID); gamerActorProxy.Send(new Actor_MatchSucess_Ntt() { GamerID = gamer.Id }); }
public void GetFoodTest() { //expected Dog dog = new Dog("Вовкодав", "ч"); Room room = new Room(); room.Add(dog); RoomStub roomStub = new RoomStub(); room.room = roomStub; double expexted = 9.0; Mock.Arrange(() => dog.dailyFood).Returns(0.9); Mock.Arrange(() => roomStub.GetFood()).Returns(8.1); // actual double actual = room.GetFood(); Assert.AreEqual(expexted, actual); // Кімната для тестування виклику з вольєра. double expectedVolary = 11.0; Room room1 = new Room(); Volary volary = new Volary(); room1.volary = volary; Mock.Arrange(() => volary.GetFood()).Returns(expectedVolary); double actualVolary = room1.GetFood(); Assert.AreEqual(expectedVolary, actualVolary); }
public static Room AddRoom(string description, TicketType ticketType) { Room newRoom = Room.Add(description, ticketType, false); Rooms.Add(newRoom.Id, newRoom); NotifyRoomsChanged(); return(newRoom); }
public void Render(Room room) { if (IsRendered == false) { IsRendered = true; foreach (Drawable obj in Objects) { room.Add(obj); } } }
public bool AddSocket(WebSocket s, int user_id, int roomNumber) { if (RoomExists(roomNumber)) { Room room = FindRoom(roomNumber); room.Add(s, user_id); return(true); } Console.WriteLine("Room {0} does not exist. Could not AddSocket.", roomNumber); return(false); }
public static void Main() { Stack <UndoMemento> undoList = new Stack <UndoMemento>(); Console.WriteLine("------------ Initial Condition -------------"); Hall hall = new Hall(); Room room1 = new Room("room1", 10, 10, 100, 100); hall.Add(room1); Room room2 = new Room("room2", 150, 150, 200, 200); hall.Add(room2); Computer computer1 = new Computer("computer1", 1, 1, 5, 5, "Desktop"); room1.Add(computer1); Table table1 = new Table("table1", 10, 10, 7, 7); room1.Add(table1); hall.Draw(); Console.WriteLine("\n-------- 1. Hit enter to change Computer Position ---------"); Console.ReadLine(); undoList.Push(computer1.changePosition(20, 20)); hall.Draw(); Console.WriteLine("\n-------- 2. Hit enter to change Computer Size ---------"); Console.ReadLine(); undoList.Push(computer1.ChangeSize(8, 8)); hall.Draw(); Console.WriteLine("\n-------- 3. Hit enter to change Table Size ---------"); Console.ReadLine(); undoList.Push(table1.ChangeSize(50, 50)); hall.Draw(); computer1.ChangeType("Laptop"); Console.WriteLine("\n------- Hit enter to undo list change ----------"); while (undoList.Count > 0) { Console.ReadLine(); var memento = undoList.Pop(); //memento.Command(memento.State); hall.Draw(); Console.WriteLine("\n------- Hit enter to undo list change ----------"); } Console.ReadLine(); Console.WriteLine("No items left to be undone"); Console.ReadLine(); }
public static void Initialize(Interfaces.ISiqiServer server) { for (int i = 0; i < 20; i++) { string id= (i+1).ToString(); Room room = new Room(id,"游戏房间"+id); for (int k = 0; k < 50; k++) { string deskid = (k + 1).ToString(); room.Add(new Desk(deskid, deskid, 4)); } server.Add(room); } }
/// <summary> /// 加入房间 /// </summary> public static void JoinRoom(this RoomComponent self, Room room, Gamer gamer) { if (gamer == null) { return; } room.Add(gamer); //房间广播 Log.Info($"玩家{gamer.UserId}进入房间"); //向Gate发送消息,玩家进入地图房间 // ... // 向玩家客户端发送消息进入游戏地图 // ... }
/// <summary> /// 加入房间 /// </summary> public static void JoinRoom(this LandMatchComponent self, Room room, Gamer gamer) { //玩家可能掉线 if (gamer == null) { return; } //玩家加入房间 成为已经进入房间的玩家 //绑定玩家与房间 以后可以通过玩家UserID找到所在房间 self.Waiting[gamer.UserID] = room; //为玩家添加座位 room.Add(gamer); //房间广播 Log.Info($"玩家{gamer.UserID}进入房间"); Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt(); foreach (Gamer _gamer in room.gamers) { if (_gamer == null) { //添加空位 broadcastMessage.Gamers.Add(new GamerInfo()); continue; } //添加玩家信息 //GamerInfo info = new GamerInfo() { UserID = _gamer.UserID, IsReady = room.IsGamerReady(gamer) }; GamerInfo info = new GamerInfo() { UserID = _gamer.UserID }; broadcastMessage.Gamers.Add(info); } //广播房间内玩家消息 每次有人进入房间都会收到一次广播 room.Broadcast(broadcastMessage); //向Gate上的User发送匹配成功 //ActorMessageSender actorProxy = Game.Scene.GetComponent<ActorMessageSenderComponent>().Get(gamer.GActorID); //actorProxy.Send(new Actor_MatchSucess_M2G() { GamerID = gamer.InstanceId }); Session GetGateSession = MapHelper.GetGateSession(); GetGateSession.Send(new T_MatchSucess_M2G() { UserID = gamer.UserID, GamerID = gamer.InstanceId }); }
public void AddTest() { // expected int expectedCarnivores = 3; int expectedDog = 1; int expectedCat = 1; string expectedHorse = "Цю тварину неможливо заселити у кімнату!"; Lion lion = new Lion("Боніфацій", "ч"); Tiger tiger = new Tiger("Шерхан", "ч"); Wolf wolf = new Wolf("Вова", "ч"); Dog dog = new Dog("Сірко", "ч"); Cat cat = new Cat("Мурзик", "ч"); Horse horse = new Horse("Ромашка", "ж"); Room room = new Room(); int actualCarnivores = 0; int actualCat = 0; int actualDog = 0; Mock.NonPublic.Arrange(room, "AddCarnivore", new object[1] { lion }).DoInstead(() => ++ actualCarnivores); Mock.NonPublic.Arrange(room, "AddCarnivore", new object[1] { tiger }).DoInstead(() => ++ actualCarnivores); Mock.NonPublic.Arrange(room, "AddCarnivore", new object[1] { wolf }).DoInstead(() => ++ actualCarnivores); Mock.NonPublic.Arrange(room, "AddDog", new object[1] { dog }).DoInstead(() => ++ actualDog); Mock.NonPublic.Arrange(room, "AddCat", new object[1] { cat }).DoInstead(() => ++ actualCat); //actual room.Add(lion); room.Add(tiger); room.Add(wolf); room.Add(cat); room.Add(dog); string actualHorse = room.Add(horse); Assert.AreEqual(expectedCarnivores, actualCarnivores); Assert.AreEqual(expectedCat, actualCat); Assert.AreEqual(expectedDog, actualDog); Assert.AreEqual(expectedHorse, actualHorse); }
public void CallTest() { //expected Room room = new Room(); room.BuildVolary(); RoomStub roomStub = new RoomStub(); room.room = roomStub; List <string> expectedVolary = new List <string> { "expectedVolary" }; List <string> expectedList = new List <string>() { "expectedList" }; Mock.Arrange(() => room.volary.Call()).Returns(expectedVolary); Mock.Arrange(() => roomStub.Call()).Returns(expectedList); // actual List <string> list = room.Call(); Assert.AreEqual(expectedList[0], list[0]); Assert.AreEqual(expectedVolary[0], list[1]); // Інша кімната без вольєрів. string expected = "expected"; Room room1 = new Room(); Dog dog = new Dog("Джекпот", "ч"); room1.Add(dog); Mock.Arrange(() => dog.Voice()).Returns(expected); List <string> list1 = room1.Call(); Assert.AreEqual(expected, list1[0]); }
protected async ETVoid RunAsync(Session session, C2G_EnterRoom message, Action <G2C_EnterRoom> reply) { G2C_EnterRoom response = new G2C_EnterRoom(); try { RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Player player = session.GetComponent <SessionPlayerComponent>().Player; Room room = roomComponent.Get(message.RoomId); if (room == null) { Log.Error($"不存在房间{message.RoomId}"); response.Error = ErrorCode.ERR_RpcFail; } if (room.Add(player) == null) { Log.Error($"房间已满,或者玩家{player.UserDB.GetComponent<UserBaseComponent>().UserName}已经存在房间{room.RoomName}中"); response.Error = ErrorCode.ERR_RpcFail; } room.BroadcastRoomDetailInfo(); BroadcastMessage.Send_G2C_Rooms(); await ETTask.CompletedTask; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public void GenerateRooom() { for (int x = 0; x < 7; x++) { for (int i = 0; i < 3; i++) { if (x == 0) { NpcChances["e"] = 0; } else { NpcChances["e"] = eliteChance; } WeightChanceExecutor weightChanceExecutor = new WeightChanceExecutor( new WeightedChanceParam(() => { Room.Add(new RoomWayPoints(x, i), "m"); }, NpcChances["m"]), new WeightedChanceParam(() => { Room.Add(new RoomWayPoints(x, i), "?"); }, NpcChances["?"]), new WeightedChanceParam(() => { Room.Add(new RoomWayPoints(x, i), "e"); }, NpcChances["e"]), new WeightedChanceParam(() => { Room.Add(new RoomWayPoints(x, i), "s"); }, NpcChances["s"])); weightChanceExecutor.Execute(); } } Room.Add(new RoomWayPoints(7, 0), "b"); }
public void InitializeRoom(string filenm) { ReadPuzzleInputFile rf = new ReadPuzzleInputFile(); var inputFile = rf.ReadFile(filenm); RowOfSeats new_row; // build a waiting room... var r = 0; var c = 0; foreach (var line in inputFile) { new_row = new RowOfSeats(); char[] s = line.ToCharArray(); foreach (var ch in s) { var new_seat = new Seat(r, c); new_seat.State = ch; //if (ch != 'L' || ch != '#' || ch != '.') //{ // throw new ArgumentOutOfRangeException(); //} new_row.ARowOfSeats.Add(new_seat); c++; } Room.Add(new_row); r++; c = 0; } ; HasChanged = false; Console.WriteLine($"Read input file. {rf.LinesRead} lines read in."); return; }
protected override async void Run(Session session, C2G_CowCowCreateGameRoomGate message, Action <G2C_CowCowCreateGameRoomGate> reply) { G2C_CowCowCreateGameRoomGate response = new G2C_CowCowCreateGameRoomGate(); try { UserInfo userInfo = Game.Scene.GetComponent <UserInfoComponent>().Get(message.UserID); if (userInfo.Diamond < message.Bureau) { response.Error = ErrorCode.ERR_CreateRoomError; response.Message = "房卡不足"; reply(response); return; } userInfo.Diamond -= (message.Bureau + 1); string roomId = string.Empty; while (true) { roomId = RandomHelper.RandomNumber(100000, 999999).ToString(); if (!Game.Scene.GetComponent <RoomComponent>().IsExist(roomId)) { break; } } Room room = ComponentFactory.Create <Room>(); room.UserID = message.UserID; room.RoomID = roomId; room.GameName = message.Name; room.Bureau = GameInfo.Bureau[message.Bureau]; room.RuleBit = message.RuleBit; room.PeopleCount = message.People; room.CurBureau = 0; Game.Scene.GetComponent <RoomComponent>().Add(room); Gamer gamer = GamerFactory.Create(message.UserID, session.InstanceId); await gamer.AddComponent <MailBoxComponent>().AddLocation(); gamer.UserID = message.UserID; gamer.Name = "房主" + userInfo.NickName; gamer.HeadIcon = userInfo.HeadIcon; gamer.RoomID = room.RoomID; gamer.Status = GamerStatus.Down; gamer.IsOffline = false; gamer.Identity = Identity.None; gamer.Coin = 0; gamer.Sex = userInfo.Sex; room.Add(gamer); Game.Scene.GetComponent <RoomComponent>().Add(gamer.UserID, room.RoomID); response.GameName = room.GameName; response.Bureau = room.Bureau; response.RuleBit = room.RuleBit; response.RoomID = room.RoomID; response.People = room.PeopleCount; //根据UserID从数据库拿到该用户信息并返回 response.GamerInfo = new GamerInfo(); response.GamerInfo.Name = gamer.Name; response.GamerInfo.HeadIcon = gamer.HeadIcon; response.GamerInfo.UserID = gamer.UserID; //这个ID用于保存?待定 response.GamerInfo.SeatID = gamer.SeatID; response.GamerInfo.Sex = gamer.Sex; response.GamerInfo.Status = (int)gamer.Status; response.GamerInfo.Coin = gamer.Coin; response.CurBureau = room.CurBureau; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public static void Add(Room room) { room.Add(); }
public ActionResult Add(Room u) { u.Add(); return(View()); }
protected override async ETTask Run(Session session, CreateUnit_G2M message) { // 查询玩家角色信息中是否已有地图与位置坐标数据 // ... Unit unit = ComponentFactory.CreateWithId <Unit>(IdGenerater.GenerateId()); unit.GActorId = message.GActorId; unit.CActorId = message.CActorId; unit.Position = new Vector3(-10, 0, -10); // 给unit添加unit状态组件与角色移动组件 unit.AddComponent <UnitStateComponent>(); unit.AddComponent <CharacterMoveComponent>(); // unit添加到UnitComponet,添加MailBoxComponent await unit.AddComponent <MailBoxComponent>().AddLocation(); Game.Scene.GetComponent <UnitComponent>().Add(unit); //创建地图房间的玩家,用UserID构建Gamer Gamer gamer = ComponentFactory.Create <Gamer, long>(message.UserId); gamer.GActorId = message.GActorId; gamer.CActorId = message.CActorId; // 更新gamer的UnitId gamer.UnitId = unit.Id; gamer.CharaId = message.CharaId; //为Gamer添加组件 await gamer.AddComponent <MailBoxComponent>().AddLocation(); //更新网关user的ActorID ActorMessageSender actorProxy = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(gamer.GActorId); actorProxy.Send(new Actor_EnterMapSucess_M2G() { GamerId = gamer.InstanceId, UnitId = unit.Id }); // 将gamer添加到地图房间 RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.GetMapRoom(1001); // 暂时用黎明镇的地图编号 room.Add(gamer); unit.gamer = gamer; unit.room = room; // 广播创建的units CreateUnits_M2C createUnits = new CreateUnits_M2C(); Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); foreach (Unit u in units) { UnitInfo unitInfo = new UnitInfo(); unitInfo.X = u.Position.x; unitInfo.Y = u.Position.y; unitInfo.Z = u.Position.z; unitInfo.UnitId = u.Id; unitInfo.UserId = u.gamer.UserId; unitInfo.CharaId = u.gamer.CharaId; createUnits.Units.Add(unitInfo); } // 应该是只向玩家可见范围的其它玩家广播,目前还没实现暂时向整个地图房间广播 room.Broadcast(createUnits); }
public void Initialise(Room room) { room.Add(this); transform.GetChild(0).GetComponent <Renderer> ().material = room.Settings.FloorMaterial; }
public void Init() { _player = new Player(new Vector2(TileSize.Int * 12, TileSize.Int * 7)); _room = new Room(); _room.Add(new TileWalker(0, 16, 0, 16).Get(x => new Tile("tile1", x, Rotation.Up, false))); //_room.Add(new TileWalker(0, 1, 0, 20).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(0, 28, 0, 1).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(17, 11, 0, 20).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(0, 28, 17, 3).Get(x => new Tile("ext1", x, Rotation.Up))); _room.Add(new TileWalker(2, 12, 0, 1).Get(x => new Wall(Rotation.Up, x))); _room.Add(new TileWalker(0, 1, 2, 12).Get(x => new Wall(Rotation.Left, x))); _room.Add(new TileWalker(14, 1, 2, 5).Get(x => new Wall(Rotation.Right, x))); _room.Add(new TileWalker(14, 1, 9, 5).Get(x => new Wall(Rotation.Right, x))); _room.Add(new TileWalker(2, 12, 14, 1).Get(x => new Wall(Rotation.Down, x))); _room.Add(new TileWalker(0, 1, 0, 1).Get(x => new WallCorner(Rotation.Up, x))); _room.Add(new TileWalker(0, 1, 14, 1).Get(x => new WallCorner(Rotation.Left, x))); _room.Add(new TileWalker(11, 1, 0, 1).Get(x => new PitCorner(Rotation.Right, x, _player))); _room.Add(new TileWalker(11, 1, 11, 1).Get(x => new PitCorner(Rotation.Down, x, _player))); _room.Add(new TileWalker(3, 8, 2, 1).Get(x => new Tile("walledge", x, Rotation.Up))); _room.Add(new TileWalker(2, 1, 3, 10).Get(x => new Tile("walledge", x, Rotation.Left))); _room.Add(new TileWalker(13, 1, 5, 6).Get(x => new Tile("walledge", x, Rotation.Right))); _room.Add(new TileWalker(3, 8, 13, 1).Get(x => new Tile("walledge", x, Rotation.Down))); _room.Add(new TileWalker(2, 1, 2, 1).Get(x => new Tile("walledgecorner", x, Rotation.Up))); _room.Add(new TileWalker(2, 1, 13, 1).Get(x => new Tile("walledgecorner", x, Rotation.Left))); _room.Add(new TileWalker(11, 1, 2, 3).Get(x => new Tile("bottomlessedge", x, Rotation.Right))); _room.Add(new TileWalker(11, 1, 11, 3).Get(x => new Tile("bottomlessedge", x, Rotation.Right))); _room.Add(new TileWalker(11, 3, 4, 1).Get(x => new Tile("bottomlessedge", x, Rotation.Up))); _room.Add(new TileWalker(11, 3, 11, 1).Get(x => new Tile("bottomlessedge", x, Rotation.Down))); _room.Add(new Obj("chest-closed", new TileLocation(2, 7))); _room.Add(new Door(DoorState.Open, new TileLocation(14, 7), Rotation.Right, "MainHallRoom", _player)); }
protected override async void Run(Session session, C2G_CowCowJoinGameRoomGate message, Action <G2C_CowCowJoinGameRoomGate> reply) { G2C_CowCowJoinGameRoomGate response = new G2C_CowCowJoinGameRoomGate(); try { Log.WriteLine($"Session:{session.Id},userId:{message.UserID}"); UserInfo userInfo = Game.Scene.GetComponent <UserInfoComponent>().Get(message.UserID); Room room = Game.Scene.GetComponent <RoomComponent>().Get(message.RoomID); if (room == null) { response.Error = ErrorCode.ERR_NotRoomNumberError; response.Message = "房间号不存在"; reply(response); return; } //超过七个人 if (room.GamerCount >= room.PeopleCount) { response.Error = ErrorCode.ERR_RoomPeopleFullError; response.Message = "房间人已满"; reply(response); return; } response.GameName = room.GameName; response.Bureau = room.Bureau; response.RuleBit = room.RuleBit; response.RoomID = room.RoomID; response.CurBureau = room.CurBureau; Gamer gamer = GamerFactory.Create(message.UserID, session.InstanceId); await gamer.AddComponent <MailBoxComponent>().AddLocation(); gamer.UserID = message.UserID; //玩家账号 gamer.Name = "闲家" + userInfo.NickName; gamer.HeadIcon = userInfo.HeadIcon; gamer.Sex = userInfo.Sex; gamer.Coin = 0; gamer.RoomID = room.RoomID; gamer.Status = GamerStatus.Down; gamer.IsOffline = false; gamer.Identity = Identity.None; room.Add(gamer); Game.Scene.GetComponent <RoomComponent>().Add(gamer.UserID, room.RoomID); Dictionary <int, Gamer> gamers = room.GetAll(); Actor_CowCowJoinGameRoomGroupSend allGamer = new Actor_CowCowJoinGameRoomGroupSend(); allGamer.LocalGamerInfo = new GamerInfo(); allGamer.LocalGamerInfo.Coin = gamer.Coin; allGamer.LocalGamerInfo.Name = gamer.Name; allGamer.LocalGamerInfo.HeadIcon = gamer.HeadIcon; allGamer.LocalGamerInfo.SeatID = gamer.SeatID; allGamer.LocalGamerInfo.Sex = gamer.Sex; allGamer.LocalGamerInfo.Status = (int)gamer.Status; allGamer.LocalGamerInfo.UserID = gamer.UserID; allGamer.GamerInfo = new RepeatedField <GamerInfo>(); foreach (Gamer g in gamers.Values) { GamerInfo gamerInfo = new GamerInfo(); gamerInfo.Coin = g.Coin; gamerInfo.Name = g.Name; gamerInfo.HeadIcon = g.HeadIcon; gamerInfo.SeatID = g.SeatID; gamerInfo.Sex = g.Sex; gamerInfo.Status = (int)g.Status; gamerInfo.UserID = g.UserID; allGamer.GamerInfo.Add(gamerInfo); } reply(response); room.Broadcast(allGamer); } catch (Exception e) { ReplyError(response, e, reply); } }
public void Init() { World.PlayMusic("Music/dungeon1"); _player = new Player(new Vector2(TileSize.Int * 2, TileSize.Int * 7)); _room = new Room(); _room.Add(new TileWalker(0, 14, 0, 16).Get(x => new Tile("tile1", x, Rotation.Up))); //_room.Add(new TileWalker(0, 1, 0, 20).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(0, 28, 0, 1).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(17, 11, 0, 20).Get(x => new Tile("ext1", x, Rotation.Up))); //_room.Add(new TileWalker(0, 28, 17, 3).Get(x => new Tile("ext1", x, Rotation.Up))); _room.Add(new TileWalker(2, 10, 0, 1).Get(x => new Wall(Rotation.Up, x))); _room.Add(new TileWalker(0, 1, 2, 5).Get(x => new Wall(Rotation.Left, x))); _room.Add(new TileWalker(0, 1, 9, 5).Get(x => new Wall(Rotation.Left, x))); _room.Add(new TileWalker(12, 1, 2, 12).Get(x => new Wall(Rotation.Right, x))); _room.Add(new TileWalker(2, 10, 14, 1).Get(x => new Wall(Rotation.Down, x))); _room.Add(new TileWalker(0, 1, 0, 1).Get(x => new WallCorner(Rotation.Up, x))); _room.Add(new TileWalker(0, 1, 14, 1).Get(x => new WallCorner(Rotation.Left, x))); _room.Add(new TileWalker(12, 1, 0, 1).Get(x => new WallCorner(Rotation.Right, x))); _room.Add(new TileWalker(12, 1, 14, 1).Get(x => new WallCorner(Rotation.Down, x))); _room.Add(new TileWalker(3, 8, 2, 1).Get(x => new Tile("walledge", x, Rotation.Up))); _room.Add(new TileWalker(2, 1, 3, 10).Get(x => new Tile("walledge", x, Rotation.Left))); _room.Add(new TileWalker(11, 1, 3, 10).Get(x => new Tile("walledge", x, Rotation.Right))); _room.Add(new TileWalker(3, 8, 13, 1).Get(x => new Tile("walledge", x, Rotation.Down))); _room.Add(new TileWalker(2, 1, 2, 1).Get(x => new Tile("walledgecorner", x, Rotation.Up))); _room.Add(new TileWalker(2, 1, 13, 1).Get(x => new Tile("walledgecorner", x, Rotation.Left))); _room.Add(new TileWalker(11, 1, 2, 1).Get(x => new Tile("walledgecorner", x, Rotation.Right))); _room.Add(new TileWalker(11, 1, 13, 1).Get(x => new Tile("walledgecorner", x, Rotation.Down))); _room.Add(new TileWalker(11, 1, 12, 2).Get(x => new Tile("itemplatform", x, Rotation.Up))); _room.Add(new TileWalker(11, 1, 12, 2).Get(x => new Obj("pot", x))); _room.Add(new Obj("chest-closed", new TileLocation(11, 2))); _room.Add(new Door(DoorState.Open, new TileLocation(0, 7), Rotation.Left, "MainHallRoom", _player)); _enemies.Add(new SpearEnemy(_player, new TileLocation(7, 7), new List <TileLocation> { new TileLocation(4, 7), new TileLocation(7, 7) })); }
protected override async void Run(Session session, C2G_CreateRoom message, Action <G2C_CreateRoom> reply) { G2C_CreateRoom response = new G2C_CreateRoom(); try { //验证合法性 if (!GateHelper.SignSession(session)) { response.Error = ErrorCode.ERR_SignError; reply(response); return; } DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>(); User user = session.GetUser(); UserInfo userInfo = await dbProxy.Query <UserInfo>(user.UserID, false); if (userInfo.Money < message.Room.GameScore) { response.Error = ErrorCode.ERR_UserMoneyLessError; reply(response); return; } //创建房间 Room room = await RoomFactory.Create(message.Room.PlayerCount, message.Room.GameCount, message.Room.GameScore, session); //创建房间玩家对象 Gamer gamer = GamerFactory.Create(user.Id, user.UserID, room.RoomId, (ushort)room.Count); await gamer.AddComponent <MailBoxComponent>().AddLocation(); gamer.AddComponent <UnitGateComponent, long>(session.Id); //房间添加玩家 room.Add(gamer); //网关服务器和玩家对应 user.ActorID = gamer.Id; //返回房间信息给玩家 response.RoomId = room.RoomId; response.Room = message.Room; response.ChairID = (ushort)(room.Count - 1); Log.Info($"创建房间成功:--- {userInfo.NickName} ,房号:{room.RoomId}"); //返回给客户端 reply(response); //存储该用户房间的创建次数 RoomHistory roomInfo = await dbProxy.Query <RoomHistory>(user.UserID, false); if (roomInfo == null) { RoomHistory roomHistory = ComponentFactory.CreateWithId <RoomHistory>(userInfo.Id); roomHistory.CreateCount = 1; roomHistory.NickName = userInfo.NickName; await dbProxy.Save(roomHistory, false); } else { roomInfo.CreateCount += 1; await dbProxy.Save(roomInfo, false); } //连接游戏服务器 //StartConfigComponent config = Game.Scene.GetComponent<StartConfigComponent>(); //IPEndPoint GameIPEndPoint= config.GameConfig.GetComponent<InnerConfig>().IPEndPoint; //Session GameSession = Game.Scene.GetComponent<NetInnerComponent>().Get(GameIPEndPoint); //GS2G_EnterRoom gs2g_EnterRoom =await GameSession.Call(new G2GS_EnterRoom() //{ // PlayerId = user.Id, // UserID = user.UserID, // GateSessionId = session.Id //}) as GS2G_EnterRoom; } catch (Exception e) { ReplyError(response, e, reply); } }
private Room GrowCity(CityPlacementInfo info) { Point start = info.GetCityCenter(); int size = info.size; Room room = new Room(); Point blockSize = new Point(4, 6); int blockCount = 0; Point origin = start; //when start tile is not flat, search around it for a flat one if (!GetTile(origin).AllHeightsAreSame() || GetTile(origin).type == TileType.Water) { for (int x = -2; x <= 2 && origin == start; x++) { for (int y = -2; y < 2; y++) { if (IsInRange(x, y) && tiles[x, y].AllHeightsAreSame() && GetTile(origin).type != TileType.Water) { origin = new Point(x, y); break; } } } } if (tiles[origin.X, origin.Y].type == TileType.Water) { return(null); } Queue <Intersection> intersections = new Queue <Intersection>(64); intersections.Enqueue(new Intersection(origin, true, true, true, true)); const int ROAD_STEPS_MIN = 3; const int ROAD_STEPS_MAX = 5; Direction[] directions = { Direction.Up, Direction.Right, Direction.Down, Direction.Left }; double levelThree = GetPercentageOfCitizenLevel(DistrictType.Business); double levelOne = GetPercentageOfCitizenLevel(DistrictType.Suburb); bool leftRightIsShort = random.NextDouble() > 0.5 ? true : false; /* * Direction <-> axis * * up: -y * down: y * left: -x * right: x * */ while (intersections.Count > 0 && blockCount < size) { Intersection curr = intersections.Dequeue(); Point pos = curr.pos; if (!IsInRange(pos)) { continue; } tiles[pos.X, pos.Y].type = TileType.Road; foreach (Direction d in directions) { if (!curr.HasDirection(d)) { continue; } int steps = ROAD_STEPS_MIN; if (leftRightIsShort && (d == Direction.Left || d == Direction.Right)) { steps = ROAD_STEPS_MIN; } else if (!leftRightIsShort && (d == Direction.Right || d == Direction.Down)) { steps = ROAD_STEPS_MIN; } else { steps = random.Next(ROAD_STEPS_MIN, ROAD_STEPS_MAX + 1); } Point p = pos; //check if the same direction already has roads on neighbouring tiles. switch (d) { case Direction.Up: p.Y -= 1; break; case Direction.Right: p.X += 1; break; case Direction.Down: p.Y += 1; break; case Direction.Left: p.X -= 1; break; } if (DirectionNeighbourIsRoad(p, d)) { continue; } p = pos; for (int i = 0; i < steps; i++) { switch (d) { case Direction.Up: p.Y -= 1; break; case Direction.Right: p.X += 1; break; case Direction.Down: p.Y += 1; break; case Direction.Left: p.X -= 1; break; } if (!IsInRange(p) || !tiles[p.X, p.Y].IsRoadPlaceable(false)) { p = new Point(-1, -1); break; } foreach (Point n in DirectionalNeighbours(p, d)) { if (GetTile(n).IsHousePlaceable()) { Tile t = GetTile(n); t.type = TileType.House; t.SetCitizenLevel(DistrictType.Suburb); t.onTopIndex = param.tileset.GetRandomHouseIndex(DistrictType.Suburb, random); blockCount++; room.Add(n); } } if (i == steps - 1 && !GetTile(p).AllHeightsAreSame()) { continue; } room.Add(p); tiles[p.X, p.Y].type = TileType.Road; blockCount++; } if (!IsInRange(p) || !GetTile(p).AllHeightsAreSame()) { continue; } double dirProb = 0.75; double[] newDirsProbabilities = { dirProb, dirProb, dirProb, dirProb }; //dont move back from where we came. switch (d) { case Direction.Up: newDirsProbabilities[2] = 0.0; break; case Direction.Right: newDirsProbabilities[3] = 0.0; break; case Direction.Down: newDirsProbabilities[0] = 0.0; break; case Direction.Left: newDirsProbabilities[1] = 0.0; break; } intersections.Enqueue(new Intersection(p, newDirsProbabilities, random)); //intersections.Enqueue(new Intersection(p, random.NextDouble() < dirProb, random.NextDouble() < dirProb, random.NextDouble() < dirProb, random.NextDouble() < dirProb)); } } return(room); }