void createMonster(MsgCreate m) { Monster u = mUnitMgr.getUnit(m.guid, UnitType.Monster, m.tid) as Monster; u.setParam(m.pos, m.dir); u.agentId = m.agentId; }
void createPlayer(MsgCreate m) { Player u = mUnitMgr.getUnit(m.guid, UnitType.Player, m.tid) as Player; u.agentId = m.agentId; u.onSyncState(m); u.setParam(m.pos, m.dir); if (u.isAgent) { EventMgr.single.SendEvent("Game.Player", u); } }
void onReqUnit(NetworkMessage msg) { Log.i("LanHost onReqUnit", Log.Tag.Net); MsgReqUnit m = msg.ReadMessage <MsgReqUnit> (); Unit u = mUnitMgr.getUnit(m.guid); MsgCreate reply = new MsgCreate(); reply.unitType = u.type; reply.guid = u.guid; reply.agentId = mClients[msg.conn.connectionId].accoundId; reply.pos = u.pos; reply.dir = u.dir; reply.state = u.state; reply.tid = u.tid; sendTo(msg.conn.connectionId, (short)MyMsgId.Create, reply); }
public DropItems createDropItems(int tid, Vector3 pos, Vector3 dir, uint instanceID = 0) { DropItems u = mUnitMgr.getUnit(0, UnitType.Drop, tid) as DropItems; u.setParam(pos, dir, instanceID); MsgCreate reply = new MsgCreate(); reply.agentId = u.agentId; reply.guid = u.guid; reply.pos = u.pos; reply.dir = u.dir; reply.state = u.state; reply.tid = u.tid; reply.unitType = u.type; sendToAll((short)MyMsgId.Create, reply); return(u); }
public Player createPlayer(int tid, Vector3 pos, Vector3 dir, uint agentId = 0) { Player u = mUnitMgr.getUnit(0, UnitType.Player, tid) as Player; u.agentId = agentId; u.setParam(pos, dir); MsgCreate reply = new MsgCreate(); reply.agentId = u.agentId; reply.guid = u.guid; reply.pos = u.pos; reply.dir = u.dir; reply.state = u.state; reply.tid = u.tid; reply.unitType = u.type; sendToAll((short)MyMsgId.Create, reply); return(u); }
void onUnitCreate(NetworkMessage msg) { Log.i("LanClient onUnitCreate", Log.Tag.Net); MsgCreate m = msg.ReadMessage <MsgCreate> (); switch (m.unitType) { case UnitType.Player: createPlayer(m); break; case UnitType.Monster: createMonster(m); break; case UnitType.Drop: createDropItems(m); break; } }
public Monster createMonster(int tid, Vector3 dir, Vector3 pos, uint agentId = 0) { Monster u = mUnitMgr.getUnit(0, UnitType.Monster, tid) as Monster; if (u == null) { return(null); } u.agentId = agentId; u.setParam(pos, dir); MsgCreate reply = new MsgCreate(); reply.agentId = u.agentId; reply.guid = u.guid; reply.pos = u.pos; reply.dir = u.dir; reply.state = u.state; reply.tid = u.tid; reply.unitType = u.type; sendToAll((short)MyMsgId.Create, reply); return(u); }
void OnReqCreateHero(NetworkMessage msg) { Log.i("LanHost OnReqCreateHero", Log.Tag.Net); Client client = getClient(msg.conn); if (client.playerGUID != 0) { //删除上个角色 Unit lu = mUnitMgr.getUnit(client.playerGUID); if (lu != null) { lu.decState(UnitState.Exist, true); } } MsgReqCreateHero m = msg.ReadMessage <MsgReqCreateHero> (); Player u = createPlayer(m.heroID, Vector3.zero, Vector3.forward, mClients [msg.conn.connectionId].accoundId); client.playerGUID = u.guid; //同步其周围玩家信息 List <Unit> units = mUnitMgr.getUnitInSphere(1, u.pos, 1000); for (int i = 0; i < units.Count; ++i) { Unit o = units[i]; if (o.guid == u.guid || !o.isState(UnitState.Exist)) { continue; } MsgCreate reply = new MsgCreate(); reply.agentId = o.agentId; reply.guid = o.guid; reply.pos = o.pos; reply.dir = o.dir; reply.state = o.state; reply.tid = o.tid; reply.unitType = o.type; sendTo(msg.conn.connectionId, (short)MyMsgId.Create, reply); } }
void createDropItems(MsgCreate m) { DropItems u = mUnitMgr.getUnit(m.guid, UnitType.Drop, m.tid) as DropItems; u.setParam(m.pos, m.dir); }