Ejemplo n.º 1
0
    public void onNewSummon(Summoned summon)
    {
        // subscribe to the death events of skeletal minions
        if (summon && summon.references && summon.references.thisAbility)
        {
            if (summon.references.thisAbility == ability || summon.references.thisAbility == summonWarrior || summon.references.thisAbility == summonMage ||
                summon.references.thisAbility == summonArcher || summon.references.thisAbility == summonWarlord || summon.references.thisAbility == summonBrawler)
            {
                Dying dying = summon.GetComponent <Dying>();
                if (!dying)
                {
                    Debug.LogError(summon.name + " does not have a Dying component yet, fix this script please"); return;
                }

                dying.deathEvent += OnSkeletonDeath;
            }
        }
    }
Ejemplo n.º 2
0
    // Use this for initialization
    public override void onCreation()
    {
        bool success = false;

        CreationReferences references = GetComponent <CreationReferences>();

        if (!references || !references.creator)
        {
            if (destroyIfFailedToMove)
            {
                SelfDestroyer dest = Comp <SelfDestroyer> .GetOrAdd(gameObject);

                dest.failedAbility = true;
                dest.die();
            }
            return;
        }

        SummonTracker tracker = references.creator.GetComponent <SummonTracker>();

        if (!tracker)
        {
            if (destroyIfFailedToMove)
            {
                SelfDestroyer dest = Comp <SelfDestroyer> .GetOrAdd(gameObject);

                dest.failedAbility = true;
                dest.die();
            }
            return;
        }

        // find a lit of summon
        List <Summoned> summons = new List <Summoned>();

        foreach (Summoned summoned in tracker.summons)
        {
            if (summoned)
            {
                summons.Add(summoned);
            }
        }
        // remove inactive objects from the list
        for (int i = summons.Count - 1; i >= 0; i--)
        {
            if (!summons[i].gameObject.activeSelf)
            {
                summons.Remove(summons[i]);
            }
        }
        // remove dying objects from the list
        if (requiredLifeState == lifeState.alive)
        {
            for (int i = summons.Count - 1; i >= 0; i--)
            {
                if (summons[i].GetComponent <Dying>() != null)
                {
                    if (summons[i].GetComponent <StateController>().currentState == summons[i].GetComponent <StateController>().dying)
                    {
                        summons.Remove(summons[i]);
                    }
                }
            }
        }
        // or remove living objects from the list
        else if (requiredLifeState == lifeState.dead)
        {
            for (int i = summons.Count - 1; i >= 0; i--)
            {
                if (summons[i].GetComponent <Dying>() != null)
                {
                    if (summons[i].GetComponent <StateController>().currentState != summons[i].GetComponent <StateController>().dying)
                    {
                        summons.Remove(summons[i]);
                    }
                }
                else
                {
                    summons.Remove(summons[i]);
                }
            }
        }
        if (summons.Count == 0)
        {
            if (destroyIfFailedToMove)
            {
                SelfDestroyer dest = Comp <SelfDestroyer> .GetOrAdd(gameObject);

                dest.failedAbility = true;
                dest.die();
            }
            return;
        }
        else
        {
            // find the nearest summon
            Summoned nearest  = summons[0];
            float    distance = Vector3.Distance(transform.position, nearest.transform.position);
            foreach (Summoned summon in summons)
            {
                if (Vector3.Distance(transform.position, summon.transform.position) < distance)
                {
                    nearest  = summon;
                    distance = Vector3.Distance(transform.position, summon.transform.position);
                }
            }

            // move to the summon's location
            transform.position = nearest.transform.position;
            // change to the summon's rotation
            transform.rotation = nearest.transform.rotation;

            success = true;

            if (kill)
            {
                Dying dying = nearest.GetComponent <Dying>();

                if (dying)
                {
                    if (eraseCorpse)
                    {
                        dying.setDelays(0.01f, 0.02f);
                    }

                    dying.myHealth.HealthDamage(dying.myHealth.maxHealth * 200);
                }
            }
        }
        if (destroyIfFailedToMove && success == false)
        {
            SelfDestroyer dest = Comp <SelfDestroyer> .GetOrAdd(gameObject);

            dest.failedAbility = true;
            dest.die();
        }
    }
Ejemplo n.º 3
0
    public void Start()
    {
        CreationReferences references = GetComponent <CreationReferences>();

        if (references && references.creator)
        {
            SummonTracker summonTracker = references.creator.GetComponent <SummonTracker>();
            if (summonTracker)
            {
                List <Summoned> minionsToUse   = new List <Summoned>();
                List <Summoned> creatorMinions = summonTracker.summons;
                if (creatorMinions.Count > 0)
                {
                    // select minions
                    if (minionsToUseAbility == MinionUseType.Nearest)
                    {
                        Summoned selected         = creatorMinions[0];
                        float    selectedDistance = Vector3.Distance(transform.position, creatorMinions[0].transform.position);
                        float    distance         = 0;
                        foreach (Summoned minion in creatorMinions)
                        {
                            distance = Vector3.Distance(transform.position, minion.transform.position);
                            if (distance < selectedDistance && (!requiresCanUseMovementAbilities || minion.GetComponent <CanUseMovementAbilities>()))
                            {
                                selectedDistance = distance;
                                selected         = minion;
                            }
                        }
                        if (!requiresCanUseMovementAbilities || selected.GetComponent <CanUseMovementAbilities>())
                        {
                            minionsToUse.Add(selected);
                        }
                    }
                    else if (minionsToUseAbility == MinionUseType.Random)
                    {
                        int      attempts = 0;
                        Summoned selected = null;
                        while (attempts < 20)
                        {
                            selected = creatorMinions[Random.Range(0, creatorMinions.Count)];
                            if (!requiresCanUseMovementAbilities || selected.GetComponent <CanUseMovementAbilities>())
                            {
                                attempts = 100000;
                                minionsToUse.Add(selected);
                            }
                        }
                    }
                    else if (minionsToUseAbility == MinionUseType.All)
                    {
                        if (!requiresCanUseMovementAbilities)
                        {
                            minionsToUse.AddRange(creatorMinions);
                        }
                        else
                        {
                            foreach (Summoned minion in creatorMinions)
                            {
                                if (minion.GetComponent <CanUseMovementAbilities>())
                                {
                                    minionsToUse.Add(minion);
                                }
                            }
                        }
                    }
                    // make the minions use the ability
                    Vector3      targetPostion = GetComponent <LocationDetector>().targetLocation;
                    UsingAbility ua            = null;
                    foreach (Summoned minion in minionsToUse)
                    {
                        ua = minion.GetComponent <UsingAbility>();
                        if (ua)
                        {
                            ua.UseAbility(ability, targetPostion, false, false);
                            ua.transform.LookAt(targetPostion);
                        }
                    }
                }
            }
        }
    }