Exemplo n.º 1
0
    internal static Character01 FindUnit(Vector2 position, Character01 source, Func <Character01, Character01, bool> check)
    {
        List <Character01> units = Instance.Units;
        float minDist            = float.MaxValue;
        int   minI = -1;

        for (int i = 0; i < units.Count; i++)
        {
            if (source == units[i])
            {
                continue;
            }
            if (check(source, units[i]))  //units[i].data.alliance != alliance
            {
                float dist = Vector2.Distance(position, units[i].transform.position);
                if (dist > 0 && (minI == -1 || dist < minDist))
                {
                    minI    = i;
                    minDist = dist;
                }
            }
        }
        if (minI != -1)
        {
            return(units[minI]);
        }
        return(null);
    }
Exemplo n.º 2
0
 public CombatAction(CombatActionId evt, Character01 source, Character01 target, int abilityId, Vector3 direction)
 {
     this.evt       = evt;
     this.source    = source;
     this.target    = target;
     this.abilityId = abilityId;
     this.direction = direction;
 }
Exemplo n.º 3
0
    void Action(Vector2 dir, bool attack)
    {
        if (attack && combatLimits.ready)
        {
            RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position,
                                                          data.abilities[rt.activeAbilityId].Last.Value.ability1_radius, rt.lastNonZeroMove,
                                                          data.abilities[rt.activeAbilityId].Last.Value.rangeLimit);
            //Debug.Log("Attempting atk "+hits.Length);
            BeginNewAbility(hits);

            //player specific reset. otherwise space only hold one frame

            /*if (!data.ai) {
             *  rt.shouldAttack = false;
             * }*/
        }

        if (data.ai)
        {
            if (rt.isMoving && rt.isStunned == 0)
            {
                // add move into combat processor too?
                GameManager.instance.combatProcessor.Add(
                    new CombatAction(CombatActionId.FixedUpdate_MoveByDirection, this, null, -1, rt.move * data.moveSpeed * Time.fixedDeltaTime));
            }
            else
            {
                GameManager.instance.combatProcessor.Add(
                    new CombatAction(CombatActionId.FixedUpdate_MoveByDirection, this, null, -1, Vector2.zero));
            }
        }
        if (!data.ai)
        {
            if (rt.rallyingCall)
            {
                if (rt.activeFollower)
                {
                    rt.DetachFollower();
                }
                else
                {
                    Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, data.rallyRange);
                    for (int i = 0; i < colliders.Length; i++)
                    {
                        Character01 c = colliders[i].GetComponent <Character01>();
                        if (c.IsAlly(this))
                        {
                            c.AttachAsFollowerTo(this);
                            break;
                        }
                    }
                    rt.rallyingCall = false;
                }
            }
        }
    }
Exemplo n.º 4
0
 // experimental - cycle 2
 /// <summary>
 /// Saves last ability for later use.
 /// </summary>
 /// <param name="character"></param>
 /// <param name="data"></param>
 /// <param name="action"></param>
 /// <returns></returns>
 public bool RecordAbilityHit(Character01 character, LinkedList <AbilityData> data, CombatAction action)
 {
     if (character == null || data == null)
     {
         Debug.Log("Null data."); return(false);
     }
     Debug.Log("Actitivating ability on character. against target. " + character.name + "; " + data.Last.Value.abilityName + "; " + action.target.name);
     lastAbilityCycle = character.StartCoroutine(character.AbilityCycle(data, action));
     return(true);
 }
Exemplo n.º 5
0
    private void ExecApproachTillDistAI(int alliance)
    {
        rt.rallyingCall = false;
        rt.shouldAttack = false;
        rt.move         = Vector2.zero;
        rt.isMoving     = true;

        // select unit to attack
        Vector2     targetPos  = transform.position;// find ally
        Character01 unitTarget = null;

        if (rt.following)
        {
            targetPos = rt.following.transform.position;// find ally
        }
        else
        {
            unitTarget = GameAI.FindUnit(transform.position, this,
                                         (source, target) => target.data.alliance != source.data.alliance);
            if (unitTarget != null)
            {
                rt.target = unitTarget.transform;
                targetPos = unitTarget.transform.position;// find ally
            }
        }
        // AI
        rt.move = targetPos - (Vector2)transform.position;

        if (rt.following == null)
        {
            CheckForAbility(targetPos, data.abilities[0].Last.Value);
        }
        else
        {
            NonOffensiveAbility(targetPos, data.followAllyAbility);
        }

        rt.lastNonZeroMove = rt.move;
    }
Exemplo n.º 6
0
    private void BeginNewAbility(RaycastHit2D[] hits)
    {
        // pick ability based on current combo
        if (rt.lastAbility != null)
        {
            rt.activeAbilityId = data.GetNextAbility(rt.lastAbility);
        }

        // note: currently combat actions support 1 ability activation per target.
        rt.lastAbility = data.abilities[rt.activeAbilityId];
        Debug.Log("Attacking with ability: " + rt.lastAbility.Last.Value.abilityName + " " + rt.lastAbility.Last.Value.abilityTag + " " + hits.Length);
        for (int i = 0; i < hits.Length; i++)
        {
            if (hits[i].transform.root != transform.root)   // rebuild combat adding pipeline
            {
                Character01 target = hits[i].transform.GetComponent <Character01>();

                rt.RecordAbilityHit(this, data.abilities[rt.activeAbilityId],
                                    new CombatAction(CombatActionId.DamageAttempt_CastCollision, this,
                                                     target, rt.activeAbilityId, Vector3.zero));
            }
        }
        combatLimits.ready = false;
    }
Exemplo n.º 7
0
 public CombatAction(Character01 source, Character01 target)
 {
     this.source = source;
     this.target = target;
 }
Exemplo n.º 8
0
 public static void DestroyUnit(Character01 unit)
 {
     Instance.Units.Remove(unit);
 }
Exemplo n.º 9
0
 public static void RegisterUnit(Character01 unit)
 {
     Instance.Units.Add(unit);
 }
Exemplo n.º 10
0
 // from follower
 public void DetachFromTarget()
 {
     following.rt.activeFollower = null;
     following = null;
 }
Exemplo n.º 11
0
 // from target
 public void DetachFollower()
 {
     activeFollower.rt.following = null;
     activeFollower = null;
 }
Exemplo n.º 12
0
 public bool IsEnemy(Character01 character01)
 {
     return(data.alliance != character01.data.alliance);
 }
Exemplo n.º 13
0
 public bool IsAlly(Character01 character01)
 {
     return(data.alliance == character01.data.alliance && character01 != this);
 }
Exemplo n.º 14
0
 // from follower
 public void AttachAsFollowerTo(Character01 target)
 {
     target.rt.activeFollower = this;
     rt.following             = target;
 }