예제 #1
0
        private void OnMessageReceived(byte[] message)
        {
            if (message[0] == MessageId.MATCH_END)
            {
                DIContainer.Logger.Debug("Match end message received, switching to MatchEndState");
                this.matchStateMachine.ChangeMatchState(new EndMatchState());
                return;
            }

            if (message[0] == MessageId.UNIT_STATE)
            {
                UnitStateMessage unitStateMessage = new UnitStateMessage(message);

                /*DIContainer.Logger.Debug(string.Format(
                 *  "Received unit state message = UnitId: '{0}' XPosition: '{1}' YPosition: '{2}' Rotation: '{3}' Frame: '{4}'",
                 *  unitStateMessage.UnitId, unitStateMessage.XPosition, unitStateMessage.YPosition, unitStateMessage.Rotation, unitStateMessage.Frame));*/

                unitStateMessageBuffer[bufferCursor].Add(unitStateMessage);
            }

            if (message[0] == MessageId.POSITION_CONFIRMATION)
            {
                PositionConfirmationMessage positionConfirmationMessage = new PositionConfirmationMessage(message);
                PCMBuffer[bufferCursor].Add(positionConfirmationMessage);
            }

            if (message[0] == MessageId.UNIT_ABILITY_ACTIVATION)
            {
                UnitAbilityActivationMessage unitAbilityActivationMessage = new UnitAbilityActivationMessage(message);
                unitAbilityMessageBuffer[bufferCursor].Add(unitAbilityActivationMessage);
            }

            if (message[0] == MessageId.UNIT_SPAWN)
            {
                UnitSpawnMessage unitSpawnMessage = new UnitSpawnMessage(message);
                unitSpawnMessageBuffer[bufferCursor].Add(unitSpawnMessage);
            }
        }
예제 #2
0
        private void UpdateUnitAbilityActivations(List <UnitAbilityActivationMessage> receivedUnitAbilityMessagesSinceLastFrame)
        {
            // sort by oldest frame to newest frame
            receivedUnitAbilityMessagesSinceLastFrame.Sort((message1, message2) =>
            {
                return(message1.StartFrame == message2.StartFrame ? 0 : MatchSimulationUnit.IsFrameInFuture(message1.StartFrame, message2.StartFrame) ? 1 : -1);
            });

            for (int i = 0; i < receivedUnitAbilityMessagesSinceLastFrame.Count; i++)
            {
                UnitAbilityActivationMessage unitAbilityActivationMessage = receivedUnitAbilityMessagesSinceLastFrame[i];

                MatchSimulationUnit unitToUpdate;
                if (simulationUnits.TryGetValue(unitAbilityActivationMessage.UnitId, out unitToUpdate))
                {
                    unitToUpdate.AbilityActivationSubject.OnNext(new AbilityActivation
                    {
                        Rotation        = UnitValueConverter.ToUnityRotation(unitAbilityActivationMessage.Rotation),
                        StartFrame      = unitAbilityActivationMessage.StartFrame,
                        ActivationFrame = unitAbilityActivationMessage.ActivationFrame
                    });
                }
            }
        }