Beispiel #1
0
    public void UpdateAttackTarget()
    {
        if (HasAttacked)
        {
            CurrentTurnState = TurnState.ExitTurn;
        }

        Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

        // Perform attack when target is clicked on && Display target information when hovering over target
        if (hit != false && hit.collider != null)
        {
            // Return from method if hit item is part of the blocking layer or is the current active human
            if (hit.collider.tag == "Blocking" || hit.collider.gameObject == ActiveHuman.gameObject)
            {
                return;
            }

            TextColorPack colorPack = ActiveHuman.Attack.CategoryColor();

            if (Input.GetMouseButtonDown(0))
            {
                ActiveHuman.SetFacingDirection((ActiveHuman.Position - hit.transform.position).x);
                ActiveHuman.PlayShootAnim();


                if (IsHit(hit.collider.gameObject))
                {
                    stats.hits++;
                    stats.shotsFired++;
                    ActiveHuman.soundStatus = SoundStatus.Hit;
                    ActiveHuman.Attack.Perform(hit.collider.gameObject, ActiveHuman.CharData, base.floatingTextMgr);
                }
                else
                {
                    stats.misses++;
                    stats.shotsFired++;
                    ActiveHuman.soundStatus = SoundStatus.Miss;
                    base.DisplayMissMsg(hit.transform.position, colorPack.fontColor, colorPack.outlineColor);
                }

                ActiveHuman.Recovery += ActiveHuman.Attack.RecoveryCost;
                ChangeState(TurnState.ExitTurn);
            }

            DisplayStateMessage(TurnState.Attacking, "Use <color=" + colorPack.fontColor.ColorAsHex() + ">" + ActiveHuman.Attack.Name + "</color> On: " + hit.collider.name);
        }
        else
        {
            DisplayStateMessage(TurnState.Attacking, "Select a target.");
        }

        DisplayMousePointer(TurnState.Attacking, CursorsType.Skill);
    }
Beispiel #2
0
    private void UseDefensive(Humanoid target)
    {
        if (target == null)
        {
            Debug.Log("Can't find defensive target");
        }

        float targetDist = Vector2.Distance(target.transform.position, ActiveHuman.Position);

        // Move if possible and hasn't already moved
        AttemptMove(target.Position);

        // Attempt to hit nearest target if any movement is complete
        if (HasMoved)
        {
            Humanoid closestTarget = Closest(TeamPlayers);

            if (closestTarget == null)
            {
                HasAttacked = true;
                return;
            }

            targetDist = Vector2.Distance(closestTarget.transform.position, ActiveHuman.Position);

            // Perform attack if less than 140% of optimal distance
            if (targetDist < optimalDistance * 1.4f)
            {
                ActiveHuman.SetFacingDirection((ActiveHuman.Position - closestTarget.Position).x);
                ActiveHuman.PlayShootAnim();

                TextColorPack colorPack = ActiveHuman.Attack.CategoryColor();

                if (IsHit(target.gameObject))
                {
                    ActiveHuman.Attack.Perform(closestTarget.gameObject, ActiveHuman.CharData, base.floatingTextMgr);
                    ActiveHuman.soundStatus = SoundStatus.Hit;
                }
                else
                {
                    DisplayMissMsg(closestTarget.transform.position, colorPack.fontColor, colorPack.outlineColor);
                    ActiveHuman.soundStatus = SoundStatus.Miss;
                }

                HasAttacked = true;
            }
        }

        Debug.Log("HasMoved: " + HasMoved);
        Debug.Log("HasAttacked: " + HasAttacked);
    }
Beispiel #3
0
    // Perform an attack or move towards target
    private void UseAttack(Humanoid target)
    {
        if (ActiveHuman.Attack.Type == SkillType.Single)
        {
            float targetDist = Vector2.Distance(target.transform.position, ActiveHuman.Position); // get Target Position
            //bool moveCloser = false;

            // Perform attack if less than 140% of optimal distance otherwise move towards player
            if (targetDist < optimalDistance * 1.4f)
            {
                ActiveHuman.SetFacingDirection((ActiveHuman.Position - target.Position).x);
                ActiveHuman.PlayShootAnim();

                TextColorPack colorPack = ActiveHuman.Attack.CategoryColor();

                bool performSupportAbility = false;

                if (ActiveHuman.CharData.type == UnitType.Support)
                {
                    float roll = UnityEngine.Random.value * 100;
                    performSupportAbility = (roll >= 50) ? true : false;
                    colorPack             = ActiveHuman.Ability.CategoryColor();
                }

                if (IsHit(target.gameObject))
                {
                    if (ActiveHuman.CharData.type != UnitType.Support || !performSupportAbility)
                    {
                        ActiveHuman.Attack.Perform(target.gameObject, ActiveHuman.CharData, base.floatingTextMgr);
                        ActiveHuman.soundStatus = SoundStatus.Hit;
                    }
                    else if (ActiveHuman.CharData.type == UnitType.Support && performSupportAbility)
                    {
                        Debug.Log("Used ability");
                        ActiveHuman.Ability = new SuppressiveFire(SkillType.Single);

                        ActiveHuman.Ability.Perform(target.gameObject, ActiveHuman.CharData, base.floatingTextMgr);
                        ActiveHuman.soundStatus = SoundStatus.Ability;
                    }
                }
                else
                {
                    DisplayMissMsg(target.transform.position, colorPack.fontColor, colorPack.outlineColor);
                    ActiveHuman.soundStatus = SoundStatus.Miss;
                }

                HasAttacked = true;

                Debug.Log("Inside Enemy Controller Stuck at ability");
            }
            else
            {
                // Move if possible and hasn't already moved, otherwise
                AttemptMove(target.Position);
            }
        }
        else if (ActiveHuman.Attack.Type == SkillType.Multiple)
        {
            // is any player members close enough?
            // Get Position between player member
            // is within 140% of optimal range?
            // no? then move closer
            //ActiveHuman.soundStatus = SoundStatus.Ability;
        }

        NewDelay();
    }