コード例 #1
0
    public override void Begin(params object[] parameters)
    {
        base.Begin(parameters);
        Diagnostics.Log("GameClientState_Turn_Begin.");
        this.EventService = Services.GetService <IEventService>();
        IGuiService service = Services.GetService <IGuiService>();

        Diagnostics.Assert(service != null);
        if (service.GetGuiPanel <LoadingScreen>().IsVisible)
        {
            service.GetGuiPanel <LoadingScreen>().Hide(false);
            service.GetGuiPanel <GameWorldScreen>().Show(new object[0]);
            service.GetGuiPanel <GameOverlayPanel>().Show(new object[0]);
            service.GetGuiPanel <InGameConsolePanel>().Load();
        }
        Amplitude.Unity.View.IViewService service2 = Services.GetService <Amplitude.Unity.View.IViewService>();
        if (service2 != null && (service2.CurrentView == null || service2.CurrentView.GetType() != typeof(WorldView)))
        {
            service2.PostViewChange(typeof(WorldView), new object[0]);
        }
        this.coroutine = Amplitude.Coroutine.StartCoroutine(this.RunAsync(), null);
        string text = AgeLocalizer.Instance.LocalizeString("%RichPresenceInGame" + base.GameClient.Session.SessionMode);

        text = text.Replace("$Name", base.GameClient.Session.GetLobbyData <string>("name", null));
        text = text.Replace("$Turn", (base.GameClient.Session.GetLobbyData <int>("_Turn", 0) + 1).ToString());
        Steamworks.SteamAPI.SteamFriends.SetRichPresence("status", text);
        IAudioEventService service3 = Services.GetService <IAudioEventService>();

        if (service3 != null)
        {
            service3.Play2DEvent("Gui/Interface/EndTurnValid");
        }
    }
コード例 #2
0
 private void UnloadScene()
 {
     if (this.SceneObject != null)
     {
         Amplitude.Unity.View.IViewService service = Services.GetService <Amplitude.Unity.View.IViewService>();
         if (service.PendingView != null && this != service.PendingView)
         {
             Diagnostics.Log("Destroying the outgame view scene to free some resources.\n(switching to '{0}')", new object[]
             {
                 service.PendingView.GetType().ToString()
             });
             UnityEngine.Object.Destroy(this.SceneObject);
             this.SceneObject = null;
             Resources.UnloadUnusedAssets();
         }
     }
 }
コード例 #3
0
    public override void End(bool abort)
    {
        base.End(abort);
        base.GameClient.TakeSnapshot();
        IMouseCursorService service = Services.GetService <IMouseCursorService>();

        if (service != null)
        {
            service.RemoveKey("Loading");
        }
        Amplitude.Unity.View.IViewService service2 = Services.GetService <Amplitude.Unity.View.IViewService>();
        if (service2 != null)
        {
            WorldView worldView = (WorldView)service2.FindByType(typeof(WorldView));
            if (worldView != null)
            {
                worldView.WorldViewTechniqueChange -= this.WorldView_WorldViewTechniqueChange;
            }
        }
    }
コード例 #4
0
    public bool SetVisibilityInFogOfWar(bool visible)
    {
        GameObject gameObject = null;

        Amplitude.Unity.View.IViewService service = Services.GetService <Amplitude.Unity.View.IViewService>();
        if (service == null)
        {
            Diagnostics.LogError("ViewService not found.");
            return(false);
        }
        if (service.CurrentView == null)
        {
            Diagnostics.LogError("viewService.CurrentView is null.");
            return(false);
        }
        WorldView worldView = service.FindByType(typeof(WorldView)) as WorldView;

        if (worldView == null)
        {
            Diagnostics.LogError("QuestMarker.SetVisibilityInFogOfWar: viewService.CurrentView is not a WorldView.");
            return(false);
        }
        if (worldView.CurrentWorldViewTechnique == null)
        {
            Diagnostics.LogError("CurrentWorldViewTechnique is null.");
            return(false);
        }
        IWorldEntityFactoryService service2 = worldView.CurrentWorldViewTechnique.Services.GetService <IWorldEntityFactoryService>();

        if (service2 == null)
        {
            Diagnostics.LogError("WorldEntityFactoryService not found.");
            return(false);
        }
        if (!service2.TryGetValue(this.GUID, out gameObject))
        {
            Diagnostics.LogError("QuestMarker.SetVisibilityInFogOfWar: cannot find marker with guid='{0}'.", new object[]
            {
                this.GUID
            });
            return(false);
        }
        if (gameObject == null)
        {
            Diagnostics.LogError("QuestMarker.SetVisibilityInFogOfWar: markerGameObject is null for marker with guid='{0}'.", new object[]
            {
                this.GUID
            });
            return(false);
        }
        this.isVisibleInFogOfWar = visible;
        foreach (MeshRenderer meshRenderer in gameObject.GetComponentsInChildren <MeshRenderer>())
        {
            for (int j = 0; j < meshRenderer.materials.Length; j++)
            {
                float value = (!visible) ? 1f : 0f;
                meshRenderer.materials[j].SetFloat("_HideInFow", value);
            }
        }
        return(true);
    }
コード例 #5
0
    public override void Begin(params object[] parameters)
    {
        base.Begin(parameters);
        IMouseCursorService service = Services.GetService <IMouseCursorService>();

        if (service != null)
        {
            service.AddKey("Loading");
        }
        Diagnostics.Log("GameClientState_GameLaunched.");
        int             num      = 0;
        ISessionService service2 = Services.GetService <ISessionService>();

        Diagnostics.Assert(service2 != null);
        Diagnostics.Assert(service2.Session != null);
        Diagnostics.Assert(service2.Session.IsOpened);
        string text = service2.Session.SteamIDUser.ToString();

        Diagnostics.Assert(service2.Session.SteamIDUser.AccountID == Amplitude.Unity.Framework.Application.UserUniqueID);
        PlayerController playerController = new PlayerController(base.GameClient)
        {
            PlayerID = "player#" + service2.Session.SteamIDUser.AccountID
        };

        for (;;)
        {
            string x         = string.Format("Empire{0}", num);
            string lobbyData = service2.Session.GetLobbyData <string>(x, null);
            if (string.IsNullOrEmpty(lobbyData))
            {
                break;
            }
            if (lobbyData.Contains(text))
            {
                goto IL_113;
            }
            num++;
        }
        Diagnostics.LogError("Player doesn't belong here (SteamUserID: {0}).", new object[]
        {
            text
        });
        goto IL_12C;
IL_113:
        playerController.Empire = base.GameClient.Game.Empires[num];
IL_12C:
        int num2 = 0;

        for (;;)
        {
            string x2         = string.Format("Empire{0}", num2);
            string lobbyData2 = service2.Session.GetLobbyData <string>(x2, null);
            if (string.IsNullOrEmpty(lobbyData2))
            {
                break;
            }
            base.GameClient.Game.Empires[num2].IsControlledByAI = true;
            MajorEmpire majorEmpire = base.GameClient.Game.Empires[num2] as MajorEmpire;
            if (majorEmpire != null)
            {
                if (!lobbyData2.StartsWith("AI"))
                {
                    majorEmpire.IsControlledByAI = false;
                    if (Steamworks.SteamAPI.IsSteamRunning)
                    {
                        string[] array = lobbyData2.Split(Amplitude.String.Separators, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < array.Length; i++)
                        {
                            Steamworks.SteamID steamID = new Steamworks.SteamID(Convert.ToUInt64(array[i], 16));
                            if (!service2.Session.GetLobbyMemberData <bool>(steamID, "Ready", false) && base.GameClient.Session.SessionMode != SessionMode.Single)
                            {
                                majorEmpire.BindPlayer(new Player(majorEmpire)
                                {
                                    Type          = PlayerType.AI,
                                    Location      = ((base.GameClient.Session.GameServer == null) ? PlayerLocation.Remote : PlayerLocation.Local),
                                    LocalizedName = MajorEmpire.GenerateBasicAIName(majorEmpire.Index)
                                });
                            }
                            else
                            {
                                string text2 = Steamworks.SteamAPI.SteamFriends.GetFriendPersonaName(steamID);
                                if (text2 == null)
                                {
                                    text2 = AgeLocalizer.Instance.LocalizeString("%DefaultPlayerName");
                                }
                                majorEmpire.BindPlayer(new Player(majorEmpire)
                                {
                                    Type          = PlayerType.Human,
                                    Location      = ((!(steamID == base.GameClient.SteamIDUser)) ? PlayerLocation.Remote : PlayerLocation.Local),
                                    LocalizedName = text2,
                                    SteamID       = steamID
                                });
                            }
                        }
                    }
                    else
                    {
                        Diagnostics.LogWarning("Steam is not running, cannot get player's name, setting a default one.");
                        majorEmpire.BindPlayer(new Player(majorEmpire)
                        {
                            Type          = PlayerType.Human,
                            Location      = PlayerLocation.Local,
                            LocalizedName = AgeLocalizer.Instance.LocalizeString("%DefaultPlayerName"),
                            SteamID       = Steamworks.SteamID.Zero
                        });
                    }
                }
                else
                {
                    majorEmpire.BindPlayer(new Player(majorEmpire)
                    {
                        Type          = PlayerType.AI,
                        Location      = ((base.GameClient.Session.GameServer == null) ? PlayerLocation.Remote : PlayerLocation.Local),
                        LocalizedName = MajorEmpire.GenerateBasicAIName(majorEmpire.Index)
                    });
                }
            }
            num2++;
        }
        IPlayerControllerRepositoryService service3 = base.GameClient.Game.GetService <IPlayerControllerRepositoryService>();

        if (service3 != null)
        {
            for (int j = 0; j < base.GameClient.Game.Empires.Length; j++)
            {
                PlayerController playerController2 = new PlayerController(base.GameClient)
                {
                    Empire   = base.GameClient.Game.Empires[j],
                    PlayerID = base.GameClient.Game.Empires[j].PlayerID
                };
                service3.Register(playerController2);
                base.GameClient.Game.Empires[j].PlayerController         = playerController2;
                base.GameClient.Game.Empires[j].PlayerControllers.Client = playerController2;
            }
        }
        if (service3 != null)
        {
            service3.Register(playerController);
            service3.SetActivePlayerController(playerController);
        }
        Ticket.ResetCounter(0UL);
        Amplitude.Unity.View.IViewService service4 = Services.GetService <Amplitude.Unity.View.IViewService>();
        if (service4 != null)
        {
            WorldView worldView = (WorldView)service4.FindByType(typeof(WorldView));
            if (worldView != null)
            {
                worldView.WorldViewTechniqueChange += this.WorldView_WorldViewTechniqueChange;
            }
            service4.PostViewChange(typeof(WorldView), new object[0]);
        }
        Amplitude.Unity.Gui.IGuiService service5 = Services.GetService <Amplitude.Unity.Gui.IGuiService>();
        Diagnostics.Assert(service5 != null);
        ConsolePanel guiPanel = service5.GetGuiPanel <ConsolePanel>();

        Diagnostics.Assert(guiPanel != null);
        guiPanel.Load();
        guiPanel.Hide(false);
    }
コード例 #6
0
ファイル: Session.cs プロジェクト: LeaderEnemyBoss/ELCP
 public override void Update()
 {
     base.Update();
     this.FiniteStateMachine.Update();
     if (this.ReturnToLobby)
     {
         if (this.GameServer != null)
         {
             this.GameServer.Dispose();
             this.GameServer = null;
         }
         if (this.GameClient != null)
         {
             this.GameClient.Dispose();
             this.GameClient = null;
         }
         Amplitude.Unity.View.IViewService service = Services.GetService <Amplitude.Unity.View.IViewService>();
         Diagnostics.Assert(service != null);
         service.PostViewChange(typeof(OutGameView), new object[]
         {
             typeof(MenuNewGameScreen)
         });
         this.PostStateChange(typeof(SessionState_Opened), new object[0]);
         string text = AgeLocalizer.Instance.LocalizeString("%RichPresenceInLobby" + base.SessionMode);
         text = text.Replace("$Name", base.GetLobbyData <string>("name", null));
         Steamworks.SteamAPI.SteamFriends.SetRichPresence("status", text);
         this.SetLobbyData("_Launching", false, true);
         this.SetLobbyData("_GameInProgress", false, true);
         this.SetLobbyData("_GameIsMigrating", false, true);
         this.SetLobbyData("_GameSyncState", SynchronizationState.Unset.ToString(), true);
         base.SteamIDServer    = null;
         this.LocalPlayerReady = false;
         this.ReturnToLobby    = false;
         return;
     }
     if (this.GameServer != null)
     {
         (this.GameServer as GameServer).Update();
     }
     if (this.GameClient != null)
     {
         (this.GameClient as GameClient).Update();
     }
     if (this.GameServer != null)
     {
         DateTime   utcNow     = DateTime.UtcNow;
         GameServer gameServer = this.GameServer as GameServer;
         int        num        = 0;
         while (num < 10000 && gameServer.HasPendingOrder)
         {
             gameServer.UpdateMessageBoxAndProcessOrders();
             if (this.GameClient != null)
             {
                 (this.GameClient as GameClient).UpdateMessageBoxAndProcessOrders();
             }
             if (num == 0 || (num + 1) % global::Session.LateUpdatePreemption.Frequency == 0)
             {
                 TimeSpan timeSpan = DateTime.UtcNow - utcNow;
                 if (timeSpan.TotalMilliseconds >= global::Session.LateUpdatePreemption.TimeSpanInMilliseconds)
                 {
                     if (global::Session.LateUpdatePreemption.EnableDiagnostics)
                     {
                         Diagnostics.LogWarning("UpdateMessageBoxAndProcessOrders has been preemptively stopped after having processed {0} order(s) in {1} milliseconds.", new object[]
                         {
                             num + 1,
                             timeSpan.TotalMilliseconds
                         });
                     }
                     break;
                 }
             }
             num++;
         }
     }
 }
コード例 #7
0
 private void UnitSpawnWorldCursor_Click(object sender, CursorTargetMouseEventArgs e)
 {
     if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.LeftControl))
     {
         this.SpawnEnnemyArmy();
         return;
     }
     if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftShift))
     {
         IGameService service = Services.GetService <IGameService>();
         if (service.Game == null || GodWorldCursor.EditorSelectedEmpire == null || GodWorldCursor.EditorSelectedUnitDesigns == null || GodWorldCursor.EditorSelectedUnitDesigns.Length == 0)
         {
             return;
         }
         if (WorldCursor.HighlightedWorldPosition.IsValid)
         {
             OrderSpawnArmy orderSpawnArmy = new OrderSpawnArmy(GodWorldCursor.EditorSelectedEmpire.Index, WorldCursor.HighlightedWorldPosition, GodWorldCursor.EditorSelectedUnitDesigns);
             service.Game.Services.GetService <IPlayerControllerRepositoryService>().ActivePlayerController.PostOrder(orderSpawnArmy);
             Diagnostics.Log("Posting order: {0}.", new object[]
             {
                 orderSpawnArmy.ToString()
             });
             return;
         }
     }
     else
     {
         if (Input.GetKey(KeyCode.RightControl))
         {
             this.SpawnWildlingArmy();
             return;
         }
         if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.LeftAlt))
         {
             this.SpawnMinorArmy();
             return;
         }
         if (Input.GetKey(KeyCode.LeftShift))
         {
             this.SpawnArmy();
             return;
         }
         if (Input.GetKey(KeyCode.LeftAlt))
         {
             this.SpawnCity();
             return;
         }
         if (Input.GetKey(KeyCode.RightShift))
         {
             this.SpawnCamp();
             return;
         }
         if (Input.GetKey(KeyCode.C))
         {
             Amplitude.Unity.View.IViewService service2 = Services.GetService <Amplitude.Unity.View.IViewService>();
             if (service2.CurrentView != null && service2.CurrentView.CameraController is IWorldViewCameraController)
             {
                 (service2.CurrentView.CameraController as IWorldViewCameraController).FocusCameraAt(WorldCursor.HighlightedWorldPosition, false, true);
             }
         }
     }
 }