Esempio n. 1
0
    private void BuyInfluenceClicked()
    {
        Guild pGuild = GameManager.Instance.PlayerAvatar.GetComponent <PlayerController>().MyGuild;

        if (!pGuild)
        {
            Debug.Log("PlayerController's MyGuild was null");
            return;
        }

        Inventory sourceInv = GameManager.Instance.PlayerAvatar.GetComponent <Inventory>();

        if (!sourceInv)
        {
            Debug.Log("PlayerAvatar did not have an inventory component");
            return;
        }

        int amtGold = sourceInv.GetAmtResource(Inventory.ResourceType.Gold);

        if (amtGold >= 50)
        {
            sourceInv.RemoveResources(Inventory.ResourceType.Gold, 50);
            pGuild.AddInfluenceFor(_vill.gameObject, 10);
        }
    }
Esempio n. 2
0
    private void HandleEnemyStrategy()
    {
        switch (_currEnemyAlertStatus)
        {
        case EnemyAlertStatus.Aggressive:
            if (!TargetedEnemy)
            {
                GameObject closestEnemy = EnemyBehaviour.GetClosestEnemy(transform.position);
                if (closestEnemy)
                {
                    if ((closestEnemy.transform.position - transform.position).sqrMagnitude < (_enemyDetectRange * _enemyDetectRange))
                    {
                        TargetedEnemy     = closestEnemy;
                        _currCombatStatus = CombatStatus.Chasing;
                    }
                }
            }

            if (TargetedEnemy)
            {
                if ((TargetedEnemy.transform.position - transform.position).sqrMagnitude > (30.0f * 30.0f))
                {
                    TargetedEnemy     = null;
                    _currCombatStatus = CombatStatus.OutOfCombat;
                }
                else
                {
                    SetTarget(TargetedEnemy.transform);
                }
            }
            else if (Target)
            {
                SetTarget(Target.transform);
            }

            break;

        case EnemyAlertStatus.Defensive:

            if (TargetedEnemy)
            {
                if ((TargetedEnemy.transform.position - transform.position).sqrMagnitude > (30.0f * 30.0f))
                {
                    TargetedEnemy     = null;
                    _currCombatStatus = CombatStatus.OutOfCombat;
                }
                else
                {
                    _attachedNavMeshAgent.isStopped = false;
                    SetTarget(TargetedEnemy.transform);
                }
            }


            break;

        case EnemyAlertStatus.Ignore:     // literally nothing
            break;

        case EnemyAlertStatus.Guard:

            _accuPatrolSeconds += Time.deltaTime;
            if (_accuPatrolSeconds >= _maxPatrolSeconds)
            {
                _accuPatrolSeconds -= _maxPatrolSeconds;
                NPCsGuild.AddInfluenceFor(_villToDefend.gameObject, 1);
            }

            if (!TargetedEnemy)
            {
                // Handle patrolling
                float      acceptableDistance = 5.0f;
                GameObject currPatrolPoint    = _villToDefend.GetComponent <PatrolRoute>().RoutePoints[_currPatrolPointIdx];
                if ((currPatrolPoint.transform.position - transform.position).sqrMagnitude < acceptableDistance)
                {
                    _currPatrolPointIdx = (_currPatrolPointIdx + 1) % _villToDefend.GetComponent <PatrolRoute>().RoutePoints.Count;
                }
                Target = _villToDefend.GetComponent <PatrolRoute>().RoutePoints[_currPatrolPointIdx];

                // Search for an enemy
                GameObject closestEnemy = EnemyBehaviour.GetClosestEnemy(transform.position);
                if (closestEnemy)
                {
                    if ((closestEnemy.transform.position - transform.position).sqrMagnitude < (_enemyDetectRange * _enemyDetectRange))
                    {
                        TargetedEnemy     = closestEnemy;
                        _currCombatStatus = CombatStatus.Chasing;
                    }
                }
            }

            if (!TargetedEnemy)
            {
                _attachedNavMeshAgent.SetDestination(Target.transform.position);
            }
            else
            {
                _attachedNavMeshAgent.SetDestination(TargetedEnemy.transform.position);
            }


            break;
        }
    }