Ejemplo n.º 1
0
 public override void BattleDamageReportReceived(BattleDamageReport battleDamageReport)
 {
     HandleIncomingBattleDamageReport(battleDamageReport, true, true, true, true, true);
     base.BattleDamageReportReceived(battleDamageReport);
 }
Ejemplo n.º 2
0
    public void HandleReceivedData(IMarshallable dataReceived)
    {
        //Debug.Log(dataReceived);
        switch (dataReceived.ObjectTypeToken)
        {
        case CommsMarshaller.ObjectTokens.NoObject:
            break;

        case CommsMarshaller.ObjectTokens.Enq:
            break;

        case CommsMarshaller.ObjectTokens.Ack:
            break;

        case CommsMarshaller.ObjectTokens.ClientInfoRequest:
            break;

        case CommsMarshaller.ObjectTokens.GameControlRequest:
            break;

        case CommsMarshaller.ObjectTokens.GameStateInfo:
            HandleGameStateInfo(dataReceived);
            break;

        case CommsMarshaller.ObjectTokens.GameUiControl:
            HandleGameUIControlInfo(dataReceived);
            break;

        case CommsMarshaller.ObjectTokens.MessageInfo:
            HandleMessageInfo(dataReceived);
            break;

        case CommsMarshaller.ObjectTokens.DefeatConditionSetInfo:
            break;

        case CommsMarshaller.ObjectTokens.DefeatConditionInfo:
            break;

        case CommsMarshaller.ObjectTokens.MessageString:
            MessageString str = dataReceived as MessageString;
            if (str != null)
            {
                //~ ShowMessage("MessageString: " + str.Message);
            }

            GameManager.Instance.MessageManager.AddMessage(str.Message, GameManager.MessageTypes.Game, null);

            break;

        case CommsMarshaller.ObjectTokens.BattleDamageReport:
            BattleDamageReport report     = dataReceived as BattleDamageReport;
            PlayerInfo         playerInfo = GameManager.Instance.PlayerInfo;

            if (report != null)
            {
                if (playerInfo != null)
                {
                    //GameManager.Instance.MessageManager.AddMessage(string.Format("MessageToAttacker: {0} - MessageToAttackee: {1}",
                    //    string.IsNullOrEmpty(report.MessageToAttacker) ? report.ToString() : report.MessageToAttacker,
                    //    string.IsNullOrEmpty(report.MessageToAttackee) ? report.ToString() : report.MessageToAttackee),
                    //    GameManager.MessageTypes.Battle, report.Position);
                    GameManager.Instance.MessageManager.AddMessage(report.PlayerInflictingDamageId == playerInfo.Id ? report.MessageToAttacker : report.MessageToAttackee, GameManager.MessageTypes.Battle, report.Position);


                    if (report.DamagePercent > 0)
                    {
                        ////Check if it is we who have been hit
                        if (report.PlayerSustainingDamageId == playerInfo.Id)
                        {
                            //Find unit which has been hit
                            PlayerUnit unit = GameManager.Instance.UnitManager.FindUnitById(report.TargetPlatformId);
                            if (unit != null)
                            {
                                //Spawn explosion
                                unit.SpawnExplosion();
                            }
                        }
                        else
                        {
                            //TODO:Jan du må huske TargetPlatformId
                            Enemy enemyUnit = GameManager.Instance.UnitManager.FindEnemyById(report.TargetPlatformId);
                            if (enemyUnit != null)
                            {
                                enemyUnit.SpawnExplosion();
                            }
                            else
                            {
                                Debug.Log("enemy is null");
                            }
                        }
                    }


                    float distanceLat = Mathf.Abs((float)report.Position.Latitude - GameManager.Instance.Origin.Latitude);
                    //float distanceLng = Mathf.Abs((float)report.Position.Longitude - GameManager.Instance.Origin.Longitude);

                    //if (distanceLat < 1 && distanceLng < 1)
                    //{
                    //    //calculate distance and bearing
                    //    //Coordinate origin = new Coordinate((float)this.Info.Position.Latitude, (float)this.Info.Position.Longitude);
                    //    Coordinate position = new Coordinate((float)report.Position.Latitude, (float)report.Position.Longitude);

                    //    Coordinate coord = CoordinateHelper.CalculateCoordinateFromBearingAndDistance(GameManager.Instance.Origin, position);

                    //    Vector3 worldPos = new Vector3(coord.Longitude, (float)report.Position.HeightOverSeaLevelM, coord.Latitude);

                    //    //Debug.Log(worldPos);
                    //    worldPos.y = transform.position.y;
                    //    //transform.position = Vector3.Lerp(transform.position, worldPos, Time.deltaTime);

                    //}
                }
            }

            break;

        case CommsMarshaller.ObjectTokens.GameInfo:
            HandleGameInfo(dataReceived);
            break;

        case CommsMarshaller.ObjectTokens.PlayerInfo:
            HandlePlayerInfo(dataReceived);
            break;

        case CommsMarshaller.ObjectTokens.PositionInfo:
            HandlePositionInfo(dataReceived);

            break;

        case CommsMarshaller.ObjectTokens.BaseUnitInfo:
            HandleBaseUnitInfo(dataReceived);
            break;

        case CommsMarshaller.ObjectTokens.GroupInfo:
            HandleGroupInfo(dataReceived);
            break;

        case CommsMarshaller.ObjectTokens.DetectedUnitInfo:
            HandleDetectedUnitInfo(dataReceived);
            break;

        case CommsMarshaller.ObjectTokens.OrderInfo:
            break;

        case CommsMarshaller.ObjectTokens.UnitMovementOrder:
            break;

        case CommsMarshaller.ObjectTokens.UnitEngagementOrder:
            break;

        case CommsMarshaller.ObjectTokens.UnitClass:
            Debug.Log("Received new unitclass");
            HandleUnitClass(dataReceived);
            break;

        case CommsMarshaller.ObjectTokens.WeaponClass:
            break;

        case CommsMarshaller.ObjectTokens.SensorClass:
            break;

        case CommsMarshaller.ObjectTokens.GameScenario:
            break;

        case CommsMarshaller.ObjectTokens.GameScenarioAlliance:
            break;

        case CommsMarshaller.ObjectTokens.GameScenarioPlayer:
            break;

        case CommsMarshaller.ObjectTokens.GameScenarioGroup:
            break;

        case CommsMarshaller.ObjectTokens.GameScenarioUnit:
            break;

        default:
            //~ ShowMessage("WTF?");
            break;
        }
    }
Ejemplo n.º 3
0
        private void HandleReceivedData(IMarshallable dataReceived)
        {
            switch (dataReceived.ObjectTypeToken)
            {
            case CommsMarshaller.ObjectTokens.NoObject:
                break;

            case CommsMarshaller.ObjectTokens.Enq:
                break;

            case CommsMarshaller.ObjectTokens.Ack:
                break;

            case CommsMarshaller.ObjectTokens.ClientInfoRequest:
                break;

            case CommsMarshaller.ObjectTokens.GameControlRequest:
                break;

            case CommsMarshaller.ObjectTokens.GameStateInfo:
                HandleGameStateInfo(dataReceived);
                break;

            case CommsMarshaller.ObjectTokens.MessageString:
                MessageString str = dataReceived as MessageString;
                if (str != null)
                {
                    if (str.Message.StartsWith("CHEAT"))
                    {
                        _selectedUnitInfo = null;
                        _unitInfoWindows.ShowInfo(str.Message);
                    }
                    else
                    {
                        ShowInfo("MessageString: " + str.Message);
                    }
                }

                break;

            case CommsMarshaller.ObjectTokens.BattleDamageReport:
                BattleDamageReport report = dataReceived as BattleDamageReport;
                if (report != null)
                {
                    if (_playerInfo != null)
                    {
                        //if (string.IsNullOrEmpty(report.MessageToAttacker) || string.IsNullOrEmpty(report.MessageToAttacker))
                        //{

                        //}
                        //if (report.PlayerInflictingDamageId == _playerInfo.Id)
                        //{
                        //    ShowInfo("+++" + report.MessageToAttacker);
                        //}
                        //else if (report.PlayerSustainingDamageId == _playerInfo.Id)
                        //{
                        //    ShowInfo("---" + report.MessageToAttackee);
                        //}
                    }
                    //ShowInfo("***BattleDamageReport: " + report.ToString());
                }

                break;

            case CommsMarshaller.ObjectTokens.GameInfo:
                GameInfo gameInfo = dataReceived as GameInfo;
                if (gameInfo != null)
                {
                    _gameInfo = gameInfo;
                    ShowInfo("*** GameInfo received.\n" + gameInfo.ToString());
                    //ShowInfo("GameWorldTimeSec=" + gameInfo.GameWorldTimeSec);
                    //ShowInfo("GameEngineTimeMs=" + gameInfo.GameEngineTimeMs);
                }
                break;

            case CommsMarshaller.ObjectTokens.PlayerInfo:
                PlayerInfo playerInfo = dataReceived as PlayerInfo;
                HandlePlayerInfo(playerInfo);
                break;

            case CommsMarshaller.ObjectTokens.PositionInfo:
                HandlePositionInfo(dataReceived);

                break;

            case CommsMarshaller.ObjectTokens.BaseUnitInfo:
                HandleBaseUnitInfo(dataReceived);

                break;

            case CommsMarshaller.ObjectTokens.GroupInfo:
                HandleGroupInfo(dataReceived);
                break;

            case CommsMarshaller.ObjectTokens.DetectedUnitInfo:
                HandleDetectedUnitInfo(dataReceived);
                break;

            case CommsMarshaller.ObjectTokens.DetectedGroupInfo:
                HandleDetectedGroupInfo(dataReceived);
                break;

            case CommsMarshaller.ObjectTokens.MessageInfo:
                HandleMessageInfo(dataReceived);
                break;

            case CommsMarshaller.ObjectTokens.OrderInfo:
                break;

            case CommsMarshaller.ObjectTokens.UnitOrder:
                break;

            case CommsMarshaller.ObjectTokens.UnitMovementOrder:
                break;

            case CommsMarshaller.ObjectTokens.UnitEngagementOrder:
                break;

            case CommsMarshaller.ObjectTokens.UnitClass:
                UnitClass unitClass = dataReceived as UnitClass;
                if (unitClass != null)
                {
                    ShowInfo("Received new UnitClass " + unitClass.Id + " " + unitClass.UnitClassShortName);
                }
                break;

            case CommsMarshaller.ObjectTokens.WeaponClass:
                break;

            case CommsMarshaller.ObjectTokens.SensorClass:
                break;

            case CommsMarshaller.ObjectTokens.GameScenario:
                var scenario = dataReceived as GameScenario;
                if (scenario != null)
                {
                    cmbPlayers.Items.Clear();
                    foreach (var al in scenario.Alliences)
                    {
                        foreach (var pl in al.ScenarioPlayers)
                        {
                            if (pl.IsCompetitivePlayer)
                            {
                                var item = new ComboBoxItem();
                                item.Content = pl.ToString();
                                item.Tag     = pl.Id;
                                cmbPlayers.Items.Add(item);
                            }
                        }
                    }
                    if (cmbPlayers.Items.Count > 0)
                    {
                        cmbPlayers.SelectedIndex = 0;
                    }
                }
                break;

            case CommsMarshaller.ObjectTokens.GameScenarioAlliance:
                break;

            case CommsMarshaller.ObjectTokens.GameScenarioPlayer:
                break;

            case CommsMarshaller.ObjectTokens.GameScenarioGroup:
                break;

            case CommsMarshaller.ObjectTokens.GameScenarioUnit:
                break;

            case CommsMarshaller.ObjectTokens.GameUiControl:
                GameUiControl control = dataReceived as GameUiControl;
                if (control != null)
                {
                    ShowInfo("### GameUiControl received: " + control.ToString());
                }
                break;

            default:
                break;
            }
        }