public void recieveFromClient(string message, String playerGuid) { Player PlayerData; Room RoomData; _PlayerCache.TryGetValue(playerGuid, out PlayerData); var room = new Tuple <string, string, int>(PlayerData.Region, PlayerData.Area, PlayerData.AreaId); if (_AreaCache.TryGetValue(room, out RoomData)) { _AreaCache.TryGetValue(room, out RoomData); } else { var RoomLoadData = new LoadRoom { Region = PlayerData.Region, Area = PlayerData.Area, id = PlayerData.AreaId }; RoomData = RoomLoadData.LoadRoomFile(); _AreaCache.TryAdd(room, RoomData); } HubContext.Instance.SendToClient("<p style='color:#999'>" + message + "<p/>", PlayerData.HubGuid); Command.ParseCommand(message, PlayerData, RoomData); }
public string ReturnRoom(string id) { Player player; if (_PlayerCache.TryGetValue(id, out player)) { string room = string.Empty; var roomJSON = new LoadRoom(); roomJSON.Region = player.Region; roomJSON.Area = player.Area; roomJSON.id = player.AreaId; Room roomData; var findRoomData = new Tuple <string, string, int>(roomJSON.Region, roomJSON.Area, roomJSON.id); if (_AreaCache.TryGetValue(findRoomData, out roomData)) { room = LoadRoom.DisplayRoom(roomData, player.Name); } else { roomData = roomJSON.LoadRoomFile(); _AreaCache.TryAdd(findRoomData, roomData); room = LoadRoom.DisplayRoom(roomData, player.Name); } return(room); } return(null); }
public static void EnterRoom(Player player, Room room, string direction = "", bool teleported = false) { var directionOrigin = oppositeDirection(direction, true); for (int i = 0; i < room.players.Count; i++) { if (teleported == false) { string name = Helpers.ReturnName(player, room.players[i], string.Empty); string movement = "walks in "; // runs, hovers, crawls. Steps out of a portal, appears? if (player.Affects?.FirstOrDefault( x => x.Name.Equals("Fly", StringComparison.CurrentCultureIgnoreCase)) != null) { movement = "floats in "; } direction = oppositeDirection(direction, false); string enterText = name + " " + movement + direction; if (player.HubGuid != null) { if (player.Name != room.players[i].Name) { HubContext.getHubContext.Clients.Client(room.players[i].HubGuid) .addNewMessageToPage(enterText); } else { if (player.Status == Player.PlayerStatus.Standing) { if (player.Affects?.FirstOrDefault( x => x.Name.Equals("Fly", StringComparison.CurrentCultureIgnoreCase)) != null) { enterText = "You float in " + direction; } else { enterText = "You walk in " + direction; } HubContext.getHubContext.Clients.Client(room.players[i].HubGuid) .addNewMessageToPage(enterText); } } var roomdata = LoadRoom.DisplayRoom(room, room.players[i].Name); Score.UpdateUiRoom(room.players[i], roomdata); } else { if (room.players[i].HubGuid != null) { HubContext.SendToClient(enterText, room.players[i].HubGuid); } } } } }
public static Room getRoom(string playerId) { Player player; if (_PlayerCache.TryGetValue(playerId, out player)) { var RoomData = new LoadRoom { Region = player.Region, Area = player.Area, id = player.AreaId }; Room getRoomData = null; if (_AreaCache.TryGetValue(RoomData.id, out getRoomData)) { return(getRoomData); } else { getRoomData = RoomData.LoadRoomFile(); _AreaCache.TryAdd(RoomData.id, getRoomData); return(getRoomData); } } return(null); }
private void OnGUI() { minSize = new Vector2(300, 200); maxSize = minSize; EditorGUILayout.Space(); EditorGUILayout.LabelField("ROOM EDITOR", _style2); EditorGUILayout.Space(); EditorGUI.DrawRect(GUILayoutUtility.GetRect(100, 2), Color.black); bool createRoom = GUI.Button(new Rect(75, 50, 150, 50), "Create a Room"); if (createRoom) { RoomConfigEditor roomConfig = (RoomConfigEditor)GetWindow(typeof(RoomConfigEditor)); roomConfig.Show(); roomConfig.nameRoom = "New Room"; roomConfig.normal = 25; roomConfig.traps = 25; roomConfig.enemies = 25; roomConfig.difficulty = 25; RoomConfigEditor.sizeImage = Vector2.one * 5; Close(); } bool loadRoom = GUI.Button(new Rect(75, 110, 150, 50), "Load Room"); if (loadRoom) { LoadRoom roomLoader = (LoadRoom)GetWindow(typeof(LoadRoom)); roomLoader.Show(); Close(); } }
public static void ExitRoom(Player player, Room room, string direction) { for (int i = 0; i < room.players.Count; i++) { string name = Helpers.ReturnName(player, room.players[i], string.Empty); string movement = "walks "; // runs, hovers, crawls. Steps out of a portal, appears? if (player.Affects?.FirstOrDefault( x => x.Name.Equals("Fly", StringComparison.CurrentCultureIgnoreCase)) != null) { movement = "floats "; } string exitDir = direction; // string prevDirection = "South"; string exitText = name + " " + movement + exitDir; if (player.Name != room.players[i].Name) { HubContext.getHubContext.Clients.Client(room.players[i].HubGuid).addNewMessageToPage(exitText); } else { exitText = "You walk " + direction; if (player.Affects?.FirstOrDefault( x => x.Name.Equals("Fly", StringComparison.CurrentCultureIgnoreCase)) != null) { exitText = "You float " + direction; } HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(exitText); } var roomdata = LoadRoom.DisplayRoom(room, room.players[i].Name); Score.UpdateUiRoom(room.players[i], roomdata); } if (player.Followers != null && player.Followers.Count > 0) { foreach (var follower in player.Followers.ToList()) { HubContext.SendToClient(Helpers.ReturnName(follower, player, string.Empty) + " follows you " + direction, player.HubGuid); HubContext.SendToClient("You follow " + Helpers.ReturnName(player, follower, string.Empty) + " " + direction, follower.HubGuid); if (follower.HubGuid == null) { Movement.MobMove(follower, player, room, direction); } else { Command.ParseCommand(direction, follower, room); } } } player.MovePoints -= 1; Score.UpdateUiPrompt(player); }
//public static Dictionary<string, Action> commandList { get; set; } public static Dictionary <string, Action> Commands(string commandOptions, string commandKey, PlayerSetup.Player playerData, Room.Room room) { var commandList = new Dictionary <String, Action>(); commandList.Add("north", () => Movement.Move(playerData, room, "North")); commandList.Add("south", () => Movement.Move(playerData, room, "South")); commandList.Add("east", () => Movement.Move(playerData, room, "East")); commandList.Add("west", () => Movement.Move(playerData, room, "West")); commandList.Add("down", () => Movement.Move(playerData, room, "Down")); commandList.Add("up", () => Movement.Move(playerData, room, "Up")); //commandList.Add("look at", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "look")); commandList.Add("look", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "look")); commandList.Add("l in", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "look in")); commandList.Add("look in", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "look in")); commandList.Add("examine", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "examine")); commandList.Add("touch", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "touch")); commandList.Add("smell", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "smell")); commandList.Add("taste", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "taste")); commandList.Add("score", () => Score.ReturnScore(playerData)); commandList.Add("inventory", () => Inventory.ReturnInventory(playerData.Inventory, playerData)); commandList.Add("equipment", () => Equipment.ShowEquipment(playerData)); commandList.Add("garb", () => Equipment.ShowEquipment(playerData)); commandList.Add("get", () => ManipulateObject.GetItem(room, playerData, commandOptions, commandKey, "item")); commandList.Add("take", () => ManipulateObject.GetItem(room, playerData, commandOptions, commandKey, "item")); commandList.Add("drop", () => ManipulateObject.DropItem(room, playerData, commandOptions, commandKey)); commandList.Add("put", () => ManipulateObject.DropItem(room, playerData, commandOptions, commandKey)); commandList.Add("save", () => Save.UpdatePlayer(playerData)); commandList.Add("'", () => Communicate.Say(commandOptions, playerData, room)); commandList.Add("say", () => Communicate.Say(commandOptions, playerData, room)); commandList.Add("sayto", () => Communicate.SayTo(commandOptions, room, playerData)); commandList.Add(">", () => Communicate.SayTo(commandOptions, room, playerData)); commandList.Add("quit", () => HubContext.Quit(playerData.HubGuid, room)); commandList.Add("wear", () => Equipment.WearItem(playerData, commandOptions)); commandList.Add("remove", () => Equipment.RemoveItem(playerData, commandOptions)); commandList.Add("wield", () => Equipment.WearItem(playerData, commandOptions, true)); commandList.Add("unwield", () => Equipment.RemoveItem(playerData, commandOptions, false, true)); commandList.Add("kill", () => Fight2.PerpareToFight(playerData, room, commandOptions)); commandList.Add("flee", () => Flee.fleeCombat(playerData, room)); commandList.Add("unlock", () => ManipulateObject.UnlockItem(room, playerData, commandOptions, commandKey)); commandList.Add("lock", () => ManipulateObject.LockItem(room, playerData, commandOptions, commandKey)); commandList.Add("open", () => ManipulateObject.Open(room, playerData, commandOptions, commandKey)); commandList.Add("close", () => ManipulateObject.Close(room, playerData, commandOptions, commandKey)); commandList.Add("punch", () => Punch.StartPunch(playerData, room)); commandList.Add("help", () => Help.ShowHelp(commandOptions, playerData)); commandList.Add("time", Update.Time.ShowTime); commandList.Add("clock", Update.Time.ShowTime); return(commandList); }
public static void EnterRoom(Player player, Room room, string direction = "") { string name = player.Name; string movement = "walks in"; // runs, hovers, crawls. Steps out of a portal, appears? direction = oppositeDirection(direction); string enterText = name + " " + movement + direction; for (int i = 0; i < room.players.Count; i++) { if (player.Name != room.players[i].Name) { HubContext.getHubContext.Clients.Client(room.players[i].HubGuid).addNewMessageToPage(enterText); } else { if (player.Status == Player.PlayerStatus.Standing) { enterText = "You walk in " + direction; HubContext.getHubContext.Clients.Client(room.players[i].HubGuid).addNewMessageToPage(enterText); } } var roomdata = LoadRoom.DisplayRoom(room, room.players[i].Name); Score.UpdateUiRoom(room.players[i], roomdata); } if (room.EventOnEnter != null) { Event.ParseCommand(room.EventOnEnter, player, null, room); } //NPC Enter event here foreach (var mob in room.mobs) { if (mob.EventOnEnter != null) { Event.ParseCommand(mob.EventOnEnter, player, mob, room); } } }
public static List <Pathfinding> SearchExits(Room.Room room, int destId) { foreach (var exit in room.exits) { if (exit.areaId == destId) { var path1 = new Pathfinding() { Name = exit.name, AreaId = exit.areaId }; list.Add(path1); return(list); } var path = new Pathfinding() { Name = exit.name, AreaId = exit.areaId }; var getRoom = new LoadRoom() { Area = exit.area, id = exit.areaId, Region = exit.region }; list.Add(path); var getNewRoom = getRoom.LoadRoomFile(); if (getNewRoom != null) { SearchExits(getNewRoom, destId); } } return(list); }
public static void ExitRoom(Player player, Room room, string direction) { string name = player.Name; string movement = "walks "; // runs, hovers, crawls. Steps out of a portal, appears? string exitDir = direction; // string prevDirection = "South"; string exitText = name + " " + movement + exitDir; for (int i = 0; i < room.players.Count; i++) { if (player.Name != room.players[i].Name) { HubContext.getHubContext.Clients.Client(room.players[i].HubGuid).addNewMessageToPage(exitText); } else { exitText = "You walk " + direction; HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(exitText); } var roomdata = LoadRoom.DisplayRoom(room, room.players[i].Name); Score.UpdateUiRoom(room.players[i], roomdata); } }
//Create transport method public static void Teleport(Player player, Room room, Exit exit = null) { Room roomData = room; //remove player from old room PlayerManager.RemovePlayerFromRoom(roomData, player); if (exit != null) { //exit message ExitRoom(player, roomData, null, true); } //change player Location if (exit != null) { //change player Location player.Area = exit.area; player.AreaId = exit.areaId; player.Region = exit.region; } else { player.Area = room.area; player.AreaId = room.areaId; player.Region = room.region; } //Get new room try { //Room getNewRoom = await HubProxy.MimHubServer.Invoke<Room>("getRoom", player.HubGuid); Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(player); if (getNewRoom != null) { //add player to new room PlayerManager.AddPlayerToRoom(getNewRoom, player); //enter message EnterRoom(player, getNewRoom, null, true); var roomDescription = LoadRoom.DisplayRoom(getNewRoom, player.Name); if (player.Status != Player.PlayerStatus.Sleeping) { HubContext.Instance.AddNewMessageToPage(player.HubGuid, roomDescription); } //NPC Enter event here foreach (var mob in getNewRoom.mobs) { if (mob.Greet) { Event.ParseCommand("greet", player, mob, getNewRoom); } else { //mob might be aggro } if (mob.MobTalkOnEnter && mob.DialogueTree != null && mob.DialogueTree.Count >= 1) { var speak = mob.DialogueTree[0]; HubContext.Instance.AddNewMessageToPage(player.HubGuid, "<span class='sayColor'>" + mob.Name + " says to you \"" + speak.Message + "\"</span>"); var i = 1; foreach (var respond in speak.PossibleResponse) { var textChoice = "<a class='multipleChoice' href='javascript:void(0)' onclick='$.connection.mIMHub.server.recieveFromClient(\"say " + respond.Response + "\",\"" + player.HubGuid + "\")'>" + i + ". " + respond.Response + "</a>"; HubContext.Instance.AddNewMessageToPage(player.HubGuid, textChoice); i++; } } } ShowUIExits(getNewRoom, player.HubGuid); } } catch (Exception e) { //log error } }
/// <summary> /// /// </summary> /// <param name="player"></param> /// <param name="room"></param> /// <param name="direction"></param> public static void Move(Player player, Room room, string direction) { Stopwatch stopwatch = Stopwatch.StartNew(); if (player.Status == Player.PlayerStatus.Fighting) { HubContext.Instance.SendToClient("You are fighting! Try fleeing.", player.HubGuid); return; } if (player.Status == Player.PlayerStatus.Resting || player.Status == Player.PlayerStatus.Sleeping) { HubContext.Instance.SendToClient("You need to get up before you move.", player.HubGuid); return; } var isBlind = player.Effects?.FirstOrDefault( x => x.Name.Equals("Blindness", StringComparison.CurrentCultureIgnoreCase)) != null; if (player.MovePoints <= 0) { HubContext.Instance.SendToClient("You are exhausted an unable to move", player.HubGuid); foreach (var character in room.players) { if (character != player) { HubContext.Instance.SendToClient( $"{Helpers.ReturnName(player, character, string.Empty)} tries to move but is too exhausted.", player.HubGuid); } } return; } if (player.ActiveSkill != null) { HubContext.Instance.SendToClient("You are too busy to move.", player.HubGuid); return; } if (room.exits == null) { room.exits = new List <Exit>(); } //Find Exit if (room.exits != null) { var exit = room.exits.Find(x => x.name == direction); if (exit != null) { if (exit.open == false) { HubContext.Instance.AddNewMessageToPage(player.HubGuid, "The " + exit.doorName + " is close"); return; } //remove player from old room PlayerManager.RemovePlayerFromRoom(room, player); //exit message ExitRoom(player, room, direction); //change player Location player.Area = exit.area; player.AreaId = exit.areaId; player.Region = exit.region; //Get new room try { //Room getNewRoom = await HubProxy.MimHubServer.Invoke<Room>("getRoom", player.HubGuid); Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(player); if (getNewRoom != null) { //add player to new room PlayerManager.AddPlayerToRoom(getNewRoom, player); //enter message EnterRoom(player, getNewRoom, direction); var roomDescription = LoadRoom.DisplayRoom(getNewRoom, player.Name); if (!isBlind) { HubContext.Instance.AddNewMessageToPage(player.HubGuid, roomDescription); } else { HubContext.Instance.SendToClient("You can't see a thing.", player.HubGuid); } foreach (var mob in getNewRoom.mobs) { if (mob.Greet) { Event.ParseCommand("greet", player, mob, getNewRoom); } if (mob.MobTalkOnEnter && mob.DialogueTree != null && mob.DialogueTree.Count > 0) { var speak = mob.DialogueTree[0]; HubContext.Instance.AddNewMessageToPage(player.HubGuid, "<span class='sayColor'>" + mob.Name + " says to you \"" + speak.Message + "\"</span>"); var i = 1; foreach (var respond in speak.PossibleResponse) { var textChoice = "<a class='multipleChoice' href='javascript:void(0)' onclick='$.connection.mIMHub.server.recieveFromClient(\"say " + respond.Response + "\",\"" + player.HubGuid + "\")'>" + i + ". " + respond.Response + "</a>"; HubContext.Instance.AddNewMessageToPage(player.HubGuid, textChoice); i++; } } if (mob.Aggro) { HubContext.Instance.SendToClient($"{mob.Name} screams and attacks you", player.HubGuid); Player.MobAttack(player, mob, getNewRoom); } if (mob.EventOnEnter != null) { Event.ParseCommand(mob.EventOnEnter, player, mob, room); } foreach (var quest in player.QuestLog.Where(x => x.Completed == false)) { if (quest.QuestHint != null && mob.Name == quest.QuestFindMob) { HubContext.Instance.SendToClient(quest.QuestHint, player.HubGuid); } } } if (!string.IsNullOrEmpty(getNewRoom.EventOnEnter)) { Event.ParseCommand(getNewRoom.EventOnEnter, player, null, room); } Score.ReturnScoreUI(player); } stopwatch.Stop(); System.Diagnostics.Debug.WriteLine("Move room command speed: " + stopwatch.Elapsed); } catch (Exception e) { //log error } } else { HubContext.Instance.AddNewMessageToPage(player.HubGuid, "There is no exit here"); } } }
/// <summary> /// Command list for the game /// </summary> /// <param name="commandOptions">Everything after the 1st occurance of a space</param> /// <param name="commandKey">The string before the 1st occurance of a space</param> /// <param name="playerData">Player Data</param> /// <param name="room">Current room</param> /// <returns>Returns Dictionary of commands</returns> public static void Commands(string commandOptions, string commandKey, PlayerSetup.Player playerData, Room.Room room) { var context = HubContext.Instance; switch (commandKey) { case "north": Movement.Move(playerData, room, "North"); break; case "east": Movement.Move(playerData, room, "East"); break; case "south": Movement.Move(playerData, room, "South"); break; case "west": Movement.Move(playerData, room, "West"); break; case "up": Movement.Move(playerData, room, "Up"); break; case "down": Movement.Move(playerData, room, "Down"); break; case "look": case "look at": case "l at": case "search": LoadRoom.ReturnRoom(playerData, room, commandOptions, "look"); break; case "l in": case "search in": LoadRoom.ReturnRoom(playerData, room, commandOptions, "look in"); break; case "examine": LoadRoom.ReturnRoom(playerData, room, commandOptions, "examine"); break; case "touch": LoadRoom.ReturnRoom(playerData, room, commandOptions, "touch"); break; case "smell": LoadRoom.ReturnRoom(playerData, room, commandOptions, "smell"); break; case "taste": LoadRoom.ReturnRoom(playerData, room, commandOptions, "taste"); break; case "score": Score.ReturnScore(playerData); break; case "inventory": Inventory.ReturnInventory(playerData.Inventory, playerData); break; case "eq": case "equip": case "equipment": case "garb": Equipment.ShowEquipment(playerData); break; case "loot": case "get": case "take": ManipulateObject.GetItem(room, playerData, commandOptions, commandKey, "item"); break; case "plunder": ManipulateObject.GetItem(room, playerData, "all " + commandOptions, commandKey, "item"); break; case "drop": case "put": ManipulateObject.DropItem(room, playerData, commandOptions, commandKey); break; case "give": ManipulateObject.GiveItem(room, playerData, commandOptions, commandKey, "killable"); break; case "save": Save.SavePlayer(playerData); break; case "say": case "'": Communicate.Say(commandOptions, playerData, room); break; case "sayto": case ">": Communicate.SayTo(commandOptions, room, playerData); break; case "newbie": Communicate.NewbieChannel(commandOptions, playerData); break; case "gossip": Communicate.GossipChannel(commandOptions, playerData); break; case "ooc": Communicate.OocChannel(commandOptions, playerData); break; case "yes": Communicate.Say("Yes", playerData, room); break; case "no": Communicate.Say("No", playerData, room); break; case "yell": Communicate.Yell(commandOptions, room, playerData); break; case "talkto": Talk.TalkTo(commandOptions, room, playerData); break; case "emote": Emote.EmoteActionToRoom(commandOptions, playerData); break; case "use": case "wear": case "wield": Equipment.WearItem(playerData, commandOptions); break; case "remove": case "doff": case "unwield": Equipment.RemoveItem(playerData, commandOptions); break; case "hit": case "kill": case "attack": Fight2.PerpareToFight(playerData, room, commandOptions); break; case "flee": Flee.fleeCombat(playerData, room); break; case "sacrifice": case "harvest": Harvest.Body(playerData, room, commandOptions); break; case "peek": Peak.DoPeak(context, playerData, room, commandOptions); break; case "steal": Steal.DoSteal(context, playerData, room, commandOptions); break; case "pick": LockPick.DoLockPick(context, playerData, room, commandOptions); break; case "c magic missile": case "cast magic missile": MagicMissile.StartMagicMissile(playerData, room, commandOptions); break; case "c armour": case "cast armour": case "c armor": case "cast armor": new Armour().StartArmour(playerData, room, commandOptions); break; case "c continual light": case "cast continual light": ContinualLight.StarContinualLight(playerData, room, commandOptions); break; case "c invis": case "cast invis": Invis.StartInvis(playerData, room, commandOptions); break; case "c weaken": case "cast weaken": Weaken.StartWeaken(playerData, room, commandOptions); break; case "c chill touch": case "cast chill touch": ChillTouch.StartChillTouch(playerData, room, commandOptions); break; case "c fly": case "cast fly": Fly.StartFly(playerData, room, commandOptions); break; case "c refresh": case "cast refresh": Refresh.StartRefresh(playerData, room, commandOptions); break; case "c faerie fire": case "cast faerie fire": FaerieFire.StartFaerieFire(playerData, room, commandOptions); break; case "c teleport": case "cast teleport": Teleport.StartTeleport(playerData, room); break; case "c blindness": case "cast blindness": Blindness.StartBlind(playerData, room, commandOptions); break; case "c haste": case "cast haste": Haste.StartHaste(playerData, room, commandOptions); break; case "c create spring": case "cast create spring": CreateSpring.StartCreateSpring(playerData, room); break; case "c shocking grasp": case "cast shocking grasp": new ShockingGrasp().StartShockingGrasp(playerData, room, commandOptions); break; case "c cause light": case "cast cause light": new CauseLight().StartCauseLight(context, playerData, room, commandOptions); break; case "c cure light": case "cast cure light": new CureLight().StartCureLight(context, playerData, room, commandOptions); break; case "c cure blindness": new CureBlindness().StartCureBlindness(context, playerData, room, commandOptions); break; case "c detect invis": case "cast detect invis": DetectInvis.DoDetectInvis(context, playerData, room); break; case "forage": new Foraging().StartForaging(playerData, room); break; case "fish": case "angle": case "line": case "trawl": case "lure": new Fishing().StartFishing(playerData, room); break; case "reel": Fishing.GetFish(playerData, room); break; case "dirt kick": new DirtKick().StartDirtKick(context, playerData, room, commandOptions); break; case "bash": new Bash().StartBash(context, playerData, room, commandOptions); break; case "shield bash": new ShieldBash().StartBash(context, playerData, room, commandOptions); break; case "punch": Punch.StartPunch(playerData, room); break; case "kick": new Kick().StartKick(context, playerData, room, commandOptions); break; case "spin kick": new SpinKick().StartKick(context, playerData, room, commandOptions); break; case "rescue": new Rescue().StartRescue(context, playerData, room, commandOptions); break; case "lunge": new Lunge().StartLunge(context, playerData, room, commandOptions); break; case "disarm": new Disarm().StartDisarm(context, playerData, room); break; case "backstab": new Backstab().StartBackstab(context, playerData, room, commandOptions); break; case "feint": new Feint().StartFeint(context, playerData, room, commandOptions); break; case "mount": case "ride": Mount.StartMount(playerData, room, commandOptions); break; case "dismount": Mount.Dismount(playerData, room, commandOptions); break; case "trip": new Trip().StartTrip(context, playerData, room, commandOptions); break; case "sneak": Sneak.DoSneak(context, playerData); break; case "hide": Hide.DoHide(context, playerData); break; case "lore": Lore.DoLore(context, playerData, commandOptions); break; case "unlock": ManipulateObject.UnlockItem(room, playerData, commandOptions, commandKey); break; case "lock": ManipulateObject.LockItem(room, playerData, commandOptions, commandKey); break; case "close": case "shut": ManipulateObject.Close(room, playerData, commandOptions, commandKey); break; case "drink": ManipulateObject.Drink(room, playerData, commandOptions, commandKey); break; case "help": case "/help": case "?": case "commands": Help.ShowHelp(commandOptions, playerData); break; case "time": case "clock": Update.Time.ShowTime(); break; case "skills": case "spells": case "skills all": ShowSkills.ShowPlayerSkills(playerData, commandOptions); break; case "practice": Trainer.Practice(playerData, room, commandOptions); break; case "list": Shop.listItems(playerData, room); break; case "buy": Shop.buyItems(playerData, room, commandOptions); break; case "sell": Shop.sellItems(playerData, room, commandOptions); break; case "quest log": case "qlog": Quest.QuestLog(playerData); break; case "wake": Status.WakePlayer(context, playerData, room); break; case "sleep": Status.SleepPlayer(context, playerData, room); break; case "rest": case "sit": Status.RestPlayer(context, playerData, room); break; case "stand": Status.StandPlayer(context, playerData, room); break; case "greet": Greet.GreetMob(playerData, room, commandOptions); break; case "who": Who.Connected(playerData); break; case "affects": Effect.Show(playerData); break; case "follow": Follow.FollowThing(playerData, room, commandOptions); break; case "nofollow": Follow.FollowThing(playerData, room, "noFollow"); break; case "quit": HubContext.Instance.Quit(playerData.HubGuid, room); break; case "craft": Craft.CraftItem(playerData, room, commandOptions, CraftType.Craft); break; case "chop": Craft.CraftItem(playerData, room, commandOptions, CraftType.Chop); break; case "cook": Craft.CraftItem(playerData, room, commandOptions, CraftType.Cook); break; case "brew": Craft.CraftItem(playerData, room, commandOptions, CraftType.Brew); break; case "forge": Craft.CraftItem(playerData, room, commandOptions, CraftType.Forge); break; case "carve": Craft.CraftItem(playerData, room, commandOptions, CraftType.Carve); break; case "knit": Craft.CraftItem(playerData, room, commandOptions, CraftType.Knitting); break; case "make": case "build": Craft.CraftItem(playerData, room, commandOptions, CraftType.Craft); break; case "show crafts": case "craftlist": Craft.CraftList(playerData); break; case "set up camp": Camp.SetUpCamp(playerData, room); break; case "repair": Events.Repair.RepairItem(playerData, room, commandOptions); break; case "/debug": PlayerSetup.Player.DebugPlayer(playerData); break; case "/setGold": PlayerSetup.Player.SetGold(playerData, commandOptions); break; case "/setAc": PlayerSetup.Player.SetAC(playerData, commandOptions); break; case "/map": SigmaMap.DrawMap(playerData.HubGuid); //not what you think it does break; default: HubContext.Instance.SendToClient("Sorry you can't do that. Try help commands or ask on the discord channel.", playerData.HubGuid); var log = new Error.Error { Date = DateTime.Now, ErrorMessage = commandKey + " " + commandOptions, MethodName = "Wrong command" }; Save.LogError(log); break; } }
public static Room getRoom(Player Thing) { Player player; if (Thing.HubGuid != null) { if (_PlayerCache.TryGetValue(Thing.HubGuid, out player)) { var RoomData = new LoadRoom { Region = player.Region, Area = player.Area, id = player.AreaId }; Room getRoomData = null; var room = new Tuple <string, string, int>(RoomData.Region, RoomData.Area, RoomData.id); if (_AreaCache.TryGetValue(room, out getRoomData)) { return(getRoomData); } else { getRoomData = RoomData.LoadRoomFile(); _AreaCache.TryAdd(room, getRoomData); return(getRoomData); } } } else { //mob var mob = Thing; var RoomData = new LoadRoom { Region = mob.Region, Area = mob.Area, id = mob.AreaId }; Room getRoomData = null; var room = new Tuple <string, string, int>(RoomData.Region, RoomData.Area, RoomData.id); if (_AreaCache.TryGetValue(room, out getRoomData)) { return(getRoomData); } else { getRoomData = RoomData.LoadRoomFile(); _AreaCache.TryAdd(room, getRoomData); return(getRoomData); } } return(null); }
/// <summary> /// /// </summary> /// <param name="player"></param> /// <param name="room"></param> /// <param name="direction"></param> public static void Move(Player player, Room room, string direction) { if (player.MovePoints <= 0) { HubContext.SendToClient("You are exhausted an unable to move", player.HubGuid); foreach (var character in room.players) { if (character != player) { HubContext.SendToClient($"{Helpers.ReturnName(player, character, string.Empty)} tries to move but is too exhausted.", player.HubGuid); } } return; } Room roomData = room; if (roomData.exits == null) { room.exits = new List <Exit>(); } //Find Exit if (roomData.exits != null) { var exit = roomData.exits.Find(x => x.name == direction); if (exit != null) { if (exit.open == false) { HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("The " + exit.doorName + " is close"); return; } //remove player from old room PlayerManager.RemovePlayerFromRoom(roomData, player); //exit message ExitRoom(player, roomData, direction); //change player Location player.Area = exit.area; player.AreaId = exit.areaId; player.Region = exit.region; //Get new room try { //Room getNewRoom = await HubProxy.MimHubServer.Invoke<Room>("getRoom", player.HubGuid); Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(player); if (getNewRoom != null) { //add player to new room PlayerManager.AddPlayerToRoom(getNewRoom, player); //enter message EnterRoom(player, getNewRoom, direction); var roomDescription = LoadRoom.DisplayRoom(getNewRoom, player.Name); HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(roomDescription); //Show exits UI ShowUIExits(getNewRoom, player.HubGuid); //NPC Enter event here foreach (var mob in getNewRoom.mobs) { if (mob.Greet) { // Event.ParseCommand("greet", player, mob, getNewRoom); } else { //mob might be aggro } if (mob.DialogueTree != null) { var speak = mob.DialogueTree[0]; HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(mob.Name + " says to you " + speak.Message); var i = 1; foreach (var respond in speak.PossibleResponse) { var textChoice = "<a class='multipleChoice' href='javascript:void(0)' onclick='$.connection.mIMHub.server.recieveFromClient(\"say " + respond.Response + "\",\"" + player.HubGuid + "\")'>" + i + ". " + respond.Response + "</a>"; HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(textChoice); i++; } } //if (!string.IsNullOrEmpty(mob.EventOnEnter)) //{ // Event.ParseCommand(mob.EventOnEnter, player, mob, room); //} //if (!string.IsNullOrEmpty(room.EventOnEnter)) //{ // Event.ParseCommand(room.EventOnEnter, player, null, room); //} foreach (var quest in player.QuestLog.Where(x => x.Completed == false)) { if (quest.QuestHint != null && mob.Name == quest.QuestFindMob) { HubContext.SendToClient(quest.QuestHint, player.HubGuid); } } } Score.ReturnScoreUI(player); } } catch (Exception e) { //log error } } else { HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("There is no exit here"); } } }
//TODO: find bug causing this task to fire randomly // ran twice when casting armor spell on cat! -_- // c armor cat //Your hands start to glow as you begin chanting the armour spell //You place your hands upon Black and White cat engulfing them in a white protective glow. //You feel better as a wave of warth surrounds your body <-- task //Someone says to you, you should be feeling better now, wake when you are ready <-- task public static async Task Awakening(PlayerSetup.Player player, Room.Room room, string step, string calledBy) { //to stop task firing twice if (player.QuestLog.FirstOrDefault(x => x.Name.Equals("Find and greet Lance")) != null) { return; } player.Status = PlayerSetup.Player.PlayerStatus.Sleeping; var oldPlayer = player; await Task.Delay(5000); if (string.IsNullOrEmpty(step)) { player.Area = "Tutorial"; player.Region = "Tutorial"; player.AreaId = 3; var exit = new Exit { area = player.Area, region = player.Region, areaId = player.AreaId }; var templeRoom = Cache.ReturnRooms() .FirstOrDefault( x => x.area.Equals(player.Area) && x.areaId.Equals(player.AreaId) && x.region.Equals(player.Region)); if (templeRoom != null) { PlayerManager.RemovePlayerFromRoom(room, oldPlayer); Movement.Teleport(player, templeRoom, exit); } else { var loadRoom = new LoadRoom { Area = player.Area, id = player.AreaId, Region = player.Region }; var newRoom = loadRoom.LoadRoomFile(); PlayerManager.RemovePlayerFromRoom(room, oldPlayer); Movement.Teleport(player, newRoom, exit); //load from DB } //fix for random wake message hint showing var playerInRoom = Cache.ReturnRooms() .FirstOrDefault( x => x.area.Equals("Tutorial") && x.areaId.Equals(1) && x.region.Equals("Tutorial")) .players.FirstOrDefault(x => x.Name.Equals(player.Name)); //well this does not work if (playerInRoom != null) { await Task.Delay(3000); HubContext.SendToClient("You feel better as a wave of warmth surrounds your body", player.HubGuid); await Task.Delay(2000); HubContext.SendToClient("<span class='sayColor'>Someone says to you \"You should be feeling better now, wake when you are ready.\"</span>", player.HubGuid); await Task.Delay(2000); HubContext.SendToClient("<p class='RoomExits'>[Hint] Type wake to wake up</p>", player.HubGuid); } //loops forever because room.players does not get updated when player leaves the ambush room // so this always tries to fire the messages below. as to why it sometimes it shows and sometimes does not, I have no idea. while (playerInRoom != null && playerInRoom.Area.Equals("Tutorial")) { await Task.Delay(30000); // <-- is this the cause && the check below is not working playerInRoom = Cache.ReturnRooms() .FirstOrDefault( x => x.area.Equals("Tutorial") && x.areaId.Equals(1) && x.region.Equals("Tutorial")) .players.FirstOrDefault(x => x.Name.Equals(player.Name)); if (playerInRoom == null) { return; } if (playerInRoom.Status != PlayerSetup.Player.PlayerStatus.Standing) { HubContext.SendToClient("You feel better as a wave of warmth surrounds your body", player.HubGuid); await Task.Delay(2000); HubContext.SendToClient("<span class='sayColor'>Someone says to you \"You should be feeling better now, wake when you are ready.\"</span>", player.HubGuid); await Task.Delay(2000); HubContext.SendToClient("<p class='RoomExits'>[Hint] Type wake to wake up</p>", player.HubGuid); } } } }
private bool TryCreateRoom(EntrancePosition entrance, Room room, ref Direction direction) { if (entrance.cardinalDirection == Direction.north && room.GetAvailableEntranceDirection(Direction.south) == true) { List <Vector2Int> roomEntrancesCopy = CopyArray(room.entrancesS); bool whileLoop = true; while (whileLoop == true) { if (roomEntrancesCopy.Count == 0) { return(false); } int roomEntranceIndex = Random.Range(0, roomEntrancesCopy.Count - 1); int xOffset = entrance.position.x - roomEntrancesCopy[roomEntranceIndex].x; int yOffset = entrance.position.y + 3; offset = new Vector2Int(xOffset, yOffset); if (LoadRoom.CanCreateRoom(room, offset, tilemap)) { direction = Direction.north; return(true); } roomEntrancesCopy.RemoveAt(roomEntranceIndex); } } else if (entrance.cardinalDirection == Direction.east && room.GetAvailableEntranceDirection(Direction.west) == true) { List <Vector2Int> roomEntrancesCopy = CopyArray(room.entrancesW); bool whileLoop = true; while (whileLoop == true) { if (roomEntrancesCopy.Count == 0) { return(false); } int roomEntranceIndex = Random.Range(0, roomEntrancesCopy.Count - 1); int xOffset = entrance.position.x + 3; int yOffset = entrance.position.y - roomEntrancesCopy[roomEntranceIndex].y; offset = new Vector2Int(xOffset, yOffset); if (LoadRoom.CanCreateRoom(room, offset, tilemap)) { direction = Direction.east; return(true); } roomEntrancesCopy.RemoveAt(roomEntranceIndex); } } else if (entrance.cardinalDirection == Direction.south && room.GetAvailableEntranceDirection(Direction.north) == true) { List <Vector2Int> roomEntrancesCopy = CopyArray(room.entrancesN); bool whileLoop = true; while (whileLoop == true) { if (roomEntrancesCopy.Count == 0) { return(false); } int roomEntranceIndex = Random.Range(0, roomEntrancesCopy.Count - 1); int xOffset = entrance.position.x - roomEntrancesCopy[roomEntranceIndex].x; int yOffset = entrance.position.y - 2 - room.roomHeight; offset = new Vector2Int(xOffset, yOffset); if (LoadRoom.CanCreateRoom(room, offset, tilemap)) { direction = Direction.south; return(true); } roomEntrancesCopy.RemoveAt(roomEntranceIndex); } } else if (entrance.cardinalDirection == Direction.west && room.GetAvailableEntranceDirection(Direction.east) == true) { List <Vector2Int> roomEntrancesCopy = CopyArray(room.entrancesN); bool whileLoop = true; while (whileLoop == true) { if (roomEntrancesCopy.Count == 0) { return(false); } int roomEntranceIndex = Random.Range(0, roomEntrancesCopy.Count - 1); int xOffset = entrance.position.x - 2 - room.roomWidth; int yOffset = entrance.position.y - roomEntrancesCopy[roomEntranceIndex].y + 1; offset = new Vector2Int(xOffset, yOffset); if (LoadRoom.CanCreateRoom(room, offset, tilemap)) { direction = Direction.west; return(true); } roomEntrancesCopy.RemoveAt(roomEntranceIndex); } } return(false); }
//public static Dictionary<string, Action> commandList { get; set; } public static Dictionary <string, Action> Commands(string commandOptions, string commandKey, PlayerSetup.Player playerData, Room.Room room) { var commandList = new Dictionary <String, Action> { { "north", () => Movement.Move(playerData, room, "North") }, { "south", () => Movement.Move(playerData, room, "South") }, { "east", () => Movement.Move(playerData, room, "East") }, { "west", () => Movement.Move(playerData, room, "West") }, { "down", () => Movement.Move(playerData, room, "Down") }, { "up", () => Movement.Move(playerData, room, "Up") }, { "look", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "look") }, { "l in", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "look in") }, { "look in", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "look in") }, { "examine", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "examine") }, { "touch", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "touch") }, { "smell", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "smell") }, { "taste", () => LoadRoom.ReturnRoom(playerData, room, commandOptions, "taste") }, { "score", () => Score.ReturnScore(playerData) }, { "inventory", () => Inventory.ReturnInventory(playerData.Inventory, playerData) }, { "equipment", () => Equipment.ShowEquipment(playerData) }, { "garb", () => Equipment.ShowEquipment(playerData) }, { "get", () => ManipulateObject.GetItem(room, playerData, commandOptions, commandKey, "item") }, { "take", () => ManipulateObject.GetItem(room, playerData, commandOptions, commandKey, "item") }, { "drop", () => ManipulateObject.DropItem(room, playerData, commandOptions, commandKey) }, { "give", () => ManipulateObject.GiveItem(room, playerData, commandOptions, commandKey, "killable") }, { "put", () => ManipulateObject.DropItem(room, playerData, commandOptions, commandKey) }, { "save", () => Save.UpdatePlayer(playerData) }, { "'", () => Communicate.Say(commandOptions, playerData, room) }, { "newbie", () => Communicate.NewbieChannel(commandOptions, playerData) }, { "gossip", () => Communicate.GossipChannel(commandOptions, playerData) }, { "ooc", () => Communicate.OocChannel(commandOptions, playerData) }, { "say", () => Communicate.Say(commandOptions, playerData, room) }, { "sayto", () => Communicate.SayTo(commandOptions, room, playerData) }, { ">", () => Communicate.SayTo(commandOptions, room, playerData) }, { "talkto", () => Talk.TalkTo(commandOptions, room, playerData) }, { "emote", () => Emote.EmoteActionToRoom(commandOptions, playerData) }, { "quit", () => HubContext.Quit(playerData.HubGuid, room) }, { "wear", () => Equipment.WearItem(playerData, commandOptions) }, { "remove", () => Equipment.RemoveItem(playerData, commandOptions) }, { "doff", () => Equipment.RemoveItem(playerData, commandOptions) }, { "wield", () => Equipment.WearItem(playerData, commandOptions, true) }, { "unwield", () => Equipment.RemoveItem(playerData, commandOptions, false, true) }, { "kill", () => Fight2.PerpareToFight(playerData, room, commandOptions) }, { "flee", () => Flee.fleeCombat(playerData, room) }, //spells { "c magic missile", () => MagicMissile.StartMagicMissile(playerData, room, commandOptions) }, { "cast magic missile", () => MagicMissile.StartMagicMissile(playerData, room, commandOptions) }, { "c armour", () => Armour.StartArmour(playerData, room, commandOptions) }, { "cast armour", () => Armour.StartArmour(playerData, room, commandOptions) }, { "c armor", () => Armour.StartArmour(playerData, room, commandOptions) }, { "cast armor", () => Armour.StartArmour(playerData, room, commandOptions) }, { "c continual light", () => ContinualLight.StarContinualLight(playerData, room, commandOptions) }, { "cast continual light", () => ContinualLight.StarContinualLight(playerData, room, commandOptions) }, { "c invis", () => Invis.StartInvis(playerData, room, commandOptions) }, { "cast invis", () => Invis.StartInvis(playerData, room, commandOptions) }, { "c weaken", () => Weaken.StartWeaken(playerData, room, commandOptions) }, { "cast weaken", () => Weaken.StartWeaken(playerData, room, commandOptions) }, { "c chill touch", () => ChillTouch.StartChillTouch(playerData, room, commandOptions) }, { "cast chill touch", () => ChillTouch.StartChillTouch(playerData, room, commandOptions) }, { "c fly", () => Fly.StartFly(playerData, room, commandOptions) }, { "cast fly", () => Fly.StartFly(playerData, room, commandOptions) }, { "c refresh", () => Refresh.StartRefresh(playerData, room, commandOptions) }, { "cast refresh", () => Refresh.StartRefresh(playerData, room, commandOptions) }, { "c faerie fire", () => FaerieFire.StartFaerieFire(playerData, room, commandOptions) }, { "cast faerie fire", () => FaerieFire.StartFaerieFire(playerData, room, commandOptions) }, { "c teleport", () => Teleport.StartTeleport(playerData, room) }, { "cast teleport", () => Teleport.StartTeleport(playerData, room) }, { "c blindness", () => Blindness.StartBlind(playerData, room, commandOptions) }, { "cast blindess", () => Blindness.StartBlind(playerData, room, commandOptions) }, { "c haste", () => Haste.StartHaste(playerData, room, commandOptions) }, { "cast haste", () => Haste.StartHaste(playerData, room, commandOptions) }, { "c create spring", () => CreateSpring.StartCreateSpring(playerData, room) }, { "cast create spring", () => CreateSpring.StartCreateSpring(playerData, room) }, //skills { "punch", () => Punch.StartPunch(playerData, room) }, { "kick", () => Kick.StartKick(playerData, room) }, // { "unlock", () => ManipulateObject.UnlockItem(room, playerData, commandOptions, commandKey) }, { "lock", () => ManipulateObject.LockItem(room, playerData, commandOptions, commandKey) }, { "open", () => ManipulateObject.Open(room, playerData, commandOptions, commandKey) }, { "close", () => ManipulateObject.Close(room, playerData, commandOptions, commandKey) }, { "drink", () => ManipulateObject.Drink(room, playerData, commandOptions, commandKey) }, { "help", () => Help.ShowHelp(commandOptions, playerData) }, { "time", Update.Time.ShowTime }, { "clock", Update.Time.ShowTime }, { "skills", () => ShowSkills.ShowPlayerSkills(playerData, commandOptions) }, { "skills all", () => ShowSkills.ShowPlayerSkills(playerData, commandOptions) }, { "practice", () => Trainer.Practice(playerData, room, commandOptions) }, { "list", () => Shop.listItems(playerData, room) }, { "buy", () => Shop.buyItems(playerData, room, commandOptions) }, { "quest log", () => Quest.QuestLog(playerData) }, { "qlog", () => Quest.QuestLog(playerData) }, { "wake", () => Status.WakePlayer(playerData, room) }, { "sleep", () => Status.SleepPlayer(playerData, room) }, { "greet", () => Greet.GreetMob(playerData, room, commandOptions) }, { "who", () => Who.Connected(playerData) }, { "affects", () => Affect.Show(playerData) }, { "follow", () => Follow.FollowThing(playerData, room, commandOptions) } }; return(commandList); }
public static async Task Awakening(PlayerSetup.Player player, Room.Room room, string step, string calledBy) { player.Status = PlayerSetup.Player.PlayerStatus.Sleeping; await Task.Delay(5000); if (string.IsNullOrEmpty(step)) { player.Area = "Tutorial"; player.Region = "Tutorial"; player.AreaId = 3; var exit = new Exit { area = player.Area, region = player.Region, areaId = player.AreaId }; var templeRoom = Cache.ReturnRooms() .FirstOrDefault( x => x.area.Equals(player.Area) && x.areaId.Equals(player.AreaId) && x.region.Equals(player.Region)); if (templeRoom != null) { Movement.Teleport(player, templeRoom, exit); } else { var loadRoom = new LoadRoom { Area = player.Area, id = player.AreaId, Region = player.Region }; var newRoom = loadRoom.LoadRoomFile(); Movement.Teleport(player, newRoom, exit); //load from DB } //fix for random wake message hint showing if (room.players.FirstOrDefault(x => x.Name.Equals(player.Name)) != null) { await Task.Delay(3000); HubContext.SendToClient("You feel better as a wave of warmth surrounds your body", player.HubGuid); await Task.Delay(2000); HubContext.SendToClient("Someone says to you, You should be feeling better now, wake when you are ready", player.HubGuid); await Task.Delay(2000); HubContext.SendToClient("<p class='RoomExits'>[Hint] Type wake to wake up</p>", player.HubGuid); } while (room.players.FirstOrDefault(x => x.Name.Equals(player.Name)) != null) { await Task.Delay(30000); if (room.players.FirstOrDefault(x => x.Name.Equals(player.Name)).Status != PlayerSetup.Player.PlayerStatus.Standing) { HubContext.SendToClient("You feel better as a wave of warth surrounds your body", player.HubGuid); await Task.Delay(2000); HubContext.SendToClient("Someone says to you, you should be feeling better now, wake when you are ready", player.HubGuid); await Task.Delay(2000); HubContext.SendToClient("<p class='RoomExits'>[Hint] Type wake to wake up</p>", player.HubGuid); } } } }
public void GenerateRandomLevel() { freeEntrances.Clear(); if (roomPossibilities.Count == 0) { Debug.Log("No room possibilities"); return; } tilemap.backgroundTilemap.ClearAllTiles(); for (int x = 0; x < numberOfRooms; x++) { CopyList(roomPossibilities, ref roomPossibilitiesCopy); CopyList(freeEntrances, ref freeEntrancesCopy); int roomIndex = Random.Range(0, roomPossibilitiesCopy.Count); if (x == 0) { LoadRoom.CreateRoom(roomPossibilitiesCopy[roomIndex], new Vector2Int(0, 0), tilemap); AddToFreeExpansions(roomIndex, new Vector2Int(0, 0), Direction.none); } else { Direction direction = Direction.none; bool whileLoop = true; while (whileLoop) { int positionIndex = Random.Range(0, freeEntrancesCopy.Count - 1); Debug.Log("PositionIndex: " + positionIndex + "roomIndex: " + roomIndex); Debug.Log("FreeExpansionCount: " + freeEntrancesCopy.Count); if (TryCreateRoom(freeEntrancesCopy[positionIndex], roomPossibilitiesCopy[roomIndex], ref direction)) { if (LoadRoom.CreateRoom(roomPossibilitiesCopy[roomIndex], offset, tilemap)) { AddToFreeExpansions(roomIndex, offset, Direction.south); //Create the hallway if (direction == Direction.north) { LoadRoom.CreateRoom(hallways[0], new Vector2Int(freeEntrancesCopy[positionIndex].position.x - 1, freeEntrancesCopy[positionIndex].position.y), tilemap, true); } else if (direction == Direction.east) { LoadRoom.CreateRoom(hallways[1], new Vector2Int(freeEntrancesCopy[positionIndex].position.x, freeEntrancesCopy[positionIndex].position.y - 1), tilemap, true); } else if (direction == Direction.south) { LoadRoom.CreateRoom(hallways[0], new Vector2Int(freeEntrancesCopy[positionIndex].position.x - 1, freeEntrancesCopy[positionIndex].position.y - 3), tilemap, true); } else { LoadRoom.CreateRoom(hallways[1], new Vector2Int(freeEntrancesCopy[positionIndex].position.x - 3, freeEntrancesCopy[positionIndex].position.y - 1), tilemap, true); } freeEntrancesCopy.RemoveAt(positionIndex); whileLoop = false; } else { freeEntrancesCopy.RemoveAt(positionIndex); } } else { if (freeEntrances.Count == 0) { roomPossibilitiesCopy.RemoveAt(roomIndex); roomIndex = Random.Range(0, roomPossibilitiesCopy.Count - 1); CopyList(freeEntrances, ref freeEntrancesCopy); } } if (freeEntrances.Count == 0 && roomPossibilitiesCopy.Count == 0) { whileLoop = false; } } } } //Adding hallways to rooms after generation of all rooms }
public static void Move(Player player, Room room, string direction) { Room roomData = room; if (roomData.exits == null) { room.exits = new List <Exit>(); } //Find Exit if (roomData.exits != null) { var exit = roomData.exits.Find(x => x.name == direction); if (exit != null) { if (exit.open == false) { HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("The " + exit.doorName + " is close"); return; } //remove player from old room PlayerManager.RemovePlayerFromRoom(roomData, player); //exit message ExitRoom(player, roomData, direction); //change player Location player.Area = exit.area; player.AreaId = exit.areaId; player.Region = exit.region; //Get new room try { //Room getNewRoom = await HubProxy.MimHubServer.Invoke<Room>("getRoom", player.HubGuid); Room getNewRoom = MIMWebClient.Hubs.MIMHub.getRoom(player.HubGuid); if (getNewRoom != null) { //add player to new room PlayerManager.AddPlayerToRoom(getNewRoom, player); //enter message EnterRoom(player, getNewRoom, direction); var roomDescription = LoadRoom.DisplayRoom(getNewRoom, player.Name); HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage(roomDescription); //NPC Enter event here foreach (var mob in getNewRoom.mobs) { if (mob.Greet) { Event.ParseCommand("greet", player, mob, getNewRoom); } else { //mob might be aggro } } } } catch (Exception e) { //log error } } else { HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("There is no exit here"); } } }