/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); manager.Initialize(); // Add Login window pageLogin = new GUILogin(manager, network, this); manager.Add(pageLogin); // Add Character selector window pageCharacterSelector = new GUICharacterSelector(manager, network, this); manager.Add(pageCharacterSelector); pageCharacterSelector.Visible = false; // Add Character creator window pageCharacterCreator = new GUICharacterCreator(manager, network, this, classConfigs); manager.Add(pageCharacterCreator); pageCharacterCreator.Visible = false; // Add Message dialog messageDialog = new GUIMessageDialog(manager, "", ""); manager.Add(messageDialog); messageDialog.Visible = false; // game gui guiGameAttribute = new GUIGameAttribute(manager, network); manager.Add(guiGameAttribute); guiGameAttribute.Visible = false; guiGameInventory = new GUIGameInventory(manager, network, Content, graphics, config.getItemList()); manager.Add(guiGameInventory); guiGameInventory.Visible = false; guiGameEquipment = new GUIGameEquipment(manager, network, Content, graphics, config.getItemList()); manager.Add(guiGameEquipment); guiGameEquipment.Visible = false; guiGameChat = new GUIGameChat(manager, network); manager.Add(guiGameChat); guiGameChat.Visible = false; guiGameMenu = new GUIGameMenu(manager, network, gameHandler, this); manager.Add(guiGameMenu); guiGameMenu.Visible = false; guiGameNPC = new GUIGameNPC(manager, network, Content, config.getDialogList()); manager.Add(guiGameNPC); guiGameNPC.Visible = false; guiGameEnvironment = new GUIGameEnvironment(manager, guiGameAttribute, null, guiGameEquipment, guiGameInventory, guiGameMenu); manager.Add(guiGameEnvironment); guiGameEnvironment.Visible = false; // Init Inventory & Equipment System guiGameInventory.init(guiGameEquipment); guiGameEquipment.init(guiGameInventory); // Shadow map //shadow.Initialize(); // SFX audioSystem.Initialize(); // BGM cue = audioSystem.getSoundBank().GetCue("01"); cue.Play(); //Debug.WriteLine("Initialized"); }
public GUIGameEnvironment(Manager manager, GUIGameAttribute guiGameAttribute = null, GUIGameSkill guiGameSkill = null, GUIGameEquipment guiGameEquipment = null, GUIGameInventory guiGameInventory = null, GUIGameMenu guiGameMenu = null) : base(manager) { this.manager = manager; this.guiGameAttribute = guiGameAttribute; this.guiGameSkill = guiGameSkill; this.guiGameEquipment = guiGameEquipment; this.guiGameInventory = guiGameInventory; this.guiGameMenu = guiGameMenu; Init(); Width = 395; Height = 80; Top = -15; Left = (manager.ScreenWidth - Width) / 2; Alpha = 220; CaptionVisible = false; CloseButtonVisible = false; Resizable = false; Movable = false; attributeButton = new Button(manager); attributeButton.Init(); attributeButton.Text = "Attributes"; attributeButton.Enabled = true; attributeButton.Parent = this; attributeButton.Width = 70; attributeButton.Top = 10; attributeButton.Left = 5; attributeButton.Click += new TomShane.Neoforce.Controls.EventHandler(attributeButton_Click); Add(attributeButton); skillButton = new Button(manager); skillButton.Init(); skillButton.Text = "Skills"; skillButton.Enabled = true; skillButton.Parent = this; skillButton.Width = 70; skillButton.Top = 10; skillButton.Left = 80; skillButton.Click += new TomShane.Neoforce.Controls.EventHandler(skillButton_Click); Add(skillButton); equipmentButton = new Button(manager); equipmentButton.Init(); equipmentButton.Text = "Equipment"; equipmentButton.Enabled = true; equipmentButton.Parent = this; equipmentButton.Width = 70; equipmentButton.Top = 10; equipmentButton.Left = 155; equipmentButton.Click += new TomShane.Neoforce.Controls.EventHandler(equipmentButton_Click); Add(equipmentButton); inventoryButton = new Button(manager); inventoryButton.Init(); inventoryButton.Text = "Inventory"; inventoryButton.Enabled = true; inventoryButton.Parent = this; inventoryButton.Width = 70; inventoryButton.Top = 10; inventoryButton.Left = 230; inventoryButton.Click += new TomShane.Neoforce.Controls.EventHandler(inventoryButton_Click); Add(inventoryButton); systemButton = new Button(manager); systemButton.Init(); systemButton.Text = "System"; systemButton.Enabled = true; systemButton.Parent = this; systemButton.Width = 70; systemButton.Top = 10; systemButton.Left = 305; systemButton.Click += new TomShane.Neoforce.Controls.EventHandler(systemButton_Click); Add(systemButton); hpBar = new TrackBar(manager); hpBar.Init(); hpBar.Value = 75; hpBar.Range = 100; hpBar.Enabled = false; hpBar.Parent = this; hpBar.Width = 183; hpBar.Height = 20; hpBar.Top = 35; hpBar.Left = 5; hpBar.Color = Color.Red; hpBar.SliderButtonVisible = false; Add(hpBar); spBar = new TrackBar(manager); spBar.Init(); spBar.Value = 75; spBar.Range = 100; spBar.Enabled = false; spBar.Parent = this; spBar.Width = 183; spBar.Height = 20; spBar.Top = 35; spBar.Left = 192; spBar.Color = Color.Blue; spBar.SliderButtonVisible = false; Add(spBar); expBar = new TrackBar(manager); expBar.Init(); expBar.Value = 75; expBar.Range = 100; expBar.Enabled = false; expBar.Parent = this; expBar.Width = 370; expBar.Height = 10; expBar.Top = 53; expBar.Left = 5; expBar.Color = Color.Yellow; expBar.SliderButtonVisible = false; Add(expBar); }
private void receiveMsg() { // What event happening, receive from server. while (state == GameState.none || state == GameState.map_warp) { try { String responseMsg = network.Receive(); //Debug.WriteLine(responseMsg); String[] line = responseMsg.Split(';'); for (int i = 0; i < line.Length; ++i) { String[] msg = line[i].Split(':'); // Get character info if (msg[0].Equals("CHARINFOSELF") && msg.Length == 2) { // Split message value String[] value = msg[1].Split(' '); if (value.Length == 24) { String statusMsg = value[0]; if (statusMsg.Equals("OK")) { // if status is OK CharacterInformation charInfo = new CharacterInformation(SelectedCharacterID, value[1] /*name*/, Convert.ToInt16(value[2]) /*class*/, Convert.ToInt16(value[3]) /*level*/, Convert.ToInt32(value[4]) /*exp*/, Convert.ToInt32(value[5]) /*curexp*/, Convert.ToInt32(value[6]) /*gold*/, Convert.ToInt32(value[7]) /*hp*/, Convert.ToInt32(value[8]) /*cur_hp*/, Convert.ToInt32(value[9]) /*sp*/, Convert.ToInt32(value[10]) /*cur_sp*/, Convert.ToInt32(value[11]) /*stpoint*/, Convert.ToInt32(value[12]) /*skpoint*/, Convert.ToInt16(value[13]) /*str*/, Convert.ToInt16(value[14]) /*dex*/, Convert.ToInt16(value[15]) /*int*/, Convert.ToInt16(value[16]) /*hair*/, Convert.ToInt16(value[17]) /*face*/, Convert.ToInt16(value[18]) /*curmap*/, Convert.ToSingle(value[19]) /*curmapx*/, Convert.ToSingle(value[20]) /*curmapy*/, Convert.ToInt16(value[21]) /*savmap*/, Convert.ToSingle(value[22]) /*savmapx*/, Convert.ToSingle(value[23]) /*savmapy*/); game.getGuiGameAttribute().setValues(charInfo); game.getGuiGameEnvironment().setValues(charInfo); if (charInfo.getChar_curmap() != CurrentMapID) { CurrentMapID = charInfo.getChar_curmap(); state = GameState.map_warping; } } } } if (msg[0].Equals("NPCDIALOG") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 3) { int npcid = Convert.ToInt32(value[0]); String txtmsg = value[1]; Dictionary <String, String> txtmenu = new Dictionary <String, String>(); String[] menus = value[2].Split(','); for (int idx = 0; idx < menus.Length; ++idx) { if ((idx + 1) % 2 == 0) { txtmenu.Add(menus[idx - 1], menus[idx]); } } game.getGuiGameNPC().setDialog(npcid, txtmsg, txtmenu); } } // Walk target if (msg[0].Equals("TARGETPOSITION") && msg.Length == 2) { // Split message value String[] value = msg[1].Split(' '); if (value.Length == 2) { float posx = Convert.ToSingle(value[0]); float posy = Convert.ToSingle(value[1]); } } // Action target if (msg[0].Equals("TARGETPLAYERNODE") && msg.Length == 2) { // Split message value String[] value = msg[1].Split(' '); if (value.Length == 1) { int id = Convert.ToInt32(value[0]); } } if (msg[0].Equals("TARGETMONSTERNODE") && msg.Length == 2) { // Split message value String[] value = msg[1].Split(' '); if (value.Length == 1) { int id = Convert.ToInt32(value[0]); } } if (msg[0].Equals("TARGETNPCNODE") && msg.Length == 2) { // Split message value String[] value = msg[1].Split(' '); if (value.Length == 1) { int id = Convert.ToInt32(value[0]); } } if (msg[0].Equals("TARGETWARPNODE") && msg.Length == 2) { // Split message value String[] value = msg[1].Split(' '); if (value.Length == 1) { int id = Convert.ToInt32(value[0]); } } // Requesting (Player, Monster, NPC, Warp, Item, ... etc) // START REQUEST -> Player node if (msg[0].Equals("LISTPLAYER") && msg.Length == 2) { List <String> value = new List <String>(msg[1].Split(' ')); for (int j = 0; j < value.Count; ++j) { if (SelectedCharacterID != Convert.ToInt32(value[j]) && !playersEntity.ContainsKey(value[j])) { network.Send("NODEPLAYER:" + value[j] + ";"); } } foreach (String key in playersEntity.Keys) { if (!value.Contains(key)) { // May play any effect before remove... playersEntity.Remove(key); break; } } } if (msg[0].Equals("NODEPLAYER") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 7 && !playersEntity.ContainsKey(value[0])) { playersEntity.Add(value[0], new UnitEntity(Convert.ToInt32(value[0]), value[1], classConfigs[Convert.ToInt16(value[2])], Convert.ToInt32(value[3]), Convert.ToInt32(value[4]), Convert.ToInt32(value[5]), Convert.ToInt32(value[6]), game, content, graphics, spriteBatch, entityNameFont, entityDamageFont, whiteRect, modelBank, itemBank, audioSystem, particleManager)); } } // END REQUEST -> Player node // START REQUEST -> Monster node if (msg[0].Equals("LISTMONSTER") && msg.Length == 2) { List <String> value = new List <String>(msg[1].Split(' ')); for (int j = 0; j < value.Count; ++j) { if (!monstersEntity.ContainsKey(value[j])) { network.Send("NODEMONSTER:" + value[j] + ";"); } } foreach (String key in monstersEntity.Keys) { if (!value.Contains(key)) { // May play any effect before remove... monstersEntity.Remove(key); break; } } } if (msg[0].Equals("NODEMONSTER") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 7 && !monstersEntity.ContainsKey(value[0])) { monstersEntity.Add(value[0], new UnitEntity(Convert.ToInt32(value[0]), value[1], classConfigs[Convert.ToInt16(value[2])], Convert.ToInt32(value[3]), Convert.ToInt32(value[4]), Convert.ToInt32(value[5]), Convert.ToInt32(value[6]), game, content, graphics, spriteBatch, entityNameFont, entityDamageFont, whiteRect, modelBank, itemBank, audioSystem, particleManager)); } } // END REQUEST -> Monster node // START REQUEST -> NPC node if (msg[0].Equals("LISTNPC") && msg.Length == 2) { List <String> value = new List <String>(msg[1].Split(' ')); for (int j = 0; j < value.Count; ++j) { if (!npcsEntity.ContainsKey(value[j])) { network.Send("NODENPC:" + value[j] + ";"); } } foreach (String key in npcsEntity.Keys) { if (!value.Contains(key)) { // May play any effect before remove... npcsEntity.Remove(key); break; } } } if (msg[0].Equals("NODENPC") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 7 && !npcsEntity.ContainsKey(value[0])) { npcsEntity.Add(value[0], new UnitEntity(Convert.ToInt32(value[0]), value[1], classConfigs[Convert.ToInt16(value[2])], Convert.ToInt32(value[3]), Convert.ToInt32(value[4]), Convert.ToInt32(value[5]), Convert.ToInt32(value[6]), game, content, graphics, spriteBatch, entityNameFont, entityDamageFont, whiteRect, modelBank, itemBank, audioSystem, particleManager)); } } // END REQUEST -> NPC node // START REQUEST -> Warp node if (msg[0].Equals("LISTWARP") && msg.Length == 2) { List <String> value = new List <String>(msg[1].Split(' ')); for (int j = 0; j < value.Count; ++j) { if (!warpsEntity.ContainsKey(value[j])) { network.Send("NODEWARP:" + value[j] + ";"); } } foreach (String key in warpsEntity.Keys) { if (!value.Contains(key)) { // May play any effect before remove... warpsEntity.Remove(key); break; } } } if (msg[0].Equals("NODEWARP") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 3 && !warpsEntity.ContainsKey(value[0])) { warpsEntity.Add(value[0], new WarpEntity(Convert.ToInt32(value[0]), Convert.ToSingle(value[1]), Convert.ToSingle(value[2]), content)); } } // END REQUEST -> Warp node // START REQUEST -> Item node if (msg[0].Equals("LISTITEM") && msg.Length == 2) { List <String> value = new List <String>(msg[1].Split(' ')); for (int j = 0; j < value.Count; ++j) { if (!itemsEntity.ContainsKey(value[j])) { network.Send("NODEITEM:" + value[j] + ";"); } } foreach (String key in itemsEntity.Keys) { if (!value.Contains(key)) { // May play any effect before remove... itemsEntity.Remove(key); break; } } } if (msg[0].Equals("NODEITEM") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 3 && !itemsEntity.ContainsKey(value[0])) { itemsEntity.Add(value[0], new ItemEntity(Convert.ToInt32(value[0]), Convert.ToInt16(value[1]), content, graphics, spriteBatch, entityNameFont, whiteRect, itemBank)); } } // END REQUEST -> Item node // UPDATE NODE if (msg[0].Equals("NODEPLAYERUPDATE") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 9) { UnitEntity ent = null; if (SelectedCharacterID == Convert.ToInt32(value[0])) { ent = playerEntity; } else { playersEntity.TryGetValue(value[0], out ent); } if (ent != null) { float posx = Convert.ToSingle(value[1]); float posy = Convert.ToSingle(value[2]); Vector3 pos = new Vector3(posx, 0, posy); if (ent.Equals(playerEntity)) { camera.target = pos; } ent.setPosition(pos); ent.currentState(GameState.anim_anim + 1 + Convert.ToInt32(value[3])); ent.curHP = Convert.ToInt32(value[4]); ent.maxHP = Convert.ToInt32(value[5]); ent.curSP = Convert.ToInt32(value[6]); ent.maxSP = Convert.ToInt32(value[7]); float roty = Convert.ToSingle(value[8]); ent.setRotation(new Vector3(0, roty, 0)); } } } if (msg[0].Equals("NODEMONSTERUPDATE") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 9) { UnitEntity ent = null; if (monstersEntity.TryGetValue(value[0], out ent)) { float posx = Convert.ToSingle(value[1]); float posy = Convert.ToSingle(value[2]); ent.setPosition(new Vector3(posx, 0, posy)); ent.currentState(GameState.anim_anim + 1 + Convert.ToInt32(value[3])); ent.curHP = Convert.ToInt32(value[4]); ent.maxHP = Convert.ToInt32(value[5]); ent.curSP = Convert.ToInt32(value[6]); ent.maxSP = Convert.ToInt32(value[7]); float roty = Convert.ToSingle(value[8]); ent.setRotation(new Vector3(0, roty, 0)); } } } if (msg[0].Equals("NODENPCUPDATE") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 9) { UnitEntity ent = null; if (npcsEntity.TryGetValue(value[0], out ent)) { float posx = Convert.ToSingle(value[1]); float posy = Convert.ToSingle(value[2]); ent.setPosition(new Vector3(posx, 0, posy)); ent.currentState(GameState.anim_anim + 1 + Convert.ToInt32(value[3])); ent.curHP = Convert.ToInt32(value[4]); ent.maxHP = Convert.ToInt32(value[5]); ent.curSP = Convert.ToInt32(value[6]); ent.maxSP = Convert.ToInt32(value[7]); float roty = Convert.ToSingle(value[8]); ent.setRotation(new Vector3(0, roty, 0)); } } } // Damage if (msg[0].Equals("PLAYERNODEDAMAGE") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 2 && SelectedCharacterID > 0) { UnitEntity ent = null; if (SelectedCharacterID == Convert.ToInt32(value[0])) { ent = playerEntity; } else { playersEntity.TryGetValue(value[0], out ent); } if (ent != null) { // Show damage ent.recieveDamage(Convert.ToInt32(value[1])); } } } if (msg[0].Equals("MONSTERNODEDAMAGE") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 2 && SelectedCharacterID > 0) { UnitEntity ent = null; if (monstersEntity.TryGetValue(value[0], out ent)) { // Show damage ent.recieveDamage(Convert.ToInt32(value[1])); } } } if (msg[0].Equals("NPCNODEDAMAGE") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 2) { UnitEntity ent = null; if (npcsEntity.TryGetValue(value[0], out ent)) { // Show damage ent.recieveDamage(Convert.ToInt32(value[1])); } } } // Inventory list if (msg[0].Equals("INVENTORYINFO") && msg.Length == 2) { GUIGameInventory inven = game.getGuiGameInventory(); GUIGameEquipment equipm = game.getGuiGameEquipment(); // Split message value List <String> value = new List <String>(msg[1].Split(' ')); for (int j = 0; j < value.Count; ++j) { String[] itemData = value[j].Split('&'); if (itemData.Length == 10 && SelectedCharacterID > 0) { int inventoryidx = Convert.ToInt32(itemData[0]); int itemid = Convert.ToInt32(itemData[1]); short amount = Convert.ToInt16(itemData[2]); short equip = Convert.ToInt16(itemData[3]); short refine = Convert.ToInt16(itemData[4]); int attributeid = Convert.ToInt32(itemData[5]); int slot1 = Convert.ToInt32(itemData[6]); int slot2 = Convert.ToInt32(itemData[7]); int slot3 = Convert.ToInt32(itemData[8]); int slot4 = Convert.ToInt32(itemData[9]); if (equip != 0) { InventoryItemData newItemData = new InventoryItemData(itemid, amount, refine, attributeid, slot1, slot2, slot3, slot4); if (!equipm.isSameItemData(equip, newItemData)) { equipm.setItemData(equip, newItemData); } } else { InventoryItemData newItemData = new InventoryItemData(itemid, amount, refine, attributeid, slot1, slot2, slot3, slot4); if (!inven.isSameItemData(inventoryidx, newItemData)) { inven.setItemData(inventoryidx, newItemData); } } } } } // Equipment if (msg[0].Equals("NODEPLAYEREQUIPMENT") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 7 && SelectedCharacterID > 0) { int id = Convert.ToInt32(value[0]); int itemid_head = Convert.ToInt32(value[1]); int itemid_body = Convert.ToInt32(value[2]); int itemid_hand = Convert.ToInt32(value[3]); int itemid_foot = Convert.ToInt32(value[4]); int itemid_weaponR = Convert.ToInt32(value[5]); int itemid_weaponL = Convert.ToInt32(value[6]); if (id == SelectedCharacterID) { playerEntity.setEquipmentItemID(itemid_head, itemid_body, itemid_hand, itemid_foot, itemid_weaponR, itemid_weaponL); } else { if (playersEntity.ContainsKey("" + id)) { playersEntity["" + id].setEquipmentItemID(itemid_head, itemid_body, itemid_hand, itemid_foot, itemid_weaponR, itemid_weaponL); } } } } if (msg[0].Equals("NODEMONSTEREQUIPMENT") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 7 && SelectedCharacterID > 0) { int id = Convert.ToInt32(value[0]); int itemid_head = Convert.ToInt32(value[1]); int itemid_body = Convert.ToInt32(value[2]); int itemid_hand = Convert.ToInt32(value[3]); int itemid_foot = Convert.ToInt32(value[4]); int itemid_weaponR = Convert.ToInt32(value[5]); int itemid_weaponL = Convert.ToInt32(value[6]); if (monstersEntity.ContainsKey("" + id)) { monstersEntity["" + id].setEquipmentItemID(itemid_head, itemid_body, itemid_hand, itemid_foot, itemid_weaponR, itemid_weaponL); } } } if (msg[0].Equals("NODENPCEQUIPMENT") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length == 7 && SelectedCharacterID > 0) { int id = Convert.ToInt32(value[0]); int itemid_head = Convert.ToInt32(value[1]); int itemid_body = Convert.ToInt32(value[2]); int itemid_hand = Convert.ToInt32(value[3]); int itemid_foot = Convert.ToInt32(value[4]); int itemid_weaponR = Convert.ToInt32(value[5]); int itemid_weaponL = Convert.ToInt32(value[6]); if (npcsEntity.ContainsKey("" + id)) { npcsEntity["" + id].setEquipmentItemID(itemid_head, itemid_body, itemid_hand, itemid_foot, itemid_weaponR, itemid_weaponL); } } } if (msg[0].Equals("CHAT") && msg.Length == 2) { String[] value = msg[1].Split(' '); if (value.Length > 0 && SelectedCharacterID > 0) { byte msgType = Convert.ToByte(value[0]); String charid = value[1]; String recMessage = ""; String name = ""; switch (msgType) { case 0: if (charid.Equals("" + playerEntity.getID())) { name = playerEntity.getName(); } else { name = playersEntity[charid].getName(); } for (int index = 2; index < value.Length; ++index) { recMessage += (value[index] + " "); } game.getGuiGameChat().InsertMessage(msgType, name, recMessage); break; case 1: if (charid.Equals("" + playerEntity.getID())) { name = playerEntity.getName(); } else { name = playersEntity[charid].getName(); } recMessage += (" [" + name + "]"); for (int index = 2; index < value.Length; ++index) { recMessage += (value[index] + " "); } game.getGuiGameChat().InsertMessage(msgType, name, recMessage); break; case 2: break; case 3: break; } } } } // For scope } // Try scope catch (Exception ex) { Debug.WriteLine(ex.StackTrace); } // Sleep 50ms avoiding 100% CPU Thread.Sleep(50); } }
public void init(GUIGameEquipment guiGameEquipment) { this.guiGameEquipment = guiGameEquipment; }