public void Update(object _plugin) { RaiseEventTestPlugin RETP = (RaiseEventTestPlugin)_plugin; isAlive = true; m_statemanager = new StateManager <STATE>(); m_statemanager.CurrstateReqUpdate = true; m_statemanager.AddUpdateFunction(STATE.IDLE, Idle); m_statemanager.AddUpdateFunction(STATE.CHASE, Chase); m_statemanager.AddUpdateFunction(STATE.ROAM, Roam); m_statemanager.AddUpdateFunction(STATE.ATTACK, Attack); m_statemanager.Currstate = m_statemanager.Prevstate = STATE.IDLE; while (isAlive) { //run AI Code lock (_info) { m_statemanager.Update(); RETP.SendMessage(103, MonsterInfo.Serialize(_info)); if (_newinfo != null) { lock (_newinfo) { _info.playerposx = _newinfo.playerposx; _info.playerposz = _newinfo.playerposz; _info.playerhp = _newinfo.playerhp; _info.hp = _newinfo.hp; _newinfo = null; } } } CustomObject co = new CustomObject(); co.Init(); co.message = "Update Success " + m_statemanager.Currstate.ToString(); RETP.SendMessage(169, CustomObject.Serialize(co) ); System.Threading.Thread.Sleep(500); } }
public override void OnRaiseEvent(IRaiseEventCallInfo info) { try { base.OnRaiseEvent(info); } catch (Exception e) { this.PluginHost.BroadcastErrorInfoEvent(e.ToString(), info); return; } switch (info.Request.EvCode) { case 1: { //string RecvdMessage = Encoding.Default.GetString((byte[])info.Request.Data); //string PlayerName = PackageDecoder.GetValue(RecvdMessage, "PlayerName"); //string Password = PackageDecoder.GetValue(RecvdMessage, "Password"); AccountdDetails ad = (AccountdDetails)AccountdDetails.Deserialize((byte[])info.Request.Data); string PlayerName = ad.userid; string Password = ad.pw; CustomObject ret = new CustomObject(); ret.Init(); ret.message = "WELCOME"; this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, CustomObject.Serialize(ret) } }, evCode: info.Request.EvCode, cacheOp: 0); int usernameexists = Convert.ToInt32(connector.ConnectAndRunScalar("SELECT COUNT(accountdb.account_name) FROM accountdb WHERE account_name = '" + PlayerName + "'")); if (Convert.ToInt32(usernameexists) == 0) { int rowsaffected = connector.ConnectAndRunNonQuery("INSERT INTO accountdb (account_name, password, date_created) VALUES('" + PlayerName + "', '" + Password + "', now())"); if (rowsaffected == 1) { ret.message = "SIGNUP SUCCESS"; this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, CustomObject.Serialize(ret) } }, evCode: info.Request.EvCode, cacheOp: 0); } } else { string olwpw = Convert.ToString(connector.ConnectAndRunScalar("SELECT accountdb.password FROM accountdb WHERE accountdb.account_name = '" + PlayerName + "'")); if (Password != olwpw) { ret.message = "NOT VALID"; this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, CustomObject.Serialize(ret) } }, evCode: (byte)(69), cacheOp: 0); return; } } ret.message = "LOGIN SUCESS"; this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, CustomObject.Serialize(ret) } }, evCode: (byte)(5), cacheOp: 0); break; } case 2: { PlayerPos pp = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data); string RecvdMessage = Encoding.Default.GetString((byte[])info.Request.Data); string PlayerName = pp.userid; //PackageDecoder.GetValue(RecvdMessage, "PlayerName"); string posx = Convert.ToString(pp.posx); //PackageDecoder.GetValue(RecvdMessage, "posx"); string posy = Convert.ToString(pp.posy); //PackageDecoder.GetValue(RecvdMessage, "posy"); string posz = Convert.ToString(pp.posz); //PackageDecoder.GetValue(RecvdMessage, "posz"); connector.ConnectAndRunNonQuery("UPDATE accountdb SET posx = " + posx + ",posy=" + posy + ",posz=" + posz + " WHERE account_name = '" + PlayerName + "'"); break; } case 3: { PlayerPos oldpp = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data); string PlayerName = oldpp.userid; PlayerPos pp = new PlayerPos(); pp.Init(); pp.userid = PackageDecoder.GetValue(PlayerName, "PlayerName"); pp.posx = (int)connector.ConnectAndRunScalar("Select posx from accountdb where account_name = '" + PlayerName + "'"); pp.posy = (int)connector.ConnectAndRunScalar("Select posy from accountdb where account_name = '" + PlayerName + "'"); pp.posz = (int)connector.ConnectAndRunScalar("Select posz from accountdb where account_name = '" + PlayerName + "'"); this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, PlayerPos.Serialize(pp) } }, evCode: (byte)(3), cacheOp: 0); break; } case 6: { PlayerPos pp = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data); string PlayerName = pp.userid; string Guild = pp.guild; connector.ConnectAndRunNonQuery("UPDATE accountdb SET guild = '" + Guild + "' WHERE account_name = '" + PlayerName + "'"); break; } case 7: { PlayerPos pp = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data); string PlayerName = pp.userid; pp.guild = Convert.ToString(connector.ConnectAndRunScalar("SELECT guild FROM accountdb WHERE account_name = '" + PlayerName + "'")); this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, PlayerPos.Serialize(pp) } }, evCode: (byte)(7), cacheOp: 0); break; } case 99: { AccountdDetails ad = (AccountdDetails)AccountdDetails.Deserialize((byte[])info.Request.Data); string PlayerName = ad.userid; string Password = ad.pw; connector.ConnectAndRunNonQuery("UPDATE accountdb SET password = '******' WHERE account_name = '" + PlayerName + "'"); break; } case 101: { MonsterInfo mi = (MonsterInfo)MonsterInfo.Deserialize((byte[])info.Request.Data); AI ai = new TestPlugin.AI(); ai._info = mi; ailist.Add(ai); multithreadmanager.AddThread(ai._info.name, new System.Threading.ParameterizedThreadStart(ai.Update), this); multithreadmanager.StartThread(ai._info.name); this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, MonsterInfo.Serialize(mi) } }, evCode: (byte)(102), cacheOp: 0); break; } case 103: { PlayerPos mi = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data); this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, PlayerPos.Serialize(mi) } }, evCode: (byte)(104), cacheOp: 0); break; } case 150: { PlayerPos mi = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data); PartitioningInfo pi = new PartitioningInfo(); pi.Init(); pi.objname = mi.userid; pi.currtile = MapPartitioningButNotPartitioningIsJustSplittingUpTheMap.ReturnTileViaPos(mi.posx, mi.posz); this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, PartitioningInfo.Serialize(pi) } }, evCode: info.Request.EvCode, cacheOp: 0); break; } case 151: { PlayerPos mi = (PlayerPos)PlayerPos.Deserialize((byte[])info.Request.Data); ListPartitioningInfo pi = new ListPartitioningInfo(); pi.Init(); pi.playerposx = mi.posx; pi.playerposz = mi.posz; pi.objname = mi.userid; pi.currtile = MapPartitioningButNotPartitioningIsJustSplittingUpTheMap.ReturnTileViaPos(mi.posx, mi.posz); pi._multitile = MapPartitioningButNotPartitioningIsJustSplittingUpTheMap.ReturnSurroundingTilesViaCurrentTile(pi.currtile); this.PluginHost.BroadcastEvent(target: (byte)info.ActorNr, senderActor: 0, targetGroup: 0, data: new Dictionary <byte, object>() { { (byte)245, ListPartitioningInfo.Serialize(pi) } }, evCode: info.Request.EvCode, cacheOp: 0); break; } case 180: { MonsterInfo mi = (MonsterInfo)MonsterInfo.Deserialize((byte[])info.Request.Data); AI updater = ailist.Find(x => x._info.name == mi.name); updater._newinfo = mi; break; } } }