there is just some types working yet:
Npc Text,
Npc Link,
Npc Face,
Npc End,
Npc Char stats Check (not all coded),
Npc Teleport,
Npc Save old MapID, X, and Y when you are teleported
Now let's start
into GameServerProject find it: public static void LoadNpcs() in Database.cs
change to:
Code:
public static void LoadNpcs() { MySqlCommand Cmd = new MySqlCommand("SELECT * FROM `cq_npc`", DatabaseConnection.NewConnection()); MySqlDataReader DR = Cmd.ExecuteReader(CommandBehavior.CloseConnection); while(DR.Read()) { Struct.NPC NPC = new Struct.NPC(); NPC.Direction = Convert.ToInt32(DR["type"]); NPC.Flag = Convert.ToInt32(DR["sort"]); NPC.ID = Convert.ToInt32(DR["id"]); NPC.Map = Convert.ToInt32(DR["mapid"]); NPC.SubType = Convert.ToInt32(DR["lookface"]); NPC.Type = Convert.ToInt32(DR["id"]); NPC.X = Convert.ToInt32(DR["cellx"]); NPC.Y = Convert.ToInt32(DR["celly"]); if(!Nano.Npcs.ContainsKey(NPC.ID)) Nano.Npcs.Add(NPC.ID, NPC); } Console.WriteLine("[GameServer] Loaded " + Nano.Npcs.Count + " npcs into the world."); DR.Close(); Cmd.Dispose(); }
Code:
public static void GetNPCTask(int MyID, ClientSocket CSocket) { MySqlCommand Cmd = new MySqlCommand("SELECT * FROM `cq_npc` WHERE `id` = " + MyID + "", DatabaseConnection.NewConnection()); MySqlDataReader DR = Cmd.ExecuteReader(CommandBehavior.CloseConnection); while (DR.Read()) { int task0 = Convert.ToInt32(DR["task0"]); int task1 = Convert.ToInt32(DR["task1"]); int actions = 0; if (task0 != 0) { actions = task0; } else if (task1 != 0) { actions = task1; } if (actions != 0) { GetTaskAction(task0, CSocket); } } DR.Close(); Cmd.Dispose(); } public static void LoadActions(int ActionID, ClientSocket CSocket) { MySqlCommand CMD = new MySqlCommand("SELECT * FROM `actions` WHERE `id` = " + ActionID + "", DatabaseConnection.NewConnection()); MySqlDataReader DR = CMD.ExecuteReader(CommandBehavior.CloseConnection); while (DR.Read()) { bool callfail = false; int id_next = Convert.ToInt32(DR["id_next"]); int id_fail = Convert.ToInt32(DR["id_nextfail"]); int type = Convert.ToInt32(DR["type"]); int data = Convert.ToInt32(DR["data"]); string param = Convert.ToString(DR["param"]); if (type == 101) //npc text { param.Replace("%user_name", CSocket.Client.Name); Handlers.Handler.Text(param, CSocket); } else if (type == 102) //npc link { string[] spit = param.Split(' '); int a = CSocket.Client.NpcTasks.Count +1; int link = 0; try { link = Convert.ToInt32(spit[1]); } catch { } CSocket.Client.NpcTasks.Add(a, link); Handlers.Handler.Link(spit[0], a, CSocket); } else if (type == 103)//npc input { string[] spit = param.Split(' '); int a = CSocket.Client.NpcTasks.Count + 1; int link = 0; int unk = 0; try { link = Convert.ToInt32(spit[1]); unk = Convert.ToInt32(spit[0]); } catch { } CSocket.Client.NpcTasks.Add(a, link); Handlers.Handler.Input(spit[2], link, CSocket); } else if (type == 104)//npc face { string[] spit = param.Split(' '); int face = 0; try { face = Convert.ToInt32(spit[2]); } catch { } Handlers.Handler.Face(face, CSocket); } else if (type == 120)//npc end { Handlers.Handler.End(CSocket); } else if (type == 1001)//check user { string[] spit = param.Split(' '); string tocheck = spit[0]; string operatorr = spit[1]; string value = spit[2]; callfail = NpcActions.TQCheckUserStats(tocheck, operatorr, value, CSocket); } else if (type == 1003)//transport to map { string[] spit = param.Split(' '); Handlers.Handler.Teleport(int.Parse(spit[0]), int.Parse(spit[1]), int.Parse(spit[2]), 0, CSocket); } else if (type == 1004) //save map { string[] spit = param.Split(' '); CSocket.Client.RecordMap = int.Parse(spit[0]); CSocket.Client.RecordX = int.Parse(spit[1]); CSocket.Client.RecordY = int.Parse(spit[2]); Database.SaveCharacter(CSocket.Client); } else if (type == 1006) //transport to recored map { Handlers.Handler.Teleport(CSocket.Client.RecordMap, CSocket.Client.RecordX, CSocket.Client.RecordY, 0, CSocket); } if (id_next != 0 && callfail == false) { LoadActions(id_next, CSocket); } if (id_fail != 0 && callfail == true) { LoadActions(id_fail, CSocket); } } CMD.Dispose(); DR.Close(); } public static void GetTaskAction(int taskID, ClientSocket CSocket) { MySqlCommand CMD = new MySqlCommand("SELECT * FROM `task` WHERE `id` = " + taskID + "", DatabaseConnection.NewConnection()); MySqlDataReader DR = CMD.ExecuteReader(CommandBehavior.CloseConnection); while (DR.Read()) { int id_next = Convert.ToInt32(DR["id_next"]); LoadActions(id_next, CSocket); } CMD.Dispose(); DR.Close(); }
Code:
/* * Created by SharpDevelop. * User: sams * Date: 3/18/2009 * Time: 8:02 PM * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using System.Collections; using System.Collections.Generic; using CoEmu_v2_GameServer.Connections; using CoEmu_v2_GameServer.Entities; using CoEmu_v2_GameServer.Structs; using CoEmu_v2_GameServer.Packets; using CoEmu_v2_GameServer.Calculations; using Lua511; using LuaInterface; namespace CoEmu_v2_GameServer.Handlers { /// <summary> /// Description of NpcTalk. /// </summary> public partial class Handler { public static void NpcTalk(ClientSocket CSocket, int ID, int LinkBack) { if(ID > 0) CSocket.Client.LastNPC = ID; switch(ID) { case 8://TC - WHS { CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog)); break; } case 10012://PC - WHS { CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog)); break; } case 10011://DC - WHS { CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog)); break; } case 10028://AM - WHS { CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog)); break; } case 10027://BI - WHS { CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog)); break; } case 44://MA - WHS { CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog)); break; } default: { if (LinkBack == 0) { CSocket.Client.NpcTasks.Clear(); Database.Database.GetNPCTask(ID, CSocket); break; } else { int task = 0; foreach (DictionaryEntry DE in CSocket.Client.NpcTasks) { if (Convert.ToInt32(DE.Key) == LinkBack) { task = Convert.ToInt32(DE.Value); } } Database.Database.GetTaskAction(task, CSocket); break; } } } } public static void Text(string value, ClientSocket CSocket) { CSocket.Send(ConquerPacket.NPCTalk(255, 1, value)); } public static void Money(int value, ClientSocket CSocket) { CSocket.Client.Money += value; CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.Money, Struct.StatusTypes.InvMoney)); } public static void CPs(int value, ClientSocket CSocket) { CSocket.Client.CPs += value; CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.CPs, Struct.StatusTypes.InvCPoints)); } public static void Link(string value, int LinkBack, ClientSocket CSocket) { CSocket.Send(ConquerPacket.NPCTalk(LinkBack, 2, value)); } public static void Input(string text, int LinkBack, ClientSocket CSocket) { CSocket.Send(ConquerPacket.NPCTalk(LinkBack, 3, text)); } public static void Face(int Face, ClientSocket CSocket) { CSocket.Send(ConquerPacket.NPCTalk(2544, Face, 255, 4)); } public static void End(ClientSocket CSocket) { CSocket.Send(ConquerPacket.NPCTalk(0, 0, 255, 100)); } } }
and under of this code add:
Code:
public Hashtable NpcTasks = new Hashtable();//temp npctask loads public int RecordMap = 1002; public int RecordX = 438; public int RecordY = 377;
bellow of it add
Client.RecordMap = Convert.ToInt32(DR["RecordMap"]);
Client.RecordX = Convert.ToInt32(DR["RecordX"]);
Client.RecordY = Convert.ToInt32(DR["RecordY"]);
and now find it: public static void SaveCharacter(Character Client)
and change for
Code:
public static void SaveCharacter(Character Client) { MySqlCommand Cmd = new MySqlCommand("UPDATE `characters` SET `Level` = " + Client.Level + ", `WHMoney` = " + Client.WHMoney + ", `PkPoints` = " + Client.PkPoints + ", `xCord` = " + Client.X + ", `yCord` = " + Client.Y + ", `Map` = " + (int)Client.Map + ", `HairStyle` = " + Client.Hair + ", `Class` = " + (int)Client.Class + ", `Exp` = " + Client.Exp + ", `Money` = " + Client.Money + ", `Str` = " + Client.Strength + ",`Vit` = " + Client.Vitality + ", `Spi` = " + Client.Spirit + ", `Dex` = " + Client.Dexterity + ", `StatPoints` = " + Client.StatPoints + ", `FirstLog` = " + 1 + ", `Reborn` = " + Client.Reborn + ", `HP` = " + Client.CurrentHP + ", `MP` = " + Client.CurrentMP + ", `RecordMap` = " + Client.RecordMap + ", `RecordX` = " + Client.RecordX + ", `RecordY` = " + Client.RecordY +" WHERE `CharID` = " + Client.ID, DatabaseConnection.NewConnection()); Cmd.ExecuteNonQuery(); Cmd.Connection.Close(); Cmd.Connection.Dispose(); Cmd.Dispose(); }
and execute the batch of my sql (it will add table: actions, task, cq_npc, and update the character table (Junior_SQL.rar)
Credits goto:
Me (all code is mine work)
felipeboladao (for a little help) thx dude
magnon for the cq_actions very thx
More Updates coming soon when i get free time to code
and for who have a must english database and want help me/us to make it much perfect pm me