Exemplo n.º 1
0
    private void HandleGameStateInfo(IMarshallable dataReceived)
    {
        //GameManager.Instance.MessageManager.AddMessage(dataReceived.ToString(), GameManager.MessageTypes.Game, null);


        GameStateInfo gameInfo = dataReceived as GameStateInfo;

        if (gameInfo != null)
        {
            switch (gameInfo.InfoType)
            {
            case CommsMarshaller.GameStateInfoType.UnitIsDestroyed:
                PlayerUnit unit = GameManager.Instance.UnitManager.FindUnitById(gameInfo.Id);
                if (unit != null)
                {
                    unit.Kill(true);
                }
                //~ ShowMessage("GameStateInfo object, UnitIsDestroyed");
                break;

            case CommsMarshaller.GameStateInfoType.DetectedContactIsLost:
                //~ ShowMessage("GameStateInfo object, DetectedContactIsLost");
                Debug.Log(string.Format("Lost detection Id: {0} - Time:{1}", gameInfo.Id, Time.time));

                Enemy e = GameManager.Instance.UnitManager.FindEnemyById(gameInfo.Id);
                if (e != null)
                {
                    e.Kill();
                }
                else
                {
                    Debug.Log("Lost contact with unit not in enemy list. Error?");
                }

                break;

            case CommsMarshaller.GameStateInfoType.AircraftIsLanded:
            {
                PlayerUnit launchPlatform = GameManager.Instance.UnitManager.FindUnitById(gameInfo.SecondaryId);
                PlayerUnit aircraft       = GameManager.Instance.UnitManager.FindUnitById(gameInfo.Id);

                Debug.Log(string.Format("Aircraft has landed: {0} on {1}", aircraft.Info.UnitName, launchPlatform.Info.UnitName));
                if (aircraft != null)
                {
                    Debug.Log(string.Format("Killing off unit: {0}. ", aircraft.Info.UnitName));
                    aircraft.Kill(false);
                    Debug.Log(string.Format("{0} killed ", aircraft.Info.UnitName));
                }
                else
                {
                    Debug.Log("Aircraft is null");
                    break;
                }

                //gameInfo.
                if (launchPlatform != null)
                {
                    AnimationLauncher al = launchPlatform.GetComponent <AnimationLauncher>();
                    Debug.Log(string.Format("Animation launcher is on: {0}", al.gameObject.name));
                    if (al != null)
                    {
                        UnitClass uc = GameManager.Instance.GetUnitClass(aircraft.Info.UnitClassId);
                        Debug.Log(string.Format("Unitclass found: {0}. ", uc.UnitClassShortName));
                        al.TakeOffMode = uc.UnitType == GameConstants.UnitType.Helicopter ? AnimationLauncher.AnimMode.HelicopterLanding : AnimationLauncher.AnimMode.FixedWingLanding;
                        Debug.Log(string.Format("Changed takeoffmode to: {0}. Attempting launch...", al.TakeOffMode.ToString()));
                        al.LaunchAnimation();
                        Debug.Log(string.Format("Animation launched..."));
                    }
                    else
                    {
                        Debug.Log("AnimationLauncher is null");
                    }
                }
                else
                {
                    Debug.Log("Launchplatform is null");
                }



                //if (carrier != null)
                //{
                //    GameManager.Instance.UnitManager.SelectedUnit = carrier;
                //}
                //~ ShowMessage("GameStateInfo object, AircraftIsLanded");
                break;
            }

            case CommsMarshaller.GameStateInfoType.AircraftTakeoff:
            {
                PlayerUnit launchPlatform = GameManager.Instance.UnitManager.FindUnitById(gameInfo.SecondaryId);
                //gameInfo.
                if (launchPlatform != null)
                {
                    AnimationLauncher al = launchPlatform.GetComponent <AnimationLauncher>();
                    if (al != null)
                    {
                        UnitClass uc = GameManager.Instance.GetUnitClass(gameInfo.UnitClassId);

                        al.TakeOffMode = uc.UnitType == GameConstants.UnitType.Helicopter ? AnimationLauncher.AnimMode.HelicopterTakeOff : AnimationLauncher.AnimMode.FixedWingTakeOff;
                        al.LaunchAnimation();
                    }
                }
                break;
            }

            case CommsMarshaller.GameStateInfoType.MissileLaunch:
                PlayerUnit shooter = GameManager.Instance.UnitManager.FindUnitById(gameInfo.SecondaryId);


                if (shooter != null)
                {
                    shooter.FireMissile();
                }
                else
                {
                    Debug.Log(gameInfo.SecondaryId + " is not a unit here");
                }

                break;
            }
        }
    }