Example #1
0
        private void UpdateUnitStates(List <UnitStateMessage> receivedUnitStateMessagesSinceLastFrame)
        {
            // sort by oldest frame to newest frame
            receivedUnitStateMessagesSinceLastFrame.Sort((message1, message2) =>
            {
                return(message1.Frame == message2.Frame ? 0 : MatchSimulationUnit.IsFrameInFuture(message1.Frame, message2.Frame) ? 1 : -1);
            });

            for (int i = 0; i < receivedUnitStateMessagesSinceLastFrame.Count; i++)
            {
                UnitStateMessage unitStateMessage = receivedUnitStateMessagesSinceLastFrame[i];

                MatchSimulationUnit unitToUpdate;

                if (localPlayer != null && localPlayer.UnitId == unitStateMessage.UnitId)
                {
                    // only update the health here and ignore position and rotation for the local player,
                    // since that will be confirmed via the PositionConfirmationMessage
                    localPlayer.HealthPercent.Value = unitStateMessage.HealthPercent;
                    return;
                }
                else if (!simulationUnits.TryGetValue(unitStateMessage.UnitId, out unitToUpdate))
                {
                    return;
                }

                unitToUpdate.SetConfirmedState(unitStateMessage.XPosition, unitStateMessage.YPosition,
                                               unitStateMessage.Rotation, unitStateMessage.HealthPercent, unitStateMessage.Frame);

                //DIContainer.Logger.Debug("Received usm with frame: " + unitStateMessage.Frame);
            }
        }
Example #2
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);
            }
        }