コード例 #1
0
ファイル: NPCMain.cs プロジェクト: JesperBystrom/Portfolio
    private void Update()
    {
        Collider[] col = Physics.OverlapSphere(this.transform.position, 1);
        foreach (Collider c in col)
        {
            if (c.gameObject.CompareTag("Player"))
            {
                if (currentDialoguePlaying == null && canTalk && !isTalking)
                {
                    if (player == null)
                    {
                        this.player = c.gameObject.GetComponent <Player>();
                        this.player.npcTalkingTo = this.gameObject;
                    }
                    talk();
                }
            }
        }

        if (currentDialoguePlaying != null && Input.GetKeyDown(KeyCode.Z))
        {
            if (!currentDialoguePlaying.isFinished())
            {
                if (dialogueUI.activeInHierarchy == false)
                {
                    dialogueUI.SetActive(true);
                    dialogueUI_questGiverName.text   = this.nickname;
                    dialogueUI_questGiverFace.sprite = (Resources.LoadAll <Sprite>("spritesheet_NpcIcons"))[this.uniqueId];
                    this.player.getPlayerMovement().freeze();
                }

                this.dialogueUI_questDescription.text = currentDialoguePlaying.execute();
                if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Talk"))
                {
                    animator.Play("Talk");
                }
                return;
            }
            else
            {
                Debug.Log("QUESTS_LENGTH: " + quests.Length + " | " + currentDialoguePlaying.getId());

                foreach (Quest q in this.currentDialoguePlaying.questsToGiveOut)
                {
                    if (!player.hasQuest(q))
                    {
                        giveQuestToPlayer(new Quest(q.id, player.getCharacterName()));
                        dispose();
                        return;
                    }
                }

                /*for(int i=0;i<this.quests.Length;i++){
                 *      if(this.quests[i].getStatus() == e_QuestStatus.COMPLETED){
                 *              onQuestTurnIn(this.quests[i]);
                 *              dispose();
                 *              return;
                 *      }
                 * }*/
                if (player != null)
                {
                    foreach (Quest q in this.player.quests)
                    {
                        if (q.getStatus() == e_QuestStatus.COMPLETED)
                        {
                            this.player.getNetwork().sendQuestToServer(q, PacketTypes.QUEST_TURN_IN);
                            dispose();
                            return;
                        }
                    }
                }
            }
            dispose();
        }
    }