public void init(int loginid, CharacterInformation info)
        {
            LoggedUserID        = loginid;
            SelectedCharacterID = info.getCharid();
            CurrentMapID        = info.getChar_curmap();

            this.playerEntity = null;
            this.playerEntity = new UnitEntity(info.getCharid(), info.getChar_name(), classConfigs[info.getChar_class()], info.getChar_hair(), info.getChar_face(), info.getChar_hp(), info.getChar_sp(), game, content, graphics, spriteBatch, entityNameFont, entityDamageFont, whiteRect, modelBank, itemBank, audioSystem, particleManager);

            state = GameState.map_warp;
        }
Beispiel #2
0
        public void load()
        {
            // Load character data
            createButton.Enabled = false;
            startButton.Enabled  = false;
            game.messageDialog.setTitle("");
            game.messageDialog.setMessage("Please wait...");
            game.messageDialog.Visible            = true;
            game.messageDialog.CloseButtonVisible = false;
            Boolean end = false;

            for (int i = 0; i < game.maxchar; ++i)
            {
                String responseMsg = "";
                String statusMsg   = "";
                try
                {
                    // Try connect to server
                    //if (!network.isConnected())
                    //    network.Connect("127.0.0.1", 5000);
                    // Send login message
                    network.Send("CHARGET:" + LoggedUserID + " " + i + ";"); // Get character from index
                    // Receive message
                    while (responseMsg.Length <= 0)
                    {
                        responseMsg = network.Receive();
                    }
                }
                catch (Exception e)
                {
                    // Has any error come here
                    Debug.WriteLine(e.ToString());
                    game.messageDialog.setTitle("ERROR!!");
                    game.messageDialog.setMessage("Can't connect to server.");
                    game.messageDialog.Visible            = true;
                    game.messageDialog.CloseButtonVisible = true;
                    state = GameState.none;
                }
                // Split message from end of line
                String[] line = responseMsg.Split(';');
                for (int j = 0; j < line.Length; ++j)
                {
                    // If has message
                    // Split message name(CHARGET) and value({STATUS}|{CHARID})
                    // CHARGET:{STATUS}|{CHARID};
                    String[] msg = line[j].Split(':');
                    if (msg[0].Equals("CHARGET") && msg.Length == 2)
                    {
                        // Split message value
                        String[] value = msg[1].Split(' ');
                        if (value.Length == 2)
                        {
                            statusMsg = value[0];
                        }
                        if (statusMsg.Equals("OK"))
                        {
                            // if status is OK
                            try
                            {
                                // If character found show panel
                                CharacterInformation chara = getCharInfo(Convert.ToInt32(value[1]));
                                if (chara != null)
                                {
                                    if (!charInfo.ContainsKey(chara.getCharid()))
                                    {
                                        charInfo.Add(chara.getCharid(), chara);
                                        listId.Add(i, chara.getCharid());
                                        character_name[i].Text            = ("Name: " + charInfo[listId[i]].getChar_name());
                                        character_level[i].Text           = ("LV: " + charInfo[listId[i]].getChar_level());
                                        character_selectButton[i].Enabled = true;
                                        character_deleteButton[i].Enabled = true;
                                        character_panel[i].Visible        = true;
                                        state = GameState.none;
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                // Has any error come here
                                Debug.WriteLine(e.ToString());
                                game.messageDialog.setTitle("ERROR!!");
                                game.messageDialog.setMessage("There has something error.");
                                game.messageDialog.Visible            = true;
                                game.messageDialog.CloseButtonVisible = true;
                                state = GameState.none;
                            }
                            break;
                        }
                        else
                        {
                            // if status isn't OK
                            state = GameState.none;
                            end   = true;
                            break;
                        }
                    }
                }
                // If Readed all character data
                if (end)
                {
                    break;
                }
            }
            game.hideMessageDialog();
            createButton.Enabled = true;
            startButton.Enabled  = true;
        }