Exemple #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);
    }
Exemple #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);
    }
Exemple #3
0
    private ActionScore GetGeneralScore(List <Humanoid> targets, SkillCategory category = SkillCategory.Attack, float selfEffector = 1, float targetEffector = 1)
    {
        List <ActionScore> Targets = new List <ActionScore>();

        // Calculate healing weight for all alive team members
        foreach (Humanoid h in targets)
        {
            if (h.IsDead)
            {
                continue;
            }

            ActionScore newTarget = new ActionScore();
            newTarget.Target = h;

            // Get chance of hitting target
            float distanceFrom  = Vector2.Distance(h.transform.position, ActiveHuman.transform.position);
            float distanceScore = GetDistanceScore(distanceFrom);

            // Get health score applying self effector if active player
            if (h.GetHashCode() == ActiveHuman.GetHashCode())
            {
                float generalScore = GetHealthScore(h.CharData.health, h.MaxHealth, category, selfEffector, targetEffector);
                newTarget.Score = distanceScore * (generalScore / 50);
                //Debug.Log("General state score: " + newTarget.Score);
            }
            else
            {
                newTarget.Score = distanceScore * (GetHealthScore(h.CharData.health, h.MaxHealth, category, targetEffector) / 50);
                //Debug.Log("General state score: " + newTarget.Score);
            }

            // Cap Score
            if (newTarget.Score > 50)
            {
                newTarget.Score = 50;
            }

            Targets.Add(newTarget);
        }

        return(GetHighest(Targets));
    }
Exemple #4
0
    public void CallUpdate()
    {
        if (base.IsTimerActive)
        {
            base.UpdateDelayTimer();
        }
        else
        {
            // If enemy ai has performed an attack then end turn and return from method
            if (HasAttacked)
            {
                ActiveHuman.StopMovement();
                EndTurn();
                return;
            }

            if (CurrentState == State.Enabled)
            {
                ActivateAction(winningAction);
            }
        }
    }
Exemple #5
0
    private Humanoid Closest(List <Humanoid> team)
    {
        Humanoid closest     = null;
        float    minDistance = 10000;

        foreach (Humanoid h in team)
        {
            // Skip active player
            if (h.GetHashCode() == ActiveHuman.GetHashCode())
            {
                continue;
            }

            float distance = Vector3.Distance(ActiveHuman.Position, h.Position);

            if (minDistance > distance)
            {
                closest     = h;
                minDistance = distance;
            }
        }

        return(closest);
    }
Exemple #6
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();
    }