Example #1
0
	//server side
	void OnServerInitialized() {

		ShowChatWindow();

		PlayerNode newNode = new PlayerNode();
		newNode.playerName = playerName;
		newNode.networkPlayer = Network.player;
		playerList.Add(newNode);

		addGameChatMessage(playerName + "joined the game.");
	}
Example #2
0
File: Map.cs Project: hilliam/Mud
    public static Map ReadMap(PlayerNode player)
    {
        var mapa = new Map();
        string stringMapa = "";
        try
            {
                //Pass the file path and file name to the StreamReader constructor
                //StreamReader sr = new StreamReader("J:\\map2.txt", System.Text.Encoding.ASCII);

                //Read the first line of text
                //var line = sr.ReadLine();

                // create reader and open file
                using (StreamReader reader = new StreamReader("J:\\map2.txt", System.Text.Encoding.ASCII))
                {
                    // read all contents
                    stringMapa = reader.ReadToEnd();
                }

                //Continue to read until you reach end of file
        //				while (line != null)
        //				{
        //					//write the lie to console window
        //					//Console.WriteLine(line);
        //					stringMapa += line;
        //					//networkView.RPC("SendMsgToClient", player.networkPlayer, player.networkPlayer, line);
        //					//Read the next line
        //					line = sr.ReadLine();
        //				}

                //close the file
                //reader.Close();
                //Console.ReadLine();
                mapa.mapString = stringMapa;
            }
            catch(Exception e)
            {
                //networkView.RPC("SendMsgToClient", player.networkPlayer, player.networkPlayer, "Exception: " + e.Message);
                //Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
             	//networkView.RPC("SendMsgToClient", player.networkPlayer, player.networkPlayer, "Executing finally block.");
                //Console.WriteLine("Executing finally block.");
            }
        return mapa;
        //System.IO.StreamReader reader = new System.IO.StreamReader(fileName,  System.Text.Encoding.ASCII);
    }
Example #3
0
        public void MoveRoot(LogarithmicGrid newGrid)
        {
            this.rootNode = (PlayerNode)this.rootNode.Children.Values
                                            .SelectMany(cn => cn.Children)
                                            .First(pn => pn.Grid.Equals(newGrid));

            var sum = this.rootNode.Sum;

            foreach (var lesserSum in this.knownPlayerNodesBySum.Keys.Where(k => k <= sum).ToArray())
            {
                this.knownPlayerNodesBySum.Remove(lesserSum);
            }

            foreach (var lesserSum in this.knownComputerNodesBySum.Keys.Where(k => k < sum).ToArray())
            {
                this.knownComputerNodesBySum.Remove(lesserSum);
            }
        }
        private void GetActionsFromNode(PlayerNode node)
        {
            if (node.Parent == null)
            {
                return;
            }
            else
            {
                GetActionsFromNode(node.Parent);
            }

            pendingActions.Enqueue(node.Action);
        }
Example #5
0
 private PlayerNode GetPlayerNode(IPlayer player)
 {
     int playerId = player.ID;
     try
     {
         return playerNodes[playerId];
     }
     catch(KeyNotFoundException)
     {
         return playerNodes[playerId] = new PlayerNode(player);
     }
 }
Example #6
0
            private IEnumerable<IPlayerNode> GetChildrenWith2()
            {
                if (this.computedNodesWith2 == null)
                {
                    this.computedNodesWith2 = new List<IPlayerNode>();
                }
                else
                {
                    foreach (var node in this.computedNodesWith2)
                    {
                        yield return node;
                    }
                }

                if (!this.allNodesWith2Computed)
                {
                    IDictionary<LogarithmicGrid, IPlayerNode> knownPlayerNodesWithSumPlus2;
                    if (!this.SearchTree.knownPlayerNodesBySum.TryGetValue(this.Sum, out knownPlayerNodesWithSumPlus2))
                    {
                        knownPlayerNodesWithSumPlus2 = new Dictionary<LogarithmicGrid, IPlayerNode>();
                        this.SearchTree.knownPlayerNodesBySum.Add(this.Sum, knownPlayerNodesWithSumPlus2);
                    }

                    foreach (var possibleState in this.Grid.NextPossibleStatesWith2().Skip(this.computedNodesWith2.Count))
                    {
                        IPlayerNode playerNode;
                        if (!knownPlayerNodesWithSumPlus2.TryGetValue(possibleState, out playerNode))
                        {
                            playerNode = new PlayerNode(possibleState, this.SearchTree, this.Sum + 2);
                            knownPlayerNodesWithSumPlus2.Add(possibleState, playerNode);
                        }

                        this.computedNodesWith2.Add(playerNode);

                        yield return playerNode;
                    }
                }

                this.allNodesWith2Computed = true;
            }
Example #7
0
 public SearchTree(IHeuristic heuristic, LogarithmicGrid startingGrid)
 {
     this.Heuristic = heuristic;
     this.rootNode = new PlayerNode(startingGrid, this, startingGrid.Sum());
 }
Example #8
0
    public static Comands ParseItemCommand(string cmd, ComandsType typeCommands, Room currentRoom, PlayerNode player)
    {
        var retornoComando = new Comands();
        var nomeItem = cmd;
        retornoComando.Comando = "Comando inválido";
        if(typeCommands == ComandsType.UsarItem)
        {
            var openDoor = false;
            foreach (var item in currentRoom.m_ItemsRoom)
            {

                if (item.m_NameItem == nomeItem)
                {
                    var jogadorComItem = player.Inventory.Where(i => i.m_NameItem == nomeItem).Select(s => s.m_NameItem == nomeItem).FirstOrDefault();
                    if(jogadorComItem)
                    {
                        if (item.m_IsUsedItem)
                        {
                            retornoComando.Comando = "Item ja usado.";
                            break;
                        }
                        else
                        {
                            if (item.m_GetItem)
                            {
                                retornoComando.Comando = "Usar item " + nomeItem;
                                item.m_IsUsedItem = true;
                                player.Inventory.Remove(item);

                                break;
                            }
                        }
                    }
                    else{
                 		retornoComando.Comando = "Jogador esta sem o item.";
                        break;
                    }
                }

            }

            retornoComando.IsOpenDoor = currentRoom.m_ItemsRoom.All(a => a.m_IsUsedItem == true);

        }
        else if (typeCommands == ComandsType.PegarItem)
        {
            foreach (var item in currentRoom.m_ItemsRoom)
            {
                if (item.m_NameItem == nomeItem)
                {
                    if (item.m_GetItem)
                    {
                        retornoComando.Comando = "Item já foi pego.";
                        break;
                    }
                    else
                    {
                        retornoComando.Comando = "Item " + nomeItem +" adquerido.";
                        item.m_GetItem = true;
                        item.m_Collectable = false;
                        //item = GameObject.GetComponent<Room>();
                        player.Inventory.Add(item);
                        break;
                    }
                }
            }
        }
        else if (typeCommands == ComandsType.LargarItem)
        {
            foreach (var item in currentRoom.m_ItemsRoom)
            {
                if (item.m_NameItem == nomeItem)
                {
                    var jogadorComItem = player.Inventory.Where(i => i.m_NameItem == nomeItem).Select(s => s.m_NameItem == nomeItem).FirstOrDefault();
                    if(jogadorComItem)
                    {
                        if (item.m_Collectable)
                        {
                            retornoComando.Comando = "Item já foi largado.";
                            break;
                        }
                        else
                        {
                            retornoComando.Comando = "Deixou item " + nomeItem;
                            item.m_GetItem = false;
                            item.m_Collectable = true;
                            player.Inventory.Remove(item);
                            break;
                        }
                    }else{
                        retornoComando.Comando = "O jogador esta sem esse item.";
                        break;
                    }
                }
            }
        }

        return retornoComando;
    }
Example #9
0
 // Server method
 void OnServerInitialized()
 {
     this.ShowChatWindow();
     // no support for sending an RPC on the server to the server itself :(
     PlayerNode newEntry = new PlayerNode();
     newEntry.PlayerName = this.playerName;
     newEntry.NetworkPlayer = Network.player;
     this.playerList.Add(newEntry);
     this.AddGameChatMessage(this.playerName + " joined the chat");
 }
Example #10
0
	void TellServerOurName(string name, NetworkMessageInfo info) {

		PlayerNode node = new PlayerNode();
		node.playerName = name;
		node.networkPlayer = info.sender;
		playerList.Add(node);

		addGameChatMessage(name+" joined the chat");
	}
Example #11
0
    public void TellServerOurName(string stName, NetworkMessageInfo info)
    {
        string stWelcomeMsg = "Bem vindo ao servidor de MUD!\n";

        PlayerNode newEntry = new PlayerNode ();
        newEntry.stPlayerName = stName;
        newEntry.networkPlayer = info.sender;
        playerList.Add (newEntry);

        // TODO: adicionar verificacões, como login repetido, etc

        // Adiciona o novo jogador
        stWelcomeMsg += scriptRegras.AddNewPlayer (newEntry.networkPlayer, newEntry.stPlayerName);

        addGameChatMessage (newEntry.stPlayerName + " juntou-se ao servidor.");
        SendChatMessageTo (newEntry.networkPlayer, stWelcomeMsg);
    }
	//Sent by newly connected clients, recieved by server
	void TellServerOurName(string name, NetworkMessageInfo info)
	{
		PlayerNode newEntry = new PlayerNode();
		newEntry.playerName = name;
		newEntry.networkPlayer = info.sender;
		playerList.Add(newEntry);

	}
Example #13
0
    //Server function
    public void OnPlayerConnected(NetworkPlayer player)
    {
        Debug.Log("Entrou2");
        //Captura o Nome do personagem que conectou
        playerName = PlayerPrefs.GetString("playerName");
        var nameOfPlayer = playerName.Trim().ToLower().Replace(" ","");
        var existePlayerMesmoNome = playerList.Where(j => j.playerName == nameOfPlayer).Select(s => s.playerName == nameOfPlayer).FirstOrDefault();
        if(!existePlayerMesmoNome){
        PlayerNode newEntry = new PlayerNode();
        newEntry.playerName = nameOfPlayer;
        newEntry.networkPlayer = player;
        newEntry.Inventory = new List<Item>();
        //Adiciona a lista de player.
        playerList.Add(newEntry);
        //Cria as salas.
        if (!isRoomsCreate)
        {
            CreateRooms();
        }

        rooms[0].m_PlayerSalaRoom.Add(newEntry);

        networkView.RPC("SendMsgToClient", RPCMode.All, Network.player, "O jogador " + playerName + " acessou servidor!");
        networkView.RPC("SendMsgToClient", player, Network.player, IniciarMud());
        networkView.RPC("SendMsgToClient", player, Network.player, "Você está na sala " + rooms[0].m_NameRoom);

        }else{
            networkView.RPC("SendMsgToClient", player, Network.player, "Nome de personagem já existe.");
            Network.CloseConnection(player,true);
        }
        Debug.Log("Entrou3");
    }
Example #14
0
    void TellServerOurName(string name, NetworkMessageInfo info)
    {
        PlayerNode newEntry = new PlayerNode();
        newEntry.PlayerName = name;
        newEntry.NetworkPlayer = info.sender;
        this.playerList.Add(newEntry);

        this.AddGameChatMessage(name + " joined the chat");
    }
 public PlayerNode(PlayerNode parent, GameTime time, int moves, PlayerAction action, PlayerElement playerElement, int jumps)
 {
     this.Parent = parent;
     this.Time = time;
     this.Moves = moves;
     this.Action = action;
     this.PlayerElement = playerElement;
     this.Jumps = jumps;
 }
        private void ComputeNextActions()
        {
            float goalDestinationX = player.Location.X + 983;
            HashSet<int> visited = new HashSet<int>();

            orderedSet = new OrderedBag<PlayerNode>((a, b) => a.Destination((int)goalDestinationX).CompareTo(b.Destination((int)goalDestinationX)));

            PlayerNode initialNode = new PlayerNode(null, sceneTime, 0, PlayerAction.None, player.Clone(), 0);
            orderedSet.Add(initialNode);
            visited.Add((int)initialNode.PlayerElement.Location.X << 10 + (int)initialNode.PlayerElement.Location.Y);

            PlayerNode bestNode = initialNode;
            bool foundBest = false;

            while (orderedSet.Count > 0 && !foundBest)
            {
                PlayerNode current = orderedSet.RemoveFirst();

                if (current.PlayerElement.IsOnGround() && bestNode.Destination((int)goalDestinationX) > current.Destination((int)goalDestinationX))
                {
                    bestNode = current;
                }

                foreach (PlayerAction action in possibleActions)
                {
                    if (action == PlayerAction.Jump && !current.PlayerElement.IsOnGround())
                    {
                        continue;
                    }

                    PlayerElement newPlayer = current.PlayerElement.Clone();
                    newPlayer.IsPlayerAGoat = true;
                    switch (action)
                    {
                        case PlayerAction.None:
                            newPlayer.Stop();
                            break;
                        case PlayerAction.MoveRight:
                            newPlayer.MoveForward();
                            break;
                        case PlayerAction.MoveLeft:
                            newPlayer.MoveBackward();
                            break;
                        case PlayerAction.Jump:
                            newPlayer.Jump();
                            break;
                    }

                    GameTime newTime = IncrementTime(current.Time);
                    newPlayer.Update(newTime);
                    Parallel.ForEach(timeDependentElements, element => element.Update(newTime));
                    HandleInteraction(newPlayer);
                    if (newPlayer.IsDead)
                    {
                        continue;
                    }

                    int hash = ((int)(newPlayer.Location.X * 10) << 7) + (int)newPlayer.Location.Y;
                    if (!visited.Add(hash))
                    {
                        continue;
                    }

                    PlayerNode newNode = new PlayerNode(current, newTime, current.Moves + 1, action, newPlayer, current.Jumps + (action == PlayerAction.Jump ? 1 : 0));
                    if (newPlayer.Location.X > goalDestinationX && newPlayer.IsOnGround() || newPlayer.HasWon)
                    {
                        bestNode = newNode;
                        foundBest = true;
                        break;
                    }
                    orderedSet.Add(newNode);
                }
            }

            orderedSet.Clear();
            if (bestNode == initialNode)
            {
                pendingActions.Enqueue(PlayerAction.None);
            }
            else
            {
                GetActionsFromNode(bestNode);
            }
        }
Example #17
0
 void TellServerOurName(string name, NetworkMessageInfo info)
 {
     PlayerNode newEntry = new PlayerNode();
     newEntry.playerName = name;
     newEntry.player = Network.player;
     playerList.Add(newEntry);
     AddGameChatMessage(name + " has just joined the nebula!");
 }