using System; using Model; namespace Hotfix { [MessageHandler(AppType.Map)] public class G2M_CreateUnitHandler : AMRpcHandler { protected override async void Run(Session session, G2M_CreateUnit message, Action reply) { M2G_CreateUnit response = new M2G_CreateUnit(); try { Unit unit = EntityFactory.Create(UnitType.Hero); await unit.AddComponent(new MapUnitEntityActorHandler()).AddLocation(); unit.AddComponent(message.GateSessionId); Game.Scene.GetComponent().Add(unit); response.UnitId = unit.Id; response.Count = Game.Scene.GetComponent().Count; reply(response); if (response.Count == 2) { Actor_CreateUnits actorCreateUnits = new Actor_CreateUnits(); Unit[] units = Game.Scene.GetComponent().GetAll(); foreach (Unit u in units) { actorCreateUnits.Units.Add(new UnitInfo() {UnitId = u.Id, X = (int)(u.Position.X * 1000), Z = (int)(u.Position.Z * 1000) }); } MessageHelper.Broadcast(actorCreateUnits); } } catch (Exception e) { ReplyError(response, e, reply); } } } }