Esempio n. 1
0
 private void InventoryUIToggle()
 {
     if (Input.GetButtonDown("Inventory"))
     {
         if (inventoryUI.activeSelf) //if already active go to idle
         {
             psm.RequestChangeState(StateMachine.States.Idle);
         }
         else
         {
             psm.RequestChangeState(StateMachine.States.InvOpen);
         }
         ScriptToolbox.GetInstance().GetWindowCloser().DestroyPopupMenus();
     }
 }
Esempio n. 2
0
    void TriggerAttack()
    {
        Debug.Log("Player is attacking " + gameObject.name);
        UnitStateMachine u = ScriptToolbox.GetInstance().GetPlayerManager().player.GetComponent <UnitStateMachine>();

        u.currentThreat = transform;
        u.RequestChangeState(StateMachine.States.Fight);
    }
Esempio n. 3
0
 void TriggerTrade()
 {
     if (myShop != null)
     {
         UnitStateMachine u = GetComponent <UnitStateMachine>();
         u.RequestChangeState(StateMachine.States.Shopping);
     }
     else
     {
         Debug.Log("This NPC cannot trade");
     }
 }
Esempio n. 4
0
    private IEnumerator Flee()
    {
        Vector3 closestExit = GetClosestExit();
        float   z           = transform.position.z;

        PathfindingManager.RequestPath(new PathRequest(transform.position, closestExit, usm.unitController.OnPathFound));
        while (Vector3.Distance(transform.position, closestExit) > 0.5f)
        {
            yield return(null);
        }
        usm.RequestChangeState(StateMachine.States.Routed);
    }
Esempio n. 5
0
    public virtual void RecieveAttack(AttackInfo recievedAttack, Transform myAttacker)
    {
        //don't keep reacting to the same attack
        if (stateMachine.currentState != StateMachine.States.Fight ||
            stateMachine.currentState != StateMachine.States.Flight ||
            stateMachine.currentState != StateMachine.States.FightOrFlight)
        {
            stateMachine.currentThreat = myAttacker;
            stateMachine.RequestChangeState(StateMachine.States.FightOrFlight);
        }

        if (Hit())
        {
            BodyPart bodyPart = GetRandomPart();
            bodyPart.TakeDamage(recievedAttack);
        }

        if (PartTooInjured(vitalParts))
        {
            stateMachine.RequestChangeState(StateMachine.States.Dead);
            string line = "<color=red>" + gameObject.name + " has been mortally wounded!</color>";
            BattleReport.AddToBattleReport(line);
        }
    }
Esempio n. 6
0
    private IEnumerator Engage(Transform _targetTransform)
    {
        //Debug.LogError(gameObject.name + " is engaging " + _targetTransform.name);
        bool inRange;

        targetTransform = _targetTransform;
        targetBody      = targetTransform.GetComponent <BodyPartController>();
        attack1Parts    = usm.attack1Parts;
        attack2Parts    = usm.attack2Parts;

        UnitController     uc       = usm.unitController;
        BodyPartController opponent = targetTransform.GetComponent <BodyPartController>();
        Collider2D         col      = GetComponent <Collider2D>();

        usm.unitAnim.FaceDirection(transform.position, targetTransform.position);

        while (!opponent.Incapacitated())
        {
            //eventually this will be a function that will check if ranged or melee, then decide if in range or not
            //for ranged we can use a raycast of some sort to check for obstabcles
            inRange = col.IsTouching(targetTransform.GetComponent <Collider2D>());

            if (!inRange)
            {
                PathfindingManager.RequestPath(new PathRequest(transform.position, targetTransform.position, uc.OnPathFound));
                yield return(new WaitForSeconds(.1f));
            }
            else if (!usm.attackTimer.coolingDown)
            {
                Attack();
            }
            yield return(null);
        }
        usm.RequestChangeState(StateMachine.States.Idle);
        yield break;
    }
Esempio n. 7
0
    //can be used for descriptions and observations as well
    void TriggerDialogue()
    {
        UnitStateMachine u = GetComponent <UnitStateMachine>();

        u.RequestChangeState(StateMachine.States.Talking);
    }
Esempio n. 8
0
 //dialogue ended via continue button
 private void SoftDialogueExit()
 {
     unitTalking.RequestChangeState(StateMachine.States.Idle);
     ScriptToolbox.GetInstance().GetPlayerManager().playerStateMachine.RequestChangeState(StateMachine.States.Idle);
     CloseDialogueWindow();
 }