/** * The main function which handles all game logic. * @param action the message the client has sent to the server * @param player the player who sent the message * @param database the database reference for database lookups and writes */ public ActionResponse PlayerAction(String action, Player player, SqlWrapper database) { String[] input = action.Split(' '); String subject = ""; ActionResponse rAction = new ActionResponse(); //gets the rest of the action which isnt the first word(the command) if (input.Length > 1) { subject = action.Remove(0, input[0].Count() + 1).ToLower(); } //sanity check, this has never happened but it cant hurt to have if (player == null) { rAction.message = U.NL("Not in list you do not exsist"); return(rAction); } //Get the currnt room once. Room currentRoom = RoomList[player.RoomIndex]; switch (input[0].ToLower()) { case "help": Console.Clear(); rAction.Set(HelpMessage(), ActionID.NORMAL); break; case "look": String temp = database.GetRoomDescrption(currentRoom.RoomIndex); rAction.Set(temp, ActionID.NORMAL); break; case "graf": database.AddGrafiti(subject, currentRoom.RoomIndex); rAction.Set("You added Grafiti: " + subject, ActionID.UPDATE); break; case "pickup": String pik = database.MoveItem("room" + player.RoomIndex, "player" + player.PlayerName, subject); pik += "Pick up Item: " + subject; rAction.Set(pik, ActionID.UPDATE); break; case "drop": String drp = database.MoveItem("player" + player.PlayerName, "room" + player.RoomIndex, subject); drp += "Drop Item: " + subject; rAction.Set(drp, ActionID.UPDATE); break; case "inventory": rAction.Set(database.GetOwnedItems("player" + player.PlayerName), ActionID.NORMAL); break; case "say": rAction.Set(subject, ActionID.SAY); break; case "go": // is arg[1] sensible? int[] indexs = currentRoom.GetExitIndexs(); if ((input[1].ToLower() == "north") && (currentRoom.north != -1)) { player.SetRoom(RoomList[currentRoom.north].RoomIndex); } else if ((input[1].ToLower() == "east") && (currentRoom.east != -1)) { player.SetRoom(RoomList[currentRoom.east].RoomIndex); } else if ((input[1].ToLower() == "south") && (currentRoom.south != -1)) { player.SetRoom(RoomList[currentRoom.south].RoomIndex); } else if ((input[1].ToLower() == "west") && (currentRoom.west != -1)) { player.SetRoom(RoomList[currentRoom.west].RoomIndex); } else { //handle error rAction.Set(U.NL("\nERROR") + U.NL("\nCan not go " + input[1] + " from here"), ActionID.UPDATE); return(rAction); } String str = U.NL(database.UpdatePlayerPos(player)); rAction.Set(str, ActionID.MOVE); break; default: //handle error rAction.Set(U.NL("\nERROR") + HelpMessage(), ActionID.NORMAL); break; } return(rAction); }