// Use this for initialization
    void Start()
    {
        LocationDetector detector          = GetComponent <LocationDetector>();
        Vector3          newTargetLocation = detector.targetLocation;

        newTargetLocation      += getRandomPositionInCircle();
        newTargetLocation       = new Vector3(newTargetLocation.x, getY(newTargetLocation), newTargetLocation.z);
        detector.targetLocation = newTargetLocation;
    }
Beispiel #2
0
 // Use this for initialization
 void Start()
 {
     baseLocalScaleZ = transform.localScale.z;
     detector        = GetComponentInParent <LocationDetector>();
     if (detector)
     {
         startLocation = detector.startLocation;
     }
 }
Beispiel #3
0
    public void Start()
    {
        if (!active)
        {
            return;
        }
        //if the aiming method requires a component that is not present do not use it
        if (aimingMethod == AimingMethod.TargetDirection && !GetComponent <LocationDetector>())
        {
            aimingMethod = AimingMethod.Random;
        }
        if (aimingMethod == AimingMethod.TravelDirection && !GetComponent <AbilityMover>())
        {
            aimingMethod = AimingMethod.Random;
        }

        Vector3 startPos = transform.position;

        if (createAtTarget)
        {
            LocationDetector ld = GetComponent <LocationDetector>();
            if (ld)
            {
                startPos = ld.targetLocation;
            }
        }
        else if (createAtStartLocation)
        {
            LocationDetector ld = GetComponent <LocationDetector>();
            if (ld)
            {
                startPos = ld.startLocation;
            }
        }


        startPos += offset;

        // create the ability object depending on the aiming method
        if (aimingMethod == AimingMethod.Random)
        {
            // create a random aim point
            Vector3 aimPoint = new Vector3(startPos.x + Random.Range(-5f, 5f), startPos.y, startPos.z + Random.Range(-5f, 5f));
            // create the ability object
            GetComponent <AbilityObjectConstructor>().constructAbilityObject(abilityToInstantiate, startPos, aimPoint);
        }
        else if (aimingMethod == AimingMethod.TargetDirection)
        {
            // create the ability object
            GetComponent <AbilityObjectConstructor>().constructAbilityObject(abilityToInstantiate, startPos, GetComponent <LocationDetector>().targetLocation);
        }
        else if (aimingMethod == AimingMethod.TravelDirection)
        {
            // create the ability object
            GetComponent <AbilityObjectConstructor>().constructAbilityObject(abilityToInstantiate, startPos, transform.position + GetComponent <AbilityMover>().positionDelta);
        }
    }
 // Use this for initialization
 void Start()
 {
     // get references
     mover            = GetComponent <AbilityMover>();
     locationDetector = GetComponent <LocationDetector>();
     // set the current direction to the start direction
     currentDirection = locationDetector.targetLocation - locationDetector.startLocation;
     // randomise at start
     if (timeToRandomise == TimeToRandomise.Start)
     {
         randomiseDirection(maximumAngleChange);
     }
     // prepare to randomise initialy if using direction mode
     index = directionChangeInterval;
 }
Beispiel #5
0
    // Use this for initialization
    void Start()
    {
        abilityMover = GetComponent <AbilityMover>();

        locationDetector = GetComponent <LocationDetector>();
        AlignmentManager alignmentManager = GetComponent <AlignmentManager>();

        if (locationDetector && alignmentManager)
        {
            Alignment alignment = alignmentManager.alignment;
            if (alignment)
            {
                List <Transform> possibleTargets = new List <Transform>();
                foreach (BaseHealth health in BaseHealth.all)
                {
                    if (health.alignmentManager && alignment.foes.Contains(health.alignmentManager.alignment) && health.currentHealth > 0)
                    {
                        possibleTargets.Add(health.transform);
                    }
                }

                Vector3 position = locationDetector.targetLocation;
                targetPosition = position;
                float distance       = 0f;
                float targetDistance = 0f;

                foreach (Transform possibleTarget in possibleTargets)
                {
                    distance       = Vector3.Distance(position, possibleTarget.position);
                    targetDistance = Vector3.Distance(position, targetPosition);
                    if ((target == null || distance < targetDistance) && distance < maxDistanceFromTarget)
                    {
                        targetPosition = possibleTarget.position;
                        target         = possibleTarget;
                    }
                }

                if (target)
                {
                    targetGo = target.gameObject;
                }
            }
        }
    }
Beispiel #6
0
 public static void copy(LocationDetector to, LocationDetector from)
 {
     to.startLocation        = from.startLocation;
     to.targetLocationOffset = from.targetLocationOffset;
     to.targetLocation       = from.targetLocation - from.targetLocationOffset;
 }
Beispiel #7
0
    public GameObject constructAbilityObject(Ability ability, Vector3 location, Vector3 targetLocation, GameObject overridePrefab = null, bool InheritSharedHitDetector = true)
    {
        // create the ability object
        GameObject abilityObject = null;

        if (overridePrefab == null)
        {
            // if there is no override prefab instantiate the ability's ability prefab
            abilityObject = Instantiate(ability.abilityPrefab, location, Quaternion.Euler(targetLocation - location));
        }
        else // othewise instrantiate the override prefab
        {
            abilityObject = Instantiate(overridePrefab, location, Quaternion.Euler(targetLocation - location));
        }

        // apply the relevant mutator if this entity has one
        if (mutatorManager)
        {
            mutators = mutatorManager.getMutators(ability);
            if (mutators != null)
            {
                foreach (AbilityMutator mutator in mutators)
                {
                    abilityObject = mutator.Mutate(abilityObject, location, targetLocation);
                    if (mutator.changeLocation)
                    {
                        targetLocation = mutator.newLocation;
                    }
                    if (mutator.changeTargetLocation)
                    {
                        targetLocation = mutator.newTargetLocation;
                    }
                }
            }
        }

        // move the ability object if necessary
        foreach (DefineStartLocation defineStartLocation in abilityObject.GetComponents <DefineStartLocation>())
        {
            if (defineStartLocation.active)
            {
                defineStartLocation.setLocation(location, targetLocation);
                // the direction from the cast point needs to be maintained
                if (defineStartLocation.maintainDirectionFromCastPoint())
                {
                    targetLocation = abilityObject.transform.position + targetLocation - location;
                }
            }
        }


        // initialise a location detector if necessary
        LocationDetector locationDetector = abilityObject.GetComponent <LocationDetector>();

        if (locationDetector)
        {
            locationDetector.startLocation  = abilityObject.transform.position;
            locationDetector.targetLocation = targetLocation;
        }

        // rotate the ability object
        abilityObject.transform.LookAt(targetLocation);

        // give the ability object its alignment
        AlignmentManager abilityAlignmentManager = abilityObject.GetComponent <AlignmentManager>();

        if (!abilityAlignmentManager)
        {
            abilityAlignmentManager = abilityObject.AddComponent <AlignmentManager>();
        }
        abilityAlignmentManager.alignment = myAlignmentManager.alignment;

        // give the ability object its creation references
        CreationReferences abilityCreationReferences = abilityObject.GetComponent <CreationReferences>();

        if (!abilityCreationReferences)
        {
            abilityCreationReferences = abilityObject.AddComponent <CreationReferences>();
        }
        abilityCreationReferences.thisAbility         = ability;
        abilityCreationReferences.locationCreatedFrom = location;
        // if this an ability object then the creator is this objects creator, otherwise the creator is this object
        if (myCreationReferences && GetComponent <AbilityObjectIndicator>())
        {
            abilityCreationReferences.creator = myCreationReferences.creator;
        }
        else
        {
            abilityCreationReferences.creator = gameObject;
        }

        // check whether there should be a shared hit detector
        HitDetector abilityHitDetector = abilityObject.GetComponent <HitDetector>();

        if (abilityHitDetector)
        {
            SharedHitDetector sharedHitDetector = null;
            if (myHitDetector && myHitDetector.sharedHitDetector && InheritSharedHitDetector)
            {
                sharedHitDetector = myHitDetector.sharedHitDetector;
            }
            // create a shared hit detector
            else if (ability.sharedHitDetector)
            {
                GameObject newGameObject = new GameObject();
                sharedHitDetector = newGameObject.AddComponent <SharedHitDetector>();
                sharedHitDetector.gameObject.AddComponent <SelfDestroyer>();
                sharedHitDetector.name = abilityObject.name + "'s shared hit detector";
            }
            if (sharedHitDetector != null && !abilityHitDetector.cannotHaveSharedhitDetector)
            {
                abilityHitDetector.sharedHitDetector = sharedHitDetector;
            }
        }

        // build the damage stats for each damage stats holder
        foreach (DamageStatsHolder damageStatsHolder in abilityObject.GetComponents <DamageStatsHolder>())
        {
            damageStatsHolder.damageStats = DamageStats.buildDamageStats(damageStatsHolder, GetComponent <TaggedStatsHolder>());
        }

        // attach any on hit status appliers if this ability deals damage on hit
        if (myTaggedStatsHolder && abilityObject.GetComponent <DamageEnemyOnHit>() && !abilityObject.GetComponent <CannotApplyAdditionalStatuses>())
        {
            ChanceToApplyStatusOnEnemyHit applier;
            float poisonChance = myTaggedStatsHolder.GetStatValue(Tags.Properties.PoisonChance, ability.useTags);
            if (poisonChance > 0)
            {
                applier = abilityObject.AddComponent <ChanceToApplyStatusOnEnemyHit>();
                applier.statusEffect             = StatusEffectList.getEffect(StatusEffectID.Poison);
                applier.chance                   = poisonChance;
                applier.canApplyToSameEnemyAgain = false;
            }
            float igniteChance = myTaggedStatsHolder.GetStatValue(Tags.Properties.IgniteChance, ability.useTags);
            if (igniteChance > 0)
            {
                applier = abilityObject.AddComponent <ChanceToApplyStatusOnEnemyHit>();
                applier.statusEffect             = StatusEffectList.getEffect(StatusEffectID.Ignite);
                applier.chance                   = igniteChance;
                applier.canApplyToSameEnemyAgain = false;
            }
            float chillChance = myTaggedStatsHolder.GetStatValue(Tags.Properties.ChillChance, ability.useTags);
            if (chillChance > 0)
            {
                applier = abilityObject.AddComponent <ChanceToApplyStatusOnEnemyHit>();
                applier.statusEffect             = StatusEffectList.getEffect(StatusEffectID.Chill);
                applier.chance                   = chillChance;
                applier.canApplyToSameEnemyAgain = false;
            }
            float slowChance = myTaggedStatsHolder.GetStatValue(Tags.Properties.SlowChance, ability.useTags);
            if (slowChance > 0)
            {
                applier = abilityObject.AddComponent <ChanceToApplyStatusOnEnemyHit>();
                applier.statusEffect             = StatusEffectList.getEffect(StatusEffectID.Slow);
                applier.chance                   = slowChance;
                applier.canApplyToSameEnemyAgain = false;
            }
            float blindChance = myTaggedStatsHolder.GetStatValue(Tags.Properties.BlindChance, ability.useTags);
            if (blindChance > 0)
            {
                applier = abilityObject.AddComponent <ChanceToApplyStatusOnEnemyHit>();
                applier.statusEffect             = StatusEffectList.getEffect(StatusEffectID.Blind);
                applier.chance                   = blindChance;
                applier.canApplyToSameEnemyAgain = false;
            }

            float bleedChance = myTaggedStatsHolder.GetStatValue(Tags.Properties.BleedChance, ability.useTags);
            if (bleedChance > 0)
            {
                applier = abilityObject.AddComponent <ChanceToApplyStatusOnEnemyHit>();
                applier.statusEffect             = StatusEffectList.getEffect(StatusEffectID.Bleed);
                applier.chance                   = bleedChance;
                applier.canApplyToSameEnemyAgain = false;
            }
            float shockChance = myTaggedStatsHolder.GetStatValue(Tags.Properties.ShockChance, ability.useTags);
            if (shockChance > 0)
            {
                applier = abilityObject.AddComponent <ChanceToApplyStatusOnEnemyHit>();
                applier.statusEffect             = StatusEffectList.getEffect(StatusEffectID.Shock);
                applier.chance                   = shockChance;
                applier.canApplyToSameEnemyAgain = false;
            }
        }


        // if the ability has an ability object constructor give it a tagged stats holder with your tagged stats
        if (myTaggedStatsHolder && abilityObject.GetComponent <RequiresTaggedStats>())
        {
            TaggedStatsHolder holder = abilityObject.GetComponent <TaggedStatsHolder>();
            if (holder == null)
            {
                holder = abilityObject.AddComponent <TaggedStatsHolder>();
            }
            holder.simpleStats.AddRange(myTaggedStatsHolder.simpleStats);
            holder.taggedStats.AddRange(myTaggedStatsHolder.taggedStats);
        }

        // set the direction if there is an ability mover
        if (abilityObject.GetComponent <AbilityMover>())
        {
            abilityObject.GetComponent <AbilityMover>().positionDelta = Vector3.Normalize(targetLocation - location);
            // if the ability object defines its own start direction then let it
            if (abilityObject.GetComponent <DefineStartDirection>())
            {
                abilityObject.GetComponent <DefineStartDirection>().setDirection();
            }
        }

        // run any on creation methods
        foreach (OnCreation component in abilityObject.GetComponents <OnCreation>())
        {
            if (component.runOnCreation)
            {
                component.onCreation();
            }
        }

        // invoke the event
        if (abilityObjectCreatedEvent != null)
        {
            abilityObjectCreatedEvent.Invoke(ability, abilityObject);
        }

        return(abilityObject);
    }
    public void createAbilityObject()
    {
        if (failsIfFailedAbility)
        {
            SelfDestroyer destroyer = GetComponent <SelfDestroyer>();
            if (destroyer && destroyer.failedAbility)
            {
                return;
            }
        }

        //if the aiming method requires a component that is not present do not use it
        if (aimingMethod == AimingMethod.TargetDirection && !GetComponent <LocationDetector>())
        {
            aimingMethod = AimingMethod.Random;
        }
        if (aimingMethod == AimingMethod.TravelDirection && !GetComponent <AbilityMover>())
        {
            aimingMethod = AimingMethod.Random;
        }

        Vector3 startPos = transform.position;

        if (createAtTarget)
        {
            LocationDetector ld = GetComponent <LocationDetector>();
            if (ld)
            {
                startPos = ld.targetLocation;
            }
        }
        else if (createAtStartLocation)
        {
            LocationDetector ld = GetComponent <LocationDetector>();
            if (ld)
            {
                startPos = ld.startLocation;
            }
        }
        else if (createAtCastLocation)
        {
            CreationReferences references = GetComponent <CreationReferences>();
            if (references)
            {
                startPos = references.locationCreatedFrom;
            }
        }


        startPos += offset;

        // create the ability object depending on the aiming method
        if (aimingMethod == AimingMethod.Random)
        {
            // create a random aim point
            Vector3 aimPoint = new Vector3(startPos.x + Random.Range(-5f, 5f), startPos.y, startPos.z + Random.Range(-5f, 5f));
            // create the ability object
            GetComponent <AbilityObjectConstructor>().constructAbilityObject(abilityToInstantiate, startPos, aimPoint);
        }
        else if (aimingMethod == AimingMethod.TargetDirection)
        {
            // create the ability object
            GetComponent <AbilityObjectConstructor>().constructAbilityObject(abilityToInstantiate, startPos, GetComponent <LocationDetector>().targetLocation);
        }
        else if (aimingMethod == AimingMethod.TravelDirection)
        {
            // create the ability object
            GetComponent <AbilityObjectConstructor>().constructAbilityObject(abilityToInstantiate, startPos, transform.position + GetComponent <AbilityMover>().positionDelta);
        }
    }
Beispiel #9
0
 // Use this for initialization
 void Start()
 {
     mover            = GetComponent <AbilityMover>();
     detector         = GetComponent <LocationDetector>();
     previousPosition = transform.position;
 }
Beispiel #10
0
    public void createObjects()
    {
        objectsToCreateOnDeath.RemoveAll(x => x.gameObject == null);
        Transform  caster = null;
        GameObject go     = null;

        if (attachToCaster)
        {
            CreationReferences references = GetComponent <CreationReferences>();
            if (references && references.creator)
            {
                caster = GetComponent <CreationReferences>().creator.transform;
            }
        }
        if (rotationToPassOn == RotationToPassOn.Own)
        {
            foreach (GameObjectHolder holder in objectsToCreateOnDeath)
            {
                go = Instantiate(holder.gameObject, transform.position, transform.rotation);
                if (caster)
                {
                    go.transform.parent = caster; go.transform.localPosition = new Vector3(0, 0, 0);
                }
            }
        }
        else if (rotationToPassOn == RotationToPassOn.Parent && transform.parent)
        {
            foreach (GameObjectHolder holder in objectsToCreateOnDeath)
            {
                go = Instantiate(holder.gameObject, transform.position, transform.parent.transform.rotation);
                if (caster)
                {
                    go.transform.parent = caster; go.transform.localPosition = new Vector3(0, 0, 0);
                }
            }
        }
        else
        {
            foreach (GameObjectHolder holder in objectsToCreateOnDeath)
            {
                go = Instantiate(holder.gameObject, transform.position, Quaternion.identity);
                if (caster)
                {
                    go.transform.parent = caster; go.transform.localPosition = new Vector3(0, 0, 0);
                }
            }
        }

        if (go && passOnLocationDetector)
        {
            LocationDetector detector = GetComponent <LocationDetector>();
            if (detector)
            {
                LocationDetector newDetector = go.GetComponent <LocationDetector>();
                if (!newDetector)
                {
                    newDetector = go.AddComponent <LocationDetector>();
                }
                LocationDetector.copy(newDetector, detector);
            }
        }
        if (go && passOnCreationReferences)
        {
            CreationReferences references = GetComponent <CreationReferences>();
            if (references)
            {
                CreationReferences newReferences = go.GetComponent <CreationReferences>();
                if (!newReferences)
                {
                    newReferences = go.AddComponent <CreationReferences>();
                }
                references.copyTo(newReferences);
            }
        }
        // apply increases to radius and height
        if (increasedRadius != 0 || increasedHeight != 0)
        {
            go.transform.localScale = new Vector3(go.transform.localScale.x * (1 + increasedRadius), go.transform.localScale.y * (1 + increasedHeight), go.transform.localScale.z * (1 + increasedRadius));
        }
    }
Beispiel #11
0
 // Use this for initialization
 void Start()
 {
     locationDetector = GetComponent <LocationDetector>();
 }