public void Enter(ActorPeer peer) { _executionFiber.Enqueue(() => { ListPeer.Add(peer); SpawnPlayer(peer); }); }
public void Exit(ActorPeer peer) { _executionFiber.Enqueue(() => { ListPeer.Remove(peer); }); IActor player = ListPlayer.FirstOrDefault(a => a.peerID == peer.playerID); if (player != null) { lock (ListPlayer) { ListPlayer.Remove(player); } Region currentRegion = Region.GetRegionFromPosition(player); currentRegion.ActorExit(player); } }
private void SendNewInfoToPeer(ActorPeer peer, IActor player) { List<IActor> listPlayerInRegion = new List<IActor>(); List<IActor> listCreepInRegion = new List<IActor>(); List<Region> listInterestRegion = GetInterestRegion(); foreach (var region in listInterestRegion) { listPlayerInRegion.AddRange(region.listPlayer); listCreepInRegion.AddRange(region.listCreep); } listPlayerInRegion.Remove(player); InterestRegions dataInterest = GetDataInterestRegion(listInterestRegion); dataInterest.playerPosition = new MPosition() { x = player.posX, y = player.posY }; EventData evtDataCrrepAndOtherPlayers = new EventData() { Code = (byte)AckEventType.CreateActor, Parameters = new Dictionary<byte, object>() { {(byte)Parameter.Player,GeneralFunc.Serialize(listPlayerInRegion)}, {(byte)Parameter.Creep, GeneralFunc.Serialize(listCreepInRegion)}, {(byte)Parameter.Regions,GeneralFunc.Serialize(dataInterest)} } }; peer.SendEvent(evtDataCrrepAndOtherPlayers, new SendParameters()); }
public void SpawnPlayer(ActorPeer peer) { IActor player = new IActor() { actorType = (byte)ActorType.Player, peerID = peer.playerID, actorID = AllocateActorId(), posX = 10, posY = 10 }; ListPlayer.Add(player); //#region Test Code ////List<MPlayer> listTest = new List<MPlayer>() ////{ //// new MPlayer() { id = 1,name = "duc anh"}, //// new MPlayer() {id = 2, name = "hoang anh"} ////}; //EventData evtData = new EventData() //{ // Code = (byte)AckEventType.CreateActor, // Parameters = new Dictionary<byte, object>() // { // {(byte)ActorType.Creep, GeneralFunc.Serialize(listCreep)} // } //}; //peer.SendEvent(evtData, new SendParameters()); //#endregion Region startRegion = Region.GetRegionFromPosition(player); Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaa"); startRegion.ActorEnter(player); EventData evtPlayer = new EventData() { Code = (byte)AckEventType.AssignPlayerID, Parameters = new Dictionary<byte, object>() { {0,GeneralFunc.Serialize(player)} } }; peer.SendEvent(evtPlayer, new SendParameters()); }
public void ProcessRequest(ActorPeer sender, OperationRequest operationRequest, SendParameters sendParameters) { if (operationRequest.OperationCode == (byte)AckRequestType.MoveCommand) { Movement movement = GeneralFunc.Deserialize<Movement>(operationRequest.Parameters[(byte)Parameter.Data] as byte[]); // find actor IActor player = (ListPlayer.Find(pl => pl.actorID == movement.actorID)); Region oldRegion = Region.GetRegionFromPosition(player); player.posX = movement.posX; player.posY = movement.posY; Region newRegion = Region.GetRegionFromPosition(player); if (oldRegion != newRegion) { oldRegion.ActorExit(player); newRegion.ActorEnter(player); } } }
public void OnOperationRequest(ActorPeer sender, OperationRequest operationRequest, SendParameters sendParameters) { _executionFiber.Enqueue(() => { this.ProcessRequest(sender, operationRequest, sendParameters); }); }