예제 #1
0
        public void Update()
        {
            var player = _country.PlayerCountry;

            if (_army.GetAvailableCount(player) > 0)
            {
                var locPairs = _conquest.GetAcceptableLocations(player);
                foreach (var pair in locPairs)
                {
                    var homeLoc   = pair.Item1;
                    var targetLoc = pair.Item2;
                    var name      = targetLoc.Name;
                    if (_discovery.IsDiscovered(player, targetLoc))
                    {
                        if (targetLoc.Owner != null)
                        {
                            var raceName = LocUtils.TranslateRaceName(targetLoc.Owner);
                            name += $" ({targetLoc.Owner.Name}, {raceName})";
                        }
                    }
                    else
                    {
                        name += " (?)";
                    }
                    name += ".";
                    _context.AddCase(name, () => TryStartConquest(homeLoc, targetLoc, player));
                }
            }

            _context.AddCase(
                Content.go_back,
                () => _context.GoToRelatedContext <ArmyController>());
        }
예제 #2
0
 void ShowLegend()
 {
     _out.Write();
     foreach (var pair in _colorMap)
     {
         if (_country.Countries.Contains(pair.Key))
         {
             _out.WriteCustom($"{pair.Key.Name} ({LocUtils.TranslateRaceName(pair.Key)}) ", pair.Value);
         }
     }
 }
예제 #3
0
 public void OnConquest(ConquestResult result)
 {
     if ((result.Defender != null) && (result.Defender == _country.PlayerCountry))
     {
         _out.WriteFormat(
             Content.enemy_conquest_result,
             result.Location.Name,
             result.Invader.Name,
             LocUtils.TranslateRaceName(result.Invader),
             result.InvaderSquad.Count,
             result.DefenderSquad.Count,
             result.InvaderSquad.Loses,
             result.DefenderSquad.Loses
             );
         _out.WriteFormat(result.Success ? Content.enemy_conquest_success : Content.enemy_conquest_fail, result.Location.Name);
     }
 }
예제 #4
0
 void DescribeLocation(Country country, Location loc)
 {
     _out.WriteFormat(Content.here_is, loc.Name);
     if (!_discovery.IsDiscovered(country, loc))
     {
         _out.Write(Content.here_unknown);
     }
     else if (loc.Owner != null)
     {
         var raceName = LocUtils.TranslateRaceName(loc.Owner);
         _out.WriteFormat(Content.here_live, loc.Owner.Name, raceName);
     }
     else
     {
         _out.Write(Content.here_empty);
     }
 }
예제 #5
0
        void UpdateRaceSelection()
        {
            _output.Write(Content.race_select);
            var races = _races.AllRaces;

            for (var i = 0; i < races.Count; i++)
            {
                _output.Write($"{i + 1}) {LocUtils.TranslateRaceName(races[i])}");
            }
            do
            {
                var selection = _input.ReadInt();
                if ((selection > 0) && (selection <= races.Count))
                {
                    _races.SelectPlayerRace(races[selection - 1]);
                    return;
                }
            } while (true);
        }
예제 #6
0
파일: GameLogics.cs 프로젝트: KonH/TheKing
 public void OnCountryRemoved(Country country, string reason)
 {
     if (_country.PlayerCountry == country)
     {
         Fail(reason);
     }
     if (!HasOtherCountries())
     {
         Win(Content.win_conquest);
     }
     else
     {
         var raceName = LocUtils.TranslateRaceName(country);
         _out.WriteFormat(Content.enemy_failed, country.Name, raceName);
         if (_country.Countries.Count == 1)
         {
             var lastCountry = _country.Countries[0];
             var lastRace    = LocUtils.TranslateRaceName(lastCountry);
             Win(string.Format(Content.one_alive, lastCountry.Name, lastRace));
         }
     }
 }
예제 #7
0
    IEnumerator ReadChunkRoutine(DialogueChunk dialogueChunk, PlayerNPCInput npc, GameSound voiceEventOverride)
    {
        bool hasNPC = (npc != null);

        if (_showWidgetRoutine != null)
        {
            StopCoroutine(_showWidgetRoutine);
        }

        _showWidgetRoutine = StartCoroutine(ShowWidgetRoutine(true));
        yield return(_showWidgetRoutine);

        if (dialogueChunk.chunkType == DialogueChunk.ChunkType.Choice)
        {
            _optionLayout.SetActive(true);

            for (int i = 0; i < dialogueChunk.responses.Length; i++)
            {
                _optionButtons[i].gameObject.SetActive(true);
                GetOptionTexts()[i].color = GetOptionTexts()[i].color.SetA(0f);
                GetOptionTexts()[i].text  = dialogueChunk.responses[i].response;
            }
        }

        string dialogueText = LocUtils.Translate(dialogueChunk.dialogueTerm);

        foreach (KeyValuePair <string, string> kvp in _locDynamicText)
        {
            if (dialogueText.Contains(kvp.Key))
            {
                dialogueText = dialogueText.Replace(kvp.Key, LocUtils.Translate(kvp.Value));
            }
        }

        if (_textSpeed > Mathf.Epsilon)
        {
            _lineText.text = dialogueText;

            if (_resetMouthRoutine != null)
            {
                StopCoroutine(_resetMouthRoutine);
                _resetMouthRoutine = null;
            }

            GameSound dialogueSound = voiceEventOverride;
            if (dialogueSound == GameSound.NONE)
            {
                string soundName = "SFX_UI_Dialogue_" + dialogueChunk.character.ToString();
                if (Enum.IsDefined(typeof(GameSound), soundName))
                {
                    dialogueSound = (GameSound)Enum.Parse(typeof(GameSound), soundName);
                }
            }

            GameSounds.PostEvent2D(dialogueSound);

            float lineStartTime = Time.time;
            for (int i = 0; i < dialogueText.Length; i++)
            {
                // Skip rich text
                if (dialogueText[i] == '<')
                {
                    while (dialogueText[i] != '>')
                    {
                        i++;
                    }

                    i++;
                }

                _lineText.ScaleCharacter(i);

                float timer = 0;
                while (timer < _textSpeed)
                {
                    if (hasNPC && npc.GetPlayer().HasMouthBlend())
                    {
                        float timeSinceLineState = Time.time - lineStartTime;
                        float mouthBlendWeight   = (Mathf.Sin(timeSinceLineState * _mouthFlapSpeed * Mathf.PI) * 0.5f + 0.5f) * 100f;

                        if (npc.GetPlayer().GetSkinnedMeshRenderer())
                        {
                            npc.GetPlayer().GetSkinnedMeshRenderer().SetBlendShapeWeight(npc.GetPlayer().GetMouthBlendIndex(), mouthBlendWeight);
                        }
                    }

                    if (!GameManager.GSM.IsStateActive(GameStateType.PauseMenu) && InputManager.ActiveDevice.AnyButtonWasPressed)
                    {
                        _lineText.ForceAllScaled();
                        goto lineFinished;
                    }

                    timer += Time.deltaTime;
                    yield return(null);
                }
            }

lineFinished:

            if (hasNPC && npc.GetPlayer().HasMouthBlend())
            {
                _resetMouthRoutine = StartCoroutine(ResetMouthRoutine(npc));
            }

            if (dialogueSound != GameSound.NONE)
            {
                GameSounds.PostEvent2D(dialogueSound, EventAction.StopSound);
            }
        }
        else
        {
            _lineText.text = dialogueText;
        }

        if (dialogueChunk.chunkType == DialogueChunk.ChunkType.Default)
        {
            _continuePrompt.SetActive(true);

            yield return(null);

            while (!InputManager.ActiveDevice.AnyButtonWasPressed)
            {
                yield return(null);
            }

            if (_continuePrompt != null)
            {
                _continuePrompt.SetActive(false);
            }
        }
        else
        {
            yield return(StartCoroutine(DialogueOptionsRoutine(dialogueChunk)));
        }

        _lineText.text = string.Empty;

        if (_showWidgetRoutine != null)
        {
            StopCoroutine(_showWidgetRoutine);
        }

        _showWidgetRoutine = StartCoroutine(ShowWidgetRoutine(false));
        yield return(_showWidgetRoutine);

        _readChunkRoutine = null;
    }
예제 #8
0
    IEnumerator ReadDialogueRoutine(DialogueData dialogueData)
    {
        List <Player> players = PlayerManager.GetSpawnedPlayers();

        for (int i = 0; i < players.Count; i++)
        {
            players[i].GetInput().bottomControlLens.AddRequest(new LensHandle <bool>(this, false));
        }

        for (_chunkIndex = 0; _chunkIndex < dialogueData.dialogue.Length; _chunkIndex++)
        {
            if (_chunkIndex < 0)
            {
                _chunkIndex = 0;
            }

            Vector3   faceDirection  = Vector3.zero;
            Transform prevLookTarget = null;

            bool                  hasNPC      = false;
            PlayerNPCInput        npc         = null;
            List <PlayerNPCInput> spawnedNPCs = PlayerManager.GetNPCs();
            for (int j = 0; j < spawnedNPCs.Count; j++)
            {
                if (spawnedNPCs[j].gameObject.activeInHierarchy && spawnedNPCs[j].GetPlayer().GetInfo().character == dialogueData.dialogue[_chunkIndex].character)
                {
                    hasNPC = true;
                    npc    = spawnedNPCs[j];

                    faceDirection = npc.transform.forward.SetY(0f);
                    if (dialogueData.facingMode != FacingMode.Stay)
                    {
                        faceDirection = (PlayerManager.GetLeadPlayer().transform.position - npc.transform.position).SetY(0f);
                        if (dialogueData.facingMode != FacingMode.FaceForward)
                        {
                            npc.TweenLookDirection(faceDirection);
                        }
                    }

                    prevLookTarget = npc.GetPlayer().GetPhysics().GetBody().lookTarget;
                    npc.GetPlayer().GetPhysics().GetBody().lookTarget = dialogueData.lookTarget ?? CameraManager.instance.transform;

                    break;
                }
            }

            string pattern  = @"\{(.*?)\}";
            string dialogue = LocUtils.Translate(dialogueData.dialogue[_chunkIndex].dialogueTerm);

            #region Dialogue Commands
            // LOOK FOR COMMANDS IN DIALOGUE
            // OH LORD WE BEGIN OUR DESCENT INTO MADNESS
            MatchCollection matchCollection = Regex.Matches(dialogue, pattern);
            foreach (Match m in matchCollection)
            {
                dialogue = dialogue.Replace(m.Value, "");

                string value = m.Value.Remove(0, 1);
                value = value.Remove(value.Length - 1, 1);

                string[] sections = value.Split(',');
                if (sections[0] == "SetHat")
                {
                    if (hasNPC && sections.Length == 2)
                    {
                        if (Enum.IsDefined(typeof(HatType), sections[1]))
                        {
                            HatType hatType = (HatType)Enum.Parse(typeof(HatType), sections[1]);
                            npc.GetPlayer().SetHat(hatType);

                            if (hatType != HatType.None)
                            {
                                Tweakables.VFX.bubblePop.Spawn(ObjectPool.instance.transform, npc.GetPlayer().GetActiveHats()[0].transform.position);
                            }
                        }
                    }
                    else if (sections.Length == 3)
                    {
                        if (Enum.IsDefined(typeof(CharacterType), sections[1]))
                        {
                            CharacterType character = (CharacterType)Enum.Parse(typeof(CharacterType), sections[1]);
                            for (int j = 0; j < spawnedNPCs.Count; j++)
                            {
                                if (spawnedNPCs[j].GetPlayer().GetInfo().character == character)
                                {
                                    if (Enum.IsDefined(typeof(HatType), sections[2]))
                                    {
                                        HatType hatType = (HatType)Enum.Parse(typeof(HatType), sections[2]);
                                        spawnedNPCs[j].GetPlayer().SetHat(hatType);

                                        if (hatType != HatType.None)
                                        {
                                            Tweakables.VFX.bubblePop.Spawn(ObjectPool.instance.transform, spawnedNPCs[j].GetPlayer().GetActiveHats()[0].transform.position);
                                        }
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
                else if (sections[0] == "SetSkin")
                {
                    if (hasNPC && sections.Length == 2)
                    {
                        if (Enum.IsDefined(typeof(SkinType), sections[1]))
                        {
                            SkinType skinType = (SkinType)Enum.Parse(typeof(SkinType), sections[1]);
                            npc.GetPlayer().SetSkin(skinType);
                        }
                    }
                    else if (sections.Length == 3)
                    {
                        if (Enum.IsDefined(typeof(CharacterType), sections[1]))
                        {
                            CharacterType character = (CharacterType)Enum.Parse(typeof(CharacterType), sections[1]);
                            for (int j = 0; j < spawnedNPCs.Count; j++)
                            {
                                if (spawnedNPCs[j].GetPlayer().GetInfo().character == character)
                                {
                                    if (Enum.IsDefined(typeof(SkinType), sections[2]))
                                    {
                                        SkinType skinType = (SkinType)Enum.Parse(typeof(SkinType), sections[2]);
                                        spawnedNPCs[j].GetPlayer().SetSkin(skinType);
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
            }

            dialogueData.dialogue[_chunkIndex].dialogue = dialogue;
            #endregion

            SetCharacter(dialogueData.dialogue[_chunkIndex].character);

            // Stem Target
            Transform stemTarget = dialogueData.target;
            if (!stemTarget && hasNPC)
            {
                stemTarget = npc.GetPlayer().GetPhysics().GetSausage().transform;
            }

            SetTarget(stemTarget);

            // Camera Target
            Vector3   camOffset = dialogueData.offset;
            Transform camTarget = dialogueData.target;
            if (camTarget)
            {
                faceDirection = camTarget.forward;
            }
            else if (hasNPC)
            {
                camTarget = npc.transform.GetBoneTagInChildren(BoneLocation.SpineMiddle).transform;
                camOffset = Vector3.up * 0.5f;
            }

            Quaternion targetLookRot = Quaternion.identity;
            if (camTarget)
            {
                if (dialogueData.facingMode == FacingMode.FaceForward && PlayerManager.GetLeadPlayer())
                {
                    faceDirection = (PlayerManager.GetLeadPlayer().transform.position - camTarget.transform.position).SetY(0f);
                }

                if (faceDirection != Vector3.zero)
                {
                    targetLookRot = Quaternion.LookRotation(faceDirection, Vector3.up);
                }

                CameraManager.RegisterFollowTarget(camTarget, camOffset, dialogueData.camWeight);
            }

            CameraManager.SetOverrideSettings(dialogueData.camSettings, targetLookRot.eulerAngles.y);

            // Jump camera to end position, calculate where bubble will be and then jump it back
            Vector3    prevCamPos = CameraManager.instance.transform.position;
            Quaternion prevCamRot = CameraManager.instance.transform.rotation;

            _snapBubbleToAlonePoint = true;

            CameraManager.SimpleSnapToTarget();

            UpdateBubblePos();

            if (_chunkIndex == 0 && dialogueData.snap)
            {
                CameraManager.SnapToTarget();
            }

            if (!dialogueData.snap)
            {
                CameraManager.instance.transform.position = prevCamPos;
                CameraManager.instance.transform.rotation = prevCamRot;
            }

            // Do emote stuff
            if (hasNPC)
            {
                if (dialogueData.dialogue[_chunkIndex].emote != EmoteType.None)
                {
                    EmoteTag emoteTag = npc.GetPayload().GetEmote(dialogueData.dialogue[_chunkIndex].emote);
                    emoteTag.Play(dialogueData.dialogue[_chunkIndex].loopEmote);

                    npc.headSwingScaleLens.AddRequest(
                        new LensHandle <float>(this, npc.GetPayload().GetEmote(dialogueData.dialogue[_chunkIndex].emote).GetShakeForce()));

                    if (emoteTag.GetUseEyeBlend())
                    {
                        npc.GetPlayer().eyeBlendLens.AddRequest(new LensHandle <float>(this, emoteTag.GetEyeBlend()));
                    }
                }
                else
                {
                    npc.headSwingScaleLens.AddRequest(new LensHandle <float>(this, 0.3f));
                }
            }

            int prevIndex = _chunkIndex;             // Hack to go back to page backwards for debug

            _readChunkRoutine = StartCoroutine(ReadChunkRoutine(dialogueData.dialogue[_chunkIndex], npc, dialogueData.voiceEvent));
            while (_readChunkRoutine != null)
            {
                yield return(null);
            }

            if (!gameObject.activeSelf || npc == null)
            {
                yield break;
            }

            _optionLayout.SetActive(false);

            foreach (var optionButton in _optionButtons)
            {
                optionButton.gameObject.SetActive(false);
            }

            if (dialogueData.dialogue[prevIndex].chunkType == DialogueChunk.ChunkType.Choice)
            {
                dialogueData.dialogue[prevIndex].SaveResponse();
            }

            if (hasNPC)
            {
                if (dialogueData.dialogue[prevIndex].emote != EmoteType.None && dialogueData.dialogue[prevIndex].loopEmote)
                {
                    npc.GetPayload().GetEmote(dialogueData.dialogue[prevIndex].emote).Stop();
                }

                npc.GetPlayer().eyeBlendLens.RemoveRequestsWithContext(this);
                npc.GetPlayer().GetPhysics().GetBody().lookTarget = prevLookTarget;

                npc.headSwingScaleLens.RemoveRequestsWithContext(this);
            }

            CameraManager.SetOverrideSettings(null, null);

            if (camTarget)
            {
                CameraManager.DeregisterFollowTarget(camTarget);
            }

            if ((prevIndex == dialogueData.dialogue.Length - 1) && dialogueData.snapBack)
            {
                CameraManager.SnapToTarget();
            }
        }

        for (int i = 0; i < players.Count; i++)
        {
            if (players[i])
            {
                players[i].GetInput().bottomControlLens.RemoveRequestsWithContext(this);
            }
        }
    }