/// <summary> /// Sends move request to other players and self. /// Use only on host! /// </summary> /// <param name="node"></param> protected virtual void SendMoveRequest(Node node) { MatchMessageUnitMoved message = new MatchMessageUnitMoved(node.Position.x, node.Position.y, _unit.Id, _unit.OwnerId); _stateManager.SendMatchStateMessage(MatchMessageType.UnitMoved, message); _stateManager.SendMatchStateMessageSelf(MatchMessageType.UnitMoved, message); }
/// <summary> /// Starts unit movement towards given node /// </summary> /// <param name="message"></param> private void MoveUnit(MatchMessageUnitMoved message) { PlayerColor color = message.OwnerId == _connection.Session.UserId ? PlayerColor.Black : PlayerColor.Red; Unit unit = _units[color][message.UnitId]; Node node = Scene02BattleController.Instance.Nodes[message.NodeX, message.NodeY]; unit.Move(node); }
/// <summary> /// Reads match messages sent by other players, and fires locally events basing on opCode. /// </summary> /// <param name="opCode"></param> /// <param name="messageJson"></param> public void ReceiveMatchStateHandle(long opCode, string messageJson) { //Choosing which event should be invoked basing on opCode, then parsing json to MatchMessage class and firing event switch ((MatchMessageType)opCode) { //UNITS case MatchMessageType.UnitSpawned: MatchMessageUnitSpawned matchMessageUnitSpawned = MatchMessageUnitSpawned.Parse(messageJson); OnUnitSpawned?.Invoke(matchMessageUnitSpawned); break; case MatchMessageType.UnitMoved: MatchMessageUnitMoved matchMessageUnitMoved = MatchMessageUnitMoved.Parse(messageJson); OnUnitMoved?.Invoke(matchMessageUnitMoved); break; case MatchMessageType.UnitAttacked: MatchMessageUnitAttacked matchMessageUnitAttacked = MatchMessageUnitAttacked.Parse(messageJson); OnUnitAttacked?.Invoke(matchMessageUnitAttacked); break; //SPELLS case MatchMessageType.SpellActivated: MatchMessageSpellActivated matchMessageSpellActivated = MatchMessageSpellActivated.Parse(messageJson); OnSpellActivated?.Invoke(matchMessageSpellActivated); break; //CARDS case MatchMessageType.CardPlayRequest: if (_connection.BattleConnection.HostId == _connection.Account.User.Id) { MatchMessageCardPlayRequest matchMessageCardPlayRequest = MatchMessageCardPlayRequest.Parse(messageJson); OnCardRequested?.Invoke(matchMessageCardPlayRequest); } break; case MatchMessageType.CardPlayed: MatchMessageCardPlayed matchMessageCardPlayed = MatchMessageCardPlayed.Parse(messageJson); OnCardPlayed?.Invoke(matchMessageCardPlayed); break; case MatchMessageType.CardCanceled: MatchMessageCardCanceled matchMessageCardCancelled = MatchMessageCardCanceled.Parse(messageJson); OnCardCancelled?.Invoke(matchMessageCardCancelled); break; case MatchMessageType.StartingHand: MatchMessageStartingHand matchMessageStartingHand = MatchMessageStartingHand.Parse(messageJson); OnStartingHandReceived?.Invoke(matchMessageStartingHand); break; } }