Esempio n. 1
0
    private List <UnitBehavior> GetSusceptibleUnits()
    {
        List <UnitBehavior> ret = new List <UnitBehavior>();
        bool isplayer           = (self.GetComponent <PlayerBehaviour>() != null);
        bool isenemy            = (self.GetComponent <EnemyBehaviour>() != null);

        foreach (UnitBehavior o in BCS.GetAliveCombatants())
        {
            if (o == self)
            {
                continue;
            }
            if (isplayer)
            {
                if (o.transform.GetComponent <PlayerBehaviour>() == null)
                {
                    ret.Add(o);
                }
            }
            else if (isenemy)
            {
                if (o.transform.GetComponent <EnemyBehaviour>() == null)
                {
                    ret.Add(o);
                }
            }
        }
        //Debug.Log("Giving " + ret.Count + " combatants back from GetSusceptibleUnits");
        return(ret);
    }
    //expected to be a turn update
    public void BasicAttackUpdate()
    {
        Turn X = MyUnit.GetCombatActionQueue()[0];

        //model.transform.forward = direction;
        X.direction = (player.transform.position - MyUnit.transform.position).normalized * 1.5f;
        MyUnit.transform.forward = X.direction;
        //todo produce a fireball unitbehavior that moves to TargetLocator's position after say 40 frames
        //Debug.Log("procced =: " + X.HasProcced);
        if (!X.HasProcced)
        {
            //test to see if we dont hit the player.
            if (X.CurrentTime - X.StartTime > X.ProcTime)
            {
                bool hit = true;
                //determine distance/angle
                Vector3 diff = player.transform.position - MyUnit.transform.position;
                // short if distance is too great.
                if (diff.magnitude > 1.5f)
                {
                    X.HasProcced = true;
                    hit          = false;
                }
                else
                {
                    float L = MyUnit.transform.GetComponent <CapsuleCollider>().radius;
                    float H = L * 2;
                    Ray   r = new Ray(MyUnit.transform.position, X.direction.normalized);
                    float o = Vector3.Cross(r.direction, diff).magnitude;
                    // Hit this unit if inside hitbox influence;
                    if ((o - player.GetComponent <SphereCollider>().radius) > L + (H - L) * (diff.magnitude / X.ran))
                    {
                        hit = false;
                    }
                    Debug.Log("Hit is: " + hit);
                }

                X.HasProcced = true;
                if (hit)
                {
                    player.DamageHealth(MyUnit.GetSkill("basicattack"));
                }
            }
        }
    }