コード例 #1
0
        private static DialogType GetDialogType(ScriptMetadata scriptMetadata, NpcTalk npcTalk, bool hasNextScript)
        {
            DialogType dialogType = DialogType.CloseNext1;
            Option     option     = scriptMetadata.Options.First(x => x.Id == npcTalk.ScriptId);

            if (option.Goto.Count == 0)
            {
                dialogType = DialogType.CloseNext1;
            }
            if (option.AmountContent > 1)
            {
                dialogType = DialogType.CloseNext;
            }

            if (!hasNextScript)
            {
                ScriptIdType type = (ScriptIdType)(npcTalk.ScriptId / 100);
                if (npcTalk.IsQuest)
                {
                    dialogType = type switch
                    {
                        ScriptIdType.Start => DialogType.AcceptDecline,
                        ScriptIdType.End => DialogType.QuestReward,
                        _ => DialogType.Close1,
                    };
                }
                else
                {
                    dialogType = DialogType.Close1;
                }
            }
            return(dialogType);
        }
コード例 #2
0
        private static int GetNextScript(ScriptMetadata scriptMetadata, NpcTalk npcTalk, int index)
        {
            if (npcTalk.IsQuest && npcTalk.ScriptId == 0)
            {
                QuestStatus questStatus = npcTalk.Quests[index];
                if (questStatus.Started)
                {
                    // Talking to npc that start the quest and condition is not completed
                    if (questStatus.StartNpcId == npcTalk.Npc.Id && questStatus.Condition.Count != questStatus.Condition.Count(x => x.Goal == x.Current))
                    {
                        return(200);
                    }
                    return(300); // Talking to npc that end the quest
                }
                return(100);     // Talking to npc that start the quest and isn't started
            }

            Option option = scriptMetadata.Options.First(x => x.Id == npcTalk.ScriptId);

            if (npcTalk.ScriptId == 0)
            {
                return(scriptMetadata.Options.First(x => x.Id > npcTalk.ScriptId).Id);
            }

            if (option.Goto.Count == 0)
            {
                return(npcTalk.ScriptId);
            }
            return(option.Goto[index]);
        }
コード例 #3
0
        private static int GetNextScript(ScriptMetadata scriptMetadata, NpcTalk npcTalk, int index, ScriptLoader scriptLoader)
        {
            if (npcTalk.IsQuest && npcTalk.ScriptId == 0)
            {
                QuestStatus questStatus = npcTalk.Quests[index];
                if (questStatus.Started)
                {
                    // Talking to npc that start the quest and condition is not completed
                    if (questStatus.StartNpcId == npcTalk.Npc.Id && questStatus.Condition.Count != questStatus.Condition.Count(x => x.Completed))
                    {
                        return(200);
                    }
                    return(300); // Talking to npc that end the quest
                }
                return(100);     // Talking to npc that start the quest and isn't started
            }

            if (npcTalk.ScriptId == 0)
            {
                if (scriptLoader.Script != null)
                {
                    // Usually hardcoded functions to get the first script id which
                    // otherwise wouldn't be possible only with the xml data
                    DynValue result = scriptLoader.Call("getFirstScriptId");
                    if (result != null && result.Number != -1)
                    {
                        return((int)result.Number);
                    }
                }

                return(scriptMetadata.Options.First(x => x.Id > npcTalk.ScriptId).Id);
            }

            Option currentOption = scriptMetadata.Options.First(x => x.Id == npcTalk.ScriptId);

            if (currentOption.Contents[npcTalk.ContentIndex].Goto.Count == 0 ||
                currentOption?.Contents.Count > 1 && currentOption?.Contents.Count > npcTalk.ContentIndex + 1)
            {
                return(npcTalk.ScriptId);
            }

            // If content has goto fail, use the lua scripts to check the requirements
            if (currentOption.Contents[npcTalk.ContentIndex].GotoFail.Count > 0)
            {
                if (scriptLoader.Script != null)
                {
                    DynValue result = scriptLoader.Call("handleGotoFail", currentOption.Contents[npcTalk.ContentIndex].Goto[index]);
                    if (result == null)
                    {
                        return(0);
                    }

                    return((int)result.Number);
                }
            }

            // TODO: check for the requirements for goto

            return(currentOption.Contents[npcTalk.ContentIndex].Goto[index]);
        }
コード例 #4
0
    void Start()
    {
        rigid2D.velocity = new Vector2(0, 0f);
        healthCanvas     = playerHealth.GetComponent <Transform>();

        if (ChapterName == "1")
        {
            activeClimb            = GameObject.Find("vine1").GetComponent <ActiveClimb>();   //防錯誤 爬藤蔓
            activePickUp           = GameObject.Find("stone1").GetComponent <ActivePickUp>(); //防錯誤 拾取物品
            ActivePickUp.PickUpInt = 0;
        }
        else if (ChapterName == "2")
        {
            activeClimb            = GameObject.Find("ladder").GetComponent <ActiveClimb>(); //防錯誤 爬藤蔓
            activePickUp           = GameObject.Find("Card").GetComponent <ActivePickUp>();  //防錯誤 拾取物品
            ActivePickUp.PickUpInt = 0;
        }
        else if (ChapterName == "3")
        {
            activeClimb            = GameObject.Find("ladder").GetComponent <ActiveClimb>();   //防錯誤 爬藤蔓
            activePickUp           = GameObject.Find("pillar1").GetComponent <ActivePickUp>(); //防錯誤 拾取物品
            npcTalk                = GameObject.Find("Door").GetComponent <NpcTalk>();
            ActivePickUp.PickUpInt = 0;
        }
        else if (ChapterName == "4")
        {
            //activeClimb = GameObject.Find("ladder").GetComponent<ActiveClimb>();  //防錯誤 爬藤蔓
            activePickUp = GameObject.Find("handle").GetComponent <ActivePickUp>(); //防錯誤 拾取物品
            //npcTalk = GameObject.Find("Door").GetComponent<NpcTalk>();
            ActivePickUp.PickUpInt = 0;
        }
    }
コード例 #5
0
 private static int GetNextScript(ScriptMetadata scriptMetadata, NpcTalk npcTalk, int index)
 {
     if (npcTalk.IsQuest && npcTalk.ScriptId == 0)
     {
         if (npcTalk.Quests[index].Started)
         {
             // Talking to npc that start the quest and is started
             if (npcTalk.Quests[index].StartNpcId == npcTalk.Npc.Id)
             {
                 return(200);
             }
             else // Talking to npc that end the quest
             {
                 return(300);
             }
         }
         else // Talking to npc that start the quest and isn't started
         {
             return(100);
         }
     }
     else
     {
         Option option = scriptMetadata.Options.First(x => x.Id == npcTalk.ScriptId);
         if (npcTalk.ScriptId == 0)
         {
             return(scriptMetadata.Options.First(x => x.Id > npcTalk.ScriptId).Id);
         }
         else
         {
             if (option.Goto.Count == 0)
             {
                 return(npcTalk.ScriptId);
             }
             else
             {
                 return(option.Goto[index]);
             }
         }
     }
 }
コード例 #6
0
        private static DialogType GetDialogType(ScriptMetadata scriptMetadata, NpcTalk npcTalk, bool hasNextScript)
        {
            DialogType dialogType = DialogType.None;
            Option     option     = scriptMetadata.Options.First(x => x.Id == npcTalk.ScriptId);

            // If npc has buttonSet by xmls, use it
            if (option.Contents[npcTalk.ContentIndex].ButtonSet != DialogType.None)
            {
                return(option.Contents[npcTalk.ContentIndex].ButtonSet);
            }

            if (option.Contents[npcTalk.ContentIndex].Goto.Count == 0)
            {
                dialogType = DialogType.CloseNext;
            }
            else
            {
                dialogType = DialogType.CloseNextWithDistractor;
            }

            if (!hasNextScript)
            {
                // Get the correct dialog type for the last quest content
                ScriptIdType type = (ScriptIdType)(npcTalk.ScriptId / 100);
                if (npcTalk.IsQuest)
                {
                    dialogType = type switch
                    {
                        ScriptIdType.Start => DialogType.AcceptDecline,
                        ScriptIdType.End => DialogType.QuestReward,
                        _ => DialogType.Close1,
                    };
                }
                else
                {
                    dialogType = DialogType.Close1;
                }
            }
            return(dialogType);
        }
コード例 #7
0
    private static DialogType GetDialogType(ScriptMetadata scriptMetadata, NpcTalk npcTalk, bool hasNextScript)
    {
        Option  option  = scriptMetadata.Options.First(x => x.Id == npcTalk.ScriptId);
        Content content = option.Contents[npcTalk.ContentIndex];

        // If npc has buttonSet by xmls, use it
        if (content.ButtonSet != DialogType.None)
        {
            return(content.ButtonSet);
        }

        if (!hasNextScript)
        {
            // Get the correct dialog type for the last quest content
            ScriptIdType type = (ScriptIdType)(npcTalk.ScriptId / 100);
            if (npcTalk.IsQuest)
            {
                return(type switch
                {
                    ScriptIdType.Start => DialogType.AcceptDecline,
                    ScriptIdType.End => DialogType.QuestReward,
                    _ => DialogType.Close1
                });
コード例 #8
0
        private static void HandleContinue(GameSession session, PacketReader packet)
        {
            NpcTalk npcTalk = session.Player.NpcTalk;

            if (npcTalk.Npc.IsBeauty())
            {
                HandleBeauty(session);
                return;
            }

            int index = packet.ReadInt(); // selection index

            // index is quest
            if (index <= npcTalk.Quests.Count - 1 && npcTalk.ScriptId == 0)
            {
                npcTalk.QuestId = npcTalk.Quests[index].Basic.Id;
                npcTalk.IsQuest = true;
            }

            ScriptMetadata scriptMetadata = npcTalk.IsQuest ? ScriptMetadataStorage.GetQuestScriptMetadata(npcTalk.QuestId) : ScriptMetadataStorage.GetNpcScriptMetadata(npcTalk.Npc.Id);
            ResponseType   responseType   = npcTalk.IsQuest ? ResponseType.Quest : ResponseType.Dialog;

            if (npcTalk.ScriptId != 0)
            {
                Option option = scriptMetadata.Options.First(x => x.Id == npcTalk.ScriptId);
                if (option.AmountContent <= npcTalk.ContentIndex && option.Goto.Count == 0)
                {
                    session.Send(NpcTalkPacket.Close());
                    return;
                }
            }

            // Find next script id
            int    nextScript = GetNextScript(scriptMetadata, npcTalk, index);
            Option option2    = scriptMetadata.Options.FirstOrDefault(x => x.Id == npcTalk.ScriptId);

            if (option2?.AmountContent > 1 && option2?.AmountContent > npcTalk.ContentIndex)
            {
                nextScript = npcTalk.ScriptId;
            }

            if (npcTalk.ScriptId != nextScript)
            {
                npcTalk.ContentIndex = 1;
            }
            else
            {
                npcTalk.ContentIndex++;
            }

            Option option1       = scriptMetadata.Options.First(x => x.Id == nextScript);
            bool   hasNextScript = option1.Goto.Count != 0;

            if (option1.AmountContent > npcTalk.ContentIndex)
            {
                hasNextScript = true;
            }
            npcTalk.ScriptId = nextScript;

            DialogType dialogType = GetDialogType(scriptMetadata, npcTalk, hasNextScript);

            session.Send(NpcTalkPacket.ContinueChat(nextScript, responseType, dialogType, npcTalk.ContentIndex - 1, npcTalk.QuestId));
        }
コード例 #9
0
        private static void HandleContinue(GameSession session, int index)
        {
            NpcTalk npcTalk = session.Player.NpcTalk;

            if (npcTalk.Npc.IsBeauty())
            {
                HandleBeauty(session);
                return;
            }

            ScriptLoader scriptLoader = new ScriptLoader($"Npcs/{npcTalk.Npc.Id}", session);

            // index is quest
            if (index <= npcTalk.Quests.Count - 1 && npcTalk.ScriptId == 0)
            {
                npcTalk.QuestId = npcTalk.Quests[index].Basic.Id;
                npcTalk.IsQuest = true;
            }

            ScriptMetadata scriptMetadata = npcTalk.IsQuest ? ScriptMetadataStorage.GetQuestScriptMetadata(npcTalk.QuestId) : ScriptMetadataStorage.GetNpcScriptMetadata(npcTalk.Npc.Id);
            ResponseType   responseType   = npcTalk.IsQuest ? ResponseType.Quest : ResponseType.Dialog;

            if (npcTalk.ScriptId != 0)
            {
                Option option = scriptMetadata.Options.First(x => x.Id == npcTalk.ScriptId);

                // Find if player has quest condition for type "talk_in" and option id
                QuestHelper.UpdateQuest(session, npcTalk.Npc.Id.ToString(), "talk_in", option.Id.ToString());

                // If npc has no more options, close dialog
                if (option.Contents.Count <= npcTalk.ContentIndex + 1 && option.Contents[npcTalk.ContentIndex].Goto.Count == 0)
                {
                    session.Send(NpcTalkPacket.Close());
                    return;
                }
            }

            int nextScriptId = GetNextScript(scriptMetadata, npcTalk, index, scriptLoader);

            // If last script is different from next, reset content index, else increment content index
            if (npcTalk.ScriptId != nextScriptId)
            {
                npcTalk.ContentIndex = 0;
            }
            else
            {
                npcTalk.ContentIndex++;
            }

            Option nextScript    = scriptMetadata.Options.First(x => x.Id == nextScriptId);
            bool   hasNextScript = nextScript.Contents[npcTalk.ContentIndex].Goto.Count != 0;

            if (nextScript.Contents.Count > npcTalk.ContentIndex + 1)
            {
                hasNextScript = true;
            }
            npcTalk.ScriptId = nextScriptId;

            DialogType dialogType = GetDialogType(scriptMetadata, npcTalk, hasNextScript);

            session.Send(NpcTalkPacket.ContinueChat(nextScriptId, responseType, dialogType, npcTalk.ContentIndex, npcTalk.QuestId));
            // It appears if content has buttonset roulette, it's send again on every continue chat, unsure why since it doesn't break anything
        }
コード例 #10
0
    private static void HandleRespond(GameSession session, PacketReader packet)
    {
        List <QuestStatus> npcQuests = new();
        int objectId = packet.ReadInt();

        // Find if npc object id exists in field manager
        if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out IFieldActor <NpcMetadata> npc))
        {
            return;
        }

        // Get all quests for this npc
        foreach (QuestStatus item in session.Player.QuestData.Values.Where(x => x.State is not QuestState.Finished))
        {
            if (npc.Value.Id == item.StartNpcId)
            {
                npcQuests.Add(item);
            }

            if (item.State is QuestState.Started && npc.Value.Id == item.CompleteNpcId && !npcQuests.Contains(item))
            {
                npcQuests.Add(item);
            }
        }

        session.Player.NpcTalk = new(npc.Value, npcQuests);
        NpcTalk npcTalk = session.Player.NpcTalk;

        ScriptLoader scriptLoader = new($"Npcs/{npc.Value.Id}", session);

        // If NPC is a shop, load and open the shop
        if (npc.Value.IsShop())
        {
            ShopHandler.HandleOpen(session, npc);
            return;
        }

        if (npc.Value.IsBank())
        {
            session.Send(HomeBank.OpenBank());
            return;
        }

        if (npc.Value.IsBeauty())
        {
            NpcMetadata npcTarget = NpcMetadataStorage.GetNpcMetadata(npcTalk.Npc.Id);
            if (npcTarget.ShopId == 507) // mirror
            {
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 0));
                HandleBeauty(session);
                return;
            }

            session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 1));
            return;
        }

        // Check if npc has an exploration quest
        QuestHelper.UpdateExplorationQuest(session, npc.Value.Id.ToString(), "talk_in");

        // If npc has quests, send quests and talk option
        if (npcQuests.Count != 0)
        {
            // Check if npc has scripts available
            if (ScriptMetadataStorage.NpcHasScripts(npc.Value.Id))
            {
                npcTalk.ScriptId = 0;
                session.Send(QuestPacket.SendDialogQuest(objectId, npcQuests));
                session.Send(NpcTalkPacket.Respond(npc, NpcType.QuestOptions, DialogType.TalkOption, npcTalk.ScriptId));
                return;
            }

            // If npc has no scripts, send the quest script id
            npcTalk.IsQuest = true;
            npcTalk.QuestId = npcQuests.First().Id;

            ScriptMetadata questScript = ScriptMetadataStorage.GetQuestScriptMetadata(npcTalk.QuestId);
            npcTalk.ScriptId = GetNextScript(questScript, npcTalk, 0, scriptLoader, session.Player);

            session.Send(QuestPacket.SendDialogQuest(objectId, npcQuests));
            session.Send(NpcTalkPacket.Respond(npc, NpcType.Quest, DialogType.CloseNext, npcTalk.ScriptId));
            return;
        }

        ScriptMetadata scriptMetadata = ScriptMetadataStorage.GetNpcScriptMetadata(npc.Value.Id);

        if (!scriptMetadata.Options.Exists(x => x.Type == ScriptType.Script))
        {
            return;
        }

        int firstScriptId = GetFirstScriptId(scriptLoader, scriptMetadata);

        npcTalk.ScriptId = firstScriptId;

        Option option = scriptMetadata.Options.First(x => x.Id == firstScriptId);

        DialogType dialogType = option.Contents[0].Distractor is null ? DialogType.Close1 : DialogType.CloseNextWithDistractor;

        session.Send(NpcTalkPacket.Respond(npc, NpcType.NormalTalk, dialogType, firstScriptId));

        // If npc has buttonset roulette, send roulette id 13.
        // TODO: Send the correct roulette id
        if (scriptMetadata.Options.Any(x => x.ButtonSet == "roulette"))
        {
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "RouletteDialog", "13"));
        }
    }
コード例 #11
0
    //---------------------碰撞-----------------------
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.name == "BossEnemy")         //觸碰到敵人
        {
            TakeDamage(10);
            damageBulletsPool.addDamageInt = 10;
            W1_beaten.SetActive(true);
            damageBulletsPool.Fire();
            StartCoroutine("Bossbeaten");
        }

        if (col.gameObject.name == "AtkParticle")         //序章-玩家受到小BOSS攻擊
        {
            //TakeDamage(BossAtk);
            TakeDamage(10);
            damageBulletsPool.addDamageInt = 10;
            damageBulletsPool.Fire();
            W1_beaten.SetActive(true);
            StartCoroutine("Bossbeaten");
        }

        if (col.gameObject.name == "F1(Clone)") //框框球攻擊
        {
            TakeDamage(5);
            damageBulletsPool.addDamageInt = 5;
            damageBulletsPool.Fire();
            StartCoroutine("Bossbeaten");
        }

        if (col.gameObject.name == "F2") //框框範圍攻擊
        {
            TakeDamage(25);
            damageBulletsPool.addDamageInt = 25;
            damageBulletsPool.Fire();
            F2_beaten.SetActive(true);
            StartCoroutine("Bossbeaten");
        }

        if (col.tag == "EndPoint")  //序章-結束點
        {
            if (ChapterName == "0")
            {
                dg_GameManager.win();
            }
            else if (ChapterName == "1")
            {
                if (StaticObject.sBE1 == 1)                 //BE1迷失森林
                {
                    gameManager.lose();
                }
                else                  //HE1離開森林
                {
                    gameManager.win();
                }
            }
            else if (ChapterName == "2")
            {
                if (StaticObject.sBE2 == 1)
                {
                    gameManager.lose();
                }
                else                  //BE2被遺忘的事
                {
                    gameManager.win();
                }
            }
            else if (ChapterName == "4")
            {
                if (StaticObject.sBE2 == 1)  //BE3萬籟俱寂的等待
                {
                    gameManager.lose();
                }
                else  //HE2真實的世界 +彩蛋
                {
                    gameManager.win();
                }
            }
        }

        if (HealthSlider.value < 100)
        {
            if (col.gameObject.name == "BloodStation")             //補血站
            {
                addBlood = true;
                lineParticle.SetActive(true);
            }

            if (col.tag == "heart")              //補血愛心
            {
                addBulletsPool.addDamageInt = 10;
                addBulletsPool.Fire();
                curHealth += 10;
                Destroy(col.gameObject);
            }
        }

        if (col.tag == "vine")         //進入藤蔓
        {
            activeClimb = col.gameObject.GetComponent <ActiveClimb>();
        }

        if (col.tag == "NPC")         //觸碰到NPC
        {
            npcTalk = col.gameObject.GetComponent <NpcTalk>();
        }

        if (col.tag == "pickUpObj")         //拾取物件
        {
            activePickUp = col.gameObject.GetComponent <ActivePickUp>();

            if (col.gameObject.name == activePickUp.PickUpObjName) //形石
            {
                activePickUp.PickUpObjBool = true;
            }
        }

        if (col.gameObject.name == "redFairy" || col.gameObject.name == "blueFairy")         //觸碰到紅藍精靈
        {
            npcTalk = GameObject.Find("NPC_Statue").GetComponent <NpcTalk>();
        }

        if (col.gameObject.name == "redFlower" || col.gameObject.name == "blueFlower")        //觸碰到紅藍花
        {
            npcTalk = GameObject.Find("NPC_Bobby").GetComponent <NpcTalk>();
        }

        if (col.gameObject.name == "rightClock" || col.gameObject.name == "falseClock")         //觸碰到時鐘
        {
            npcTalk = GameObject.Find("NPC_Dida").GetComponent <NpcTalk>();
        }

        if (col.gameObject.name == "rightKey" || col.gameObject.name == "falseKey") //觸碰到鑰匙
        {
            npcTalk = GameObject.Find("Door").GetComponent <NpcTalk>();
        }

        if (col.gameObject.name == "Teleportation") //傳送陣
        {
            StartCoroutine("Teleportation");
        }
    }
コード例 #12
0
    public void FixedUpdate()
    {
        //-------------JUMP-----------------------------
        if (isActive)
        {
            grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
            animator_S.SetBool("ground", grounded);
            if (ChapterName == "0")
            {
                animator_B.SetBool("ground", grounded);
            }

            if (grounded)
            {
                jumping = false;
                animator_S.SetBool("isJump", jumping);
                if (ChapterName == "0")
                {
                    animator_B.SetBool("isJump", jumping);
                }
                if (CrossPlatformInputManager.GetButtonDown("Jump") || Input.GetKeyDown(KeyCode.B))
                {
                    jumping          = true;
                    rigid2D.velocity = new Vector2(0, jumpForce);
                    animator_S.SetBool("isJump", jumping);
                    if (ChapterName == "0")
                    {
                        animator_B.SetBool("isJump", jumping);
                    }
                }
            }


            //-------------MOVE----------------------------

            Vector2 moveVec = new Vector2(CrossPlatformInputManager.GetAxis("Horizontal"), CrossPlatformInputManager.GetAxis("Vertiacl")) * speed;
            if (Input.GetKey(KeyCode.RightArrow))
            {
                moveVec = new Vector2(2, 0);
            }
            else if (Input.GetKey(KeyCode.LeftArrow))
            {
                moveVec = new Vector2(-2, 0);
            }
            rigid2D.velocity = new Vector2(moveVec.x, rigid2D.velocity.y);

            if (ChapterName == "0")
            {
                animator_S.SetFloat("run", Mathf.Abs(moveVec.x));
                animator_B.SetFloat("run", Mathf.Abs(moveVec.x));
            }
            else
            {
                animator_S.SetFloat("Speed", Mathf.Abs(moveVec.x));
            }


            if (moveVec.x > 0)
            {
                graphics.localRotation     = Quaternion.Euler(0, 0, 0);
                healthCanvas.localRotation = Quaternion.Euler(0, 0, 0);
                attackParticle.rotation    = Quaternion.Euler(0, 0, 0);
                var G0 = gesture.G0_ParticleP.textureSheetAnimation;
                G0.flipU = 0;
                var G1 = gesture.G1_ParticleP.textureSheetAnimation;
                G1.flipU = 0;
                var G2 = gesture.G2_ParticleP.textureSheetAnimation;
                G2.flipU = 0;
                var G3 = gesture.G3_ParticleP.textureSheetAnimation;
                G3.flipU = 0;
                var G4 = gesture.G4_ParticleP.textureSheetAnimation;
                G4.flipU = 0;
                var G5 = gesture.G5_ParticleP.textureSheetAnimation;
                G5.flipU = 0;
                var G6 = gesture.G6_ParticleP.textureSheetAnimation;
                G6.flipU = 0;
                var B1 = gesture.B1_ParticleP.textureSheetAnimation;
                B1.flipU = 0;
                var B2 = gesture.B2_ParticleP.textureSheetAnimation;
                B2.flipU = 0;
                var B3 = gesture.B3_ParticleP.textureSheetAnimation;
                B3.flipU = 0;
                var B4 = gesture.B4_ParticleP.textureSheetAnimation;
                B4.flipU = 0;
                if (ChapterName == "0")
                {
                    dg_GameManager.TeachMove = true;
                }
            }
            else if (moveVec.x < 0)
            {
                graphics.localRotation     = Quaternion.Euler(0, 180, 0);
                healthCanvas.localRotation = Quaternion.Euler(0, 180, 0);
                attackParticle.rotation    = Quaternion.Euler(0, 180, 0);
                var G0 = gesture.G0_ParticleP.textureSheetAnimation;
                G0.flipU = 1;
                var G1 = gesture.G1_ParticleP.textureSheetAnimation;
                G1.flipU = 1;
                var G2 = gesture.G2_ParticleP.textureSheetAnimation;
                G2.flipU = 1;
                var G3 = gesture.G3_ParticleP.textureSheetAnimation;
                G3.flipU = 1;
                var G4 = gesture.G4_ParticleP.textureSheetAnimation;
                G4.flipU = 1;
                var G5 = gesture.G5_ParticleP.textureSheetAnimation;
                G5.flipU = 1;
                var G6 = gesture.G6_ParticleP.textureSheetAnimation;
                G6.flipU = 1;
                var B1 = gesture.B1_ParticleP.textureSheetAnimation;
                B1.flipU = 1;
                var B2 = gesture.B2_ParticleP.textureSheetAnimation;
                B2.flipU = 1;
                var B3 = gesture.B3_ParticleP.textureSheetAnimation;
                B3.flipU = 1;
                var B4 = gesture.B4_ParticleP.textureSheetAnimation;
                B4.flipU = 1;
                if (ChapterName == "0")
                {
                    dg_GameManager.TeachMove = true;
                }
            }
        }
        //-----------------------Climb--------------------------
        if (ChapterName == "1" || ChapterName == "2" || ChapterName == "3")
        {
            if (CrossPlatformInputManager.GetButtonDown("Climb"))
            {
                activeClimb.isClimb = true;
                animator_S.SetBool("climb", true);
                if (ChapterName == "1")
                {
                    dialogsScript1.MaskGroup.SetActive(false);
                    Joystick.isMove = true;
                }
            }

            if (activeClimb.isClimb)
            {
                rigid2D.MovePosition(rigid2D.position + Vector2.up * 2 * Time.deltaTime);
                if (rigid2D.position.y >= activeClimb.highestPoint)
                {
                    rigid2D.position = activeClimb.targetPoint;
                    animator_S.SetBool("climb", false);
                    activeClimb.isClimb = false;
                }
            }
        }

        //----------------------Pick Up--------------------------
        if (CrossPlatformInputManager.GetButtonDown("PickUp"))
        {
            StartCoroutine("notClickable");
            animator_S.SetTrigger("pickUp");

            if (!audio.isPlaying)
            {
                audio.PlayOneShot(pickUp);
            }

            if (activePickUp.task)             //如果是任務
            {
                activePickUp.PickUpObj.SetActive(false);
                activePickUp.anotherObj.SetActive(true);

                if (activePickUp.PickUpObjName == "right")
                {
                    npcTalk.right = true;
                    npcTalk.wrong = false;
                    npcTalk.NPCBoxcollider.enabled = true;
                    if (npcTalk.whoTask == "BobbyTask")
                    {
                        gameManager.Teleportation.SetActive(true);
                        if (pickUpInt == 1)
                        {
                            dialogsScript1.teleportation();
                        }
                    }
                }
                else if (activePickUp.PickUpObjName == "wrong")
                {
                    npcTalk.right = false;
                    npcTalk.wrong = true;
                    npcTalk.NPCBoxcollider.enabled = true;
                    if (npcTalk.whoTask == "BobbyTask")
                    {
                        gameManager.Teleportation.SetActive(true);
                        if (pickUpInt == 1)
                        {
                            dialogsScript1.teleportation();
                        }
                    }
                }

                if (npcTalk.right || npcTalk.wrong)
                {
                    if (npcTalk.whoTask == "BobbyTask" || npcTalk.whoTask == "DidaTask")
                    {
                        npcTask.Task1StarImage.sprite = npcTask.TaskFinishImage;
                        npcTask.Task1bg.sprite        = npcTask.TaskFinishBg;
                        npcTask.Task1Content.SetActive(false);
                        npcTask.Task1FinishContent.SetActive(true);
                    }
                    else if (npcTalk.whoTask == "StatueTask")
                    {
                        npcTask.Task2StarImage.sprite = npcTask.TaskFinishImage;
                        npcTask.Task2bg.sprite        = npcTask.TaskFinishBg;
                        npcTask.Task2Content.SetActive(false);
                        npcTask.Task2FinishContent.SetActive(true);
                    }
                }
            }
            else  //普通拾取物品
            {
                if (activePickUp.PickUpObjBool)
                {
                    if (activePickUp.PickUpObjName == "pillar")
                    {
                        activePickUp.PickUpObj.GetComponent <Animator>().SetTrigger("turnOn");
                        //ActivePickUp.PickUpInt += 1;
                        activePickUp.PickUpObjCol.enabled = false;
                        //int PickInt = activePickUp.PickUpObj.GetComponent<PickUpAddInt>().pick;
                        //Debug.Log(ActivePickUp.PickUpInt);
                        if (ActivePickUp.PickUpInt == 3)
                        {
                            StartCoroutine(dialogsScript3.pillarCameraMove());
                        }
                    }
                    else if (activePickUp.PickUpObjName == "handle")
                    {
                        activePickUp.PickUpObj.GetComponent <Animator>().SetBool("turnOn", true);
                        ActivePickUp.PickUpInt           += 1;
                        activePickUp.PickUpObjCol.enabled = false;
                        Debug.Log(ActivePickUp.PickUpInt);
                        if (ActivePickUp.PickUpInt >= 1) //開平台
                        {
                            StartCoroutine(dialogsScript4.PlatformOpen());
                        }
                    }
                    else
                    {
                        activePickUp.PickUpObj.SetActive(false);
                        ActivePickUp.PickUpInt += 1;
                        Debug.Log(ActivePickUp.PickUpInt);
                    }
                }
            }
            Debug.Log(activePickUp.PickUpObjName);
            isActive = false;
            StartCoroutine("MoveWait");
            //activePickUp.PickUpImg.enabled = false;
        }

        //-----------------------Talk----------------------------
        if (CrossPlatformInputManager.GetButtonDown("Talk"))
        {
            if (npcTalk.gimmick)             //機關
            {
                if (npcTalk.gimmickName == "Stone")
                {
                    if (ActivePickUp.PickUpInt >= 5)
                    {
                        npcTalk.gimmickObj.SetActive(true);
                    }
                    else
                    {
                        //尚未收集完畢
                        gameManager.downHintAni.SetTrigger("whereHint");
                        gameManager.downHintText.text = "形石尚未收集完畢";
                    }
                }

                if (npcTalk.gimmickName == "Mirror")
                {
                    if (ActivePickUp.PickUpInt >= 1)
                    {
                        dialogsScript2.Mirror = true;
                        npcTask.TaskFinish();
                    }
                    else
                    {
                        string taskStart = npcTalk.startTaskName;
                        npcTask.GetComponent <NPCTask>().Invoke(taskStart, 0f);
                        //尚未收集完畢
                        gameManager.downHintAni.SetTrigger("whereHint");
                        gameManager.downHintText.text = "尚未取得入場券";
                    }
                }

                if (npcTalk.gimmickName == "Door")
                {
                    if (npcTalk.right == true)  //完成任務
                    {
                        npcTask.TaskFinish();
                    }
                    else if (npcTalk.wrong == true)
                    {
                        string taskStart = npcTalk.startTaskName;
                        npcTask.GetComponent <NPCTask>().Invoke(taskStart, 0f);
                        //尚未收集完畢
                        gameManager.downHintAni.SetTrigger("whereHint");
                        gameManager.downHintText.text = "這把鑰匙無法開啟";
                    }
                    else
                    {
                        gameManager.downHintAni.SetTrigger("whereHint");
                        gameManager.downHintText.text = "沒有開啟門的鑰匙";
                    }
                }
            }
            else             //一般NPC
            {
                if (Mathf.Abs(rigid2D.transform.position.x - npcTalk.NPC.transform.position.x) < 2 && npcTalk.isTasting == false)
                {
                    npcTalk.isTasting = true;
                    if (npcTalk.right == true || npcTalk.wrong == true && npcTalk.finishPoint.activeInHierarchy == true)                      //完成任務
                    {
                        npcTask.TaskFinish();
                    }
                    else                      //接任務
                    {
                        string taskStart = npcTalk.startTaskName;
                        npcTask.GetComponent <NPCTask>().Invoke(taskStart, 0f);
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            Vector2      worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit        = Physics2D.Raycast(worldPoint, Vector2.zero);
            if (hit.collider == null)
            {
            }
            else if (hit.collider.name == "NPC_Bobby" || hit.collider.name == "NPC_Statue" /*|| hit.collider.name == "Stone"*/ || hit.collider.name == "NPC_Dida" || hit.collider.name == "NPC_Coco" || hit.collider.name == "NPC_Dragon" || hit.collider.name == "Mirror" && Mathf.Abs(rigid2D.transform.position.x - npcTalk.NPC.transform.position.x) < 2 && npcTalk.isTasting == false)
            {
                npcTalk = hit.collider.GetComponent <NpcTalk>();
                if (npcTalk.gimmick)                 //機關
                {
                    if (npcTalk.gimmickName == "Stone")
                    {
                        if (ActivePickUp.PickUpInt >= 5)
                        {
                            npcTalk.gimmickObj.SetActive(true);
                        }
                        else
                        {
                            gameManager.downHintAni.SetTrigger("whereHint");
                            gameManager.downHintText.text = "形石尚未收集完畢";
                        }
                    }

                    if (npcTalk.gimmickName == "Mirror")
                    {
                        if (ActivePickUp.PickUpInt >= 1)
                        {
                            dialogsScript2.Mirror = true;
                            npcTask.TaskFinish();
                        }
                        else
                        {
                            string taskStart = npcTalk.startTaskName;
                            npcTask.GetComponent <NPCTask>().Invoke(taskStart, 0f);
                            gameManager.downHintAni.SetTrigger("whereHint");
                            gameManager.downHintText.text = "尚未取得入場券";
                        }
                    }
                }
                else                 //一般NPC
                {
                    if (Mathf.Abs(rigid2D.transform.position.x - npcTalk.NPC.transform.position.x) < 2 && npcTalk.finishPoint.activeInHierarchy == true && npcTalk.isTasting == false)
                    {
                        npcTalk.isTasting = true;
                        if (npcTalk.right == true || npcTalk.wrong == true && npcTalk.finishPoint.activeInHierarchy == true)                          //完成任務
                        {
                            npcTask.TaskFinish();
                        }
                        else                          //接任務
                        {
                            string taskStart = npcTalk.startTaskName;
                            npcTask.GetComponent <NPCTask>().Invoke(taskStart, 0f);
                        }
                    }
                }
            }
        }
    }
コード例 #13
0
    private static void HandleBegin(GameSession session, PacketReader packet)
    {
        int objectId = packet.ReadInt();
        List <QuestStatus> npcQuests = new();
        int contentIndex             = 0;

        // Find if npc object id exists in field manager
        if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out Npc npc))
        {
            return;
        }

        // Get all quests for this npc
        foreach (QuestStatus item in session.Player.QuestData.Values.Where(x => x.State is not QuestState.Completed))
        {
            if (npc.Value.Id == item.StartNpcId)
            {
                npcQuests.Add(item);
            }

            if (item.State is QuestState.Started && npc.Value.Id == item.CompleteNpcId && !npcQuests.Contains(item))
            {
                npcQuests.Add(item);
            }
        }

        session.Player.NpcTalk = new(npc.Value, npcQuests);
        NpcTalk npcTalk = session.Player.NpcTalk;

        ScriptMetadata scriptMetadata = ScriptMetadataStorage.GetNpcScriptMetadata(npc.Value.Id);
        NpcKind        kind           = npc.Value.NpcMetadataBasic.Kind;

        // need to find script properly before continuing
        NpcScript npcScript = GetFirstScript(session, scriptMetadata, npcTalk, npcQuests);

        switch (kind)
        {
        // reputation NPCs only have UI Dialog Type even if they have quests to accept/accepted.
        case NpcKind.SkyLumiknightCommander:
        case NpcKind.SkyGreenHoodCommander:
        case NpcKind.SkyDarkWindCommander:
        case NpcKind.SkyMapleAllianceCommander:
        case NpcKind.SkyRoyalGuardCommander:
        case NpcKind.KritiasLumiknightCommander:
        case NpcKind.KritiasGreenHoodCommander:
        case NpcKind.KritiasMapleAllianceCommander:
        case NpcKind.Humanitas:
            npcTalk.DialogType = DialogType.UI;
            ShopHandler.HandleOpen(session, npc, npc.Value.Id);
            break;

        case NpcKind.BalmyShop:
        case NpcKind.FixedShop:
        case NpcKind.RotatingShop:
            ShopHandler.HandleOpen(session, npc, npc.Value.Id);
            break;

        case NpcKind.Storage:
        case NpcKind.BlackMarket:
        case NpcKind.Birthday:     // TODO: needs a special case? select if birthday. script if not
            npcTalk.DialogType = DialogType.UI;
            break;
        }

        npcTalk.ScriptId = npcScript?.Id ?? 0;
        ResponseSelection responseSelection = GetResponseSelection(kind, npcTalk.DialogType, contentIndex, npcScript);

        if (npcTalk.DialogType.HasFlag(DialogType.Quest))
        {
            session.Send(QuestPacket.SendDialogQuest(objectId, npcQuests));
        }

        QuestManager.OnTalkNpc(session.Player, npc.Value.Id, npcTalk.ScriptId);
        session.Send(NpcTalkPacket.Respond(npc, npcTalk.DialogType, contentIndex, responseSelection, npcTalk.ScriptId));

        if (npcScript != null)
        {
            npcTalk.TalkFunction(session, npcScript.Contents[npcTalk.ContentIndex].FunctionId, "preTalkActions");
        }
    }