Esempio n. 1
0
    public void startCollecting(ResourceTypes t)
    {
        // after dropping resource



        // npc is not in range of current building
        if (!isBuildingInRange(currentbuilding))
        {
            findBuilding();
        }

        //updateLocations();
        agent.enabled   = true;
        agent.isStopped = false;
        state           = npcState.gotoResource;


        if (findingType != t)
        {
            findingType = t;
            curRes      = 0;
        }
        setSkills();

        // Current resource is not the right type
        findResource();

        if (currentresource == null)
        {
            agent.SetDestination(transform.position);
        }
    }
Esempio n. 2
0
 private void OnValidate()
 {
     if (prevState != state)
     {
         startCollecting(findingType);
         prevState = state;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 取得道具,每次增加 1 個道具並更新介面
 /// </summary>
 public void GetProp()
 {
     propCurrent++;
     aud.PlayOneShot(soundProp, 1f);
     textProp.text = "零件: " + propCurrent + " / " + propTotal;
     if (propCurrent == propTotal)
     {
         _npcState = npcState.complete;
     }
 }
Esempio n. 4
0
 void Start()
 {
     movement       = GetComponent <Movement>();
     searchBehavior = GetComponent <FindTarget>();
     gm             = GameObject.Find("GlobalManager").GetComponent <GlobalManager>();
     ds             = GameObject.Find("PlayerCanvas").GetComponent <DialogueSystem>();
     player         = GameObject.FindGameObjectWithTag("Player");
     currentState   = npcState.Idle;
     isBusy         = false;
     nameTitle      = Instantiate(nameTitle, transform.position + Vector3.up, Quaternion.identity) as GameObject;
     nameTitle.GetComponent <TextMesh>().text = gameObject.name;
 }
Esempio n. 5
0
 void ToggleInterrogate()
 {
     if (currentState == npcState.Interrogated)
     {
         currentState = npcState.Idle;
         ds.SetDialogue(gameObject.name + ": Goodbye");
         ds.DelayClearLog();
     }
     else
     {
         currentState = npcState.Interrogated;
     }
 }
Esempio n. 6
0
 IEnumerator doJob()
 {
     ready = false;
     if (currentresource == null)
     {
         state = npcState.gotoResource;
         yield return(null);
     }
     else
     {
         gather();
         yield return(new WaitForSeconds(pickupTime));
     }
     ready = true;
 }
 public void NPCCheckHealth()
 {
     if (npcCurrentHealth > npcCuredThreshold)
     {
         npcCurrentState = npcState.isCured;
         EnemyManager.currentCuredEnemies++;
     }
     else if (npcCurrentHealth > npcFeverThreshold)
     {
         npcCurrentState = npcState.isNeutral;
     }
     else if (npcCurrentHealth < npcFeverThreshold)
     {
         npcCurrentState = npcState.isFeverish;
     }
 }
Esempio n. 8
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case npcState.gotoBuilding:
            checkBuilding();
            moveSteps(currentbuilding);
            break;

        case npcState.gotoResource:
            checkRes();
            moveSteps(currentresource);
            break;

        case npcState.dropRes:

            if (isEmpty())
            {
                state = npcState.gotoResource;
            }
            else if (emptyBuilding())
            {
                findBuilding();
                state = npcState.gotoBuilding;
            }
            break;

        case npcState.gatherRes:
            if (isFull())
            {
                state = npcState.gotoBuilding;
            }
            else if (currentresource == null)
            {
                checkRes();
                state = npcState.gotoResource;
            }
            break;


        case npcState.asleep:
            //agent.isStopped = true;
            break;

        default: break;
        }
    }
Esempio n. 9
0
 private void OnTriggerStay(Collider other)
 {
     if (ready)
     {
         if (this.isSelectedResource(other))
         {
             // Change state from going to res to gathering
             if (state == npcState.gotoResource)
             {
                 state = npcState.gatherRes;
             }
             else if (state == npcState.gatherRes)
             {
                 if (isFull())
                 {
                     state = npcState.gotoBuilding;
                 }
                 else
                 {
                     StartCoroutine(doJob());
                 }
             }
         }
     }
     if (this.isSelectedResBuilding(other))
     {
         if (state == npcState.gotoBuilding)
         {
             state = npcState.dropRes;
         }
         else if (state == npcState.dropRes)
         {
             if (isEmpty())
             {
                 state = npcState.gotoResource;
             }
             else
             {
                 if (ready)
                 {
                     drop();
                 }
             }
         }
     }
 }
Esempio n. 10
0
 public void changeState(npcState state, GameObject _object = null)
 {
     nowState         = state;
     gameObject.layer = LayerMask.NameToLayer("npc");
     if (state == npcState.follow)
     {
         if (_object != null)
         {
             player = _object;
         }
         gameObject.layer = LayerMask.NameToLayer("follow");
         rayMask          = (1 << LayerMask.NameToLayer("collider"));
     }
     else
     {
         gameObject.layer = LayerMask.NameToLayer("npc");
         rayMask          = (1 << LayerMask.NameToLayer("collider")) | (1 << LayerMask.NameToLayer("player"));
         target           = transform.position;
     }
 }
Esempio n. 11
0
    /// <summary>
    /// 對話開始
    /// </summary>
    private void DialogStart()
    {
        dialog.SetActive(true);
        StopAllCoroutines();                        // 停止所有協同程序

        switch (_npcState)
        {
        case npcState.start:
            StartCoroutine(ShowDialog(dialogStart));
            _npcState = npcState.notComplete;
            break;

        case npcState.notComplete:
            StartCoroutine(ShowDialog(dialogNotComplete));
            break;

        case npcState.complete:
            StartCoroutine(ShowDialog(dialogComplete));
            break;
        }

        /**
         * int lv = 1;
         * // 判斷式 switch
         * switch (lv)
         * {
         *  case 1:
         *      print("1 等");
         *      break;
         *  case 10:
         *      print("10 等");
         *      break;
         *  default:
         *      print("未定義");
         *      break;
         * }
         */
    }
Esempio n. 12
0
 public void SendToCrime(GameObject _prop)
 {
     currentState = npcState.Bored;
     targetProp   = _prop;
 }
Esempio n. 13
0
    void Start()
    {
        npcCurrentState = npcState.isNeutral;

        sicknessArea.GetComponent <SicknessAura>().enabled = auraFromStart;
    }
Esempio n. 14
0
 public void SendToVictim(GameObject _guest)
 {
     currentState = npcState.Violent;
     targetGuest  = _guest;
 }
Esempio n. 15
0
 void GoIdle()
 {
     currentState = npcState.Idle;
 }
Esempio n. 16
0
    void Update()
    {
        switch (currentState)
        {
        case (npcState.Idle): {
            isBusy = false;
            ResetAITargets();
            currentState = PickState();
            break;
        }

        case (npcState.Talkative): {
            if (targetConvo == null)
            {
                targetConvo = GetRandomFromArray(arrTypes.Convo);
            }
            else
            {
                if (GetDistanceFrom(targetConvo) > interactionDistance)
                {
                    movement.Approach(targetConvo);
                }
                else if (!isBusy)
                {
                    Invoke("GoIdle", focusTime);
                    isBusy = true;
                }
            }
            break;
        }

        case (npcState.Bored): {
            if (targetProp == null)
            {
                targetProp = GetRandomFromArray(arrTypes.Prop);
            }
            else if (GetDistanceFrom(targetProp) > interactionDistance)
            {
                movement.Approach(targetProp);
            }
            else if (!isBusy)
            {
                isBusy = true;
                Invoke("GoIdle", focusTime);
            }
            break;
        }

        case (npcState.Violent): {
            if (targetGuest == null)
            {
                currentState = npcState.Idle;
            }
            else if (GetDistanceFrom(targetGuest) > interactionDistance)
            {
                movement.Approach(targetGuest);
            }
            else
            {
                Kill();
            }
            break;
        }

        case (npcState.Panic): {
            if (player == null)
            {
                currentState = npcState.Idle;
            }
            else if (GetDistanceFrom(player) > interactionDistance)
            {
                movement.Approach(player);
            }
            else
            {
                Invoke("GoIdle", 3f);
            }
            break;
        }

        case (npcState.Interrogated): {
            if (GetDistanceFrom(player) > interactionDistance * 3f)
            {
                currentState = npcState.Idle;
                ds.SetDialogue(gameObject.name + ": Goodbye");
                ds.DelayClearLog();
            }
            else
            {
                movement.CancelMovement();
                movement.FaceToward(player);
                ds.SetDialogue(gameObject.name + ": I haven't seen anything");
            }
            break;
        }

        default: {
            movement.Roam();
            break;
        }
        }
        nameTitle.transform.position = transform.position + Vector3.up;
    }
Esempio n. 17
0
 void SetWitness()
 {
     currentState = npcState.Panic;
     Invoke("GoIdle", 10f);
 }
Esempio n. 18
0
    public void SetState(npcState newState)
    {
        // things to do when leaving state and entering s
        switch (newState)
        {
        case (npcState.idle):
        {
            break;
        }

        case (npcState.Celebrate):
        {
            break;
        }

        case (npcState.Disappointed):
        {
            path.SetPlaybackMode(splineMgr.ePlaybackMode.paused);
            break;
        }

        case (npcState.InteractWithPlayer):
        {
            break;
        }

        case (npcState.startPatrol):
        {
            if (path != null)
            {
                path.HeadObj = this.gameObject;
                path.SetPlaybackMode(splineMgr.ePlaybackMode.paused);
                path.reset();
            }
            break;
        }

        case (npcState.patrol):
        {
            path.HeadObj = this.gameObject;
            path.SetPlaybackMode(splineMgr.ePlaybackMode.loop);
            break;
        }

        case (npcState.pause):
        {
            path.HeadObj = this.gameObject;
            path.SetPlaybackMode(splineMgr.ePlaybackMode.paused);
            break;
        }

        case (npcState.turnToPlayer):
        {
            path.SetPlaybackMode(splineMgr.ePlaybackMode.none);
            break;
        }

        case (npcState.none):
        {
            break;
        }

        case (npcState.invalid):
        {
            break;
        }
        }
        state = newState;
    }