Exemple #1
0
    private static void AddHealth(AIController AI)
    {
        HealthDefence HP      = AI.GetComponentInParent <HealthDefence>();
        ModDisplay    display = AI.GetComponentInParent <ModDisplay>();

        HP.maxHP += (int)((float)HP.maxHP * .2f);
        if (HP.maxHP > HP.HP)
        {
            HP.HP = HP.maxHP;
        }
        if (display.Mods.Contains("\r\n Weak Health Bonus"))
        {
            display.Mods.Add("\r\n Moderate Health Bonus");
            display.Mods.Remove("\r\n Weak Health Bonus");
        }
        else if (display.Mods.Contains("\r\n Moderate Health Bonus"))
        {
            display.Mods.Add("\r\n Strong Health Bonus");
            display.Mods.Remove("\r\n Moderate Health Bonus");
        }
        else if (display.Mods.Contains("\r\n Strong Health Bonus"))
        {
            display.Mods.Add("\r\n Great Health Bonus");
            display.Mods.Remove("\r\n Strong Health Bonus");
        }
        else if (!display.Mods.Contains("\r\n Great Health Bonus"))
        {
            display.Mods.Add("\r\n Weak Health Bonus");
        }
    }
Exemple #2
0
    private static void AddMezmerizeResistance(AIController AI)
    {
        HealthDefence HP      = AI.GetComponentInParent <HealthDefence>();
        ModDisplay    display = AI.GetComponentInParent <ModDisplay>();

        if (HP.mezmerize_resistance < .03)
        {
            display.Mods.Add("\r\n Weak Mezmerize Resistance");
        }
        else if (HP.mezmerize_resistance < .06)
        {
            display.Mods.Add("\r\n Moderate Mezmerize Resistance");
            display.Mods.Remove("\r\n Weak Mezmerize Resistance");
        }
        else if (HP.mezmerize_resistance < .09)
        {
            display.Mods.Add("\r\n Strong Mezmerize Resistance");
            display.Mods.Remove("\r\n Moderate Mezmerize Resistance");
        }
        else if (HP.mezmerize_resistance < .12)
        {
            display.Mods.Add("\r\n Great Mezmerize Resistance");
            display.Mods.Remove("\r\n Strong Mezmerize Resistance");
        }
        HP.mezmerize_resistance += .03;
    }
Exemple #3
0
    private static void AddDefence(AIController AI)
    {
        HealthDefence HP      = AI.GetComponentInParent <HealthDefence>();
        ModDisplay    display = AI.GetComponentInParent <ModDisplay>();

        HP.defence += 1;
        if (display.Mods.Contains("\r\n Weak Defence Bonus"))
        {
            display.Mods.Add("\r\n Moderate Defence  Bonus");
            display.Mods.Remove("\r\n Weak Defence Bonus");
        }
        else if (display.Mods.Contains("\r\n Moderate Defence Bonus"))
        {
            display.Mods.Add("\r\n Strong Defence Bonus");
            display.Mods.Remove("\r\n Moderate Defence Bonus");
        }
        else if (display.Mods.Contains("\r\n Strong Defence Bonus"))
        {
            display.Mods.Add("\r\n Great Defence Bonus");
            display.Mods.Remove("\r\n Strong Defence Bonus");
        }
        else if (!display.Mods.Contains("\r\n Great Defence Bonus"))
        {
            display.Mods.Add("\r\n Weak Defence Bonus");
        }
    }
Exemple #4
0
        public override void UnitAggroReaction(Collider col)
        {
            HealthDefence target = col.gameObject.GetComponent <HealthDefence>();

            if (!target)
            {
                return;
            }

            /*Opponent Units will generate aggro based on their distance from this
             * unit.*/
            if (target is UnitHealthDefence)
            {
                Unit.UpdateAggro(10, target.netId, false);
                Unit.StartCoroutine(GenerateGradualDistanceBasedThreat(
                                        target,
                                        Unit.ptr.position,
                                        20));
            }

            /*Spawn Points will generate 20 aggro automatically upon entering
             * aggro radius,but only if they're not on the list beforehand*/
            if (target is SpawnPointHealthDefence)
            {
                if (!Array.Exists(Unit.HateList, delegate(ValueGroup v)
                {
                    return(v.index == (int)target.netId.Value);
                }))
                {
                    Unit.UpdateAggro(20, target.netId, false);
                }
            }
        }
Exemple #5
0
        public override void UnitAggroReaction(Collider col)
        {
            HealthDefence target = col.gameObject.GetComponentInParent <HealthDefence>();

            if (!target)
            {
                return;
            }

            /*Players will generate 100 aggro automatically upon entering
            *  aggro radius,but only if they're not on the list beforehand*/
            if (target is UnitHealthDefence)
            {
                if (!Array.Exists(Unit.HateList, delegate(ValueGroup v)
                {
                    return(v.index == (int)target.netId.Value);
                }))
                {
                    Unit.UpdateAggro(100, target.netId, false);
                }
            }

            /*A Spawn Point in the radius gradually gain threat at a rate of
             * 10 units per second*/
            else if (target is SpawnPointHealthDefence)
            {
                Unit.StartCoroutine(GenerateGradualThreat(target, target.netId, 20));
            }
        }
Exemple #6
0
    private static void AddExp(AIController AI)
    {
        HealthDefence HP      = AI.GetComponentInParent <HealthDefence>();
        ModDisplay    display = AI.GetComponentInParent <ModDisplay>();

        HP.exp_rate += .1f;
        if (display.Mods.Contains("\r\n Weak Experience Bonus"))
        {
            display.Mods.Add("\r\n Moderate Experience Bonus");
            display.Mods.Remove("\r\n Weak Experience Bonus");
        }
        else if (display.Mods.Contains("\r\n Moderate Experience Bonus"))
        {
            display.Mods.Add("\r\n Strong Experience Bonus");
            display.Mods.Remove("\r\n Moderate Experience Bonus");
        }
        else if (display.Mods.Contains("\r\n Strong Experience Bonus"))
        {
            display.Mods.Add("\r\n Great Experience Bonus");
            display.Mods.Remove("\r\n Strong Experience Bonus");
        }
        else if (!display.Mods.Contains("\r\n Great Experience Bonus"))
        {
            display.Mods.Add("\r\n Weak Experience Bonus");
        }
    }
Exemple #7
0
    private static IEnumerator Quake(Gun gun, BulletScript script)
    {
        script.coroutines_running++;
        while (!script.has_collided && !script.Target)//Wait for collision and check target validity
        {
            yield return(new WaitForEndOfFrame());
        }
        string layer = "";

        if (gun.client_user)
        {
            layer = LayerMask.LayerToName(
                gun.client_user.gameObject.layer);
        }
        else
        {
            layer = LayerMask.LayerToName(
                gun.GetComponentInParent <HealthDefence>()
                .gameObject.layer);
        }
        Collider[] target_colliders = Physics.OverlapSphere(script.gameObject.transform.position, 7,
                                                            LayerMask.GetMask(layer), QueryTriggerInteraction.Collide);
        foreach (Collider col in target_colliders)
        {
            HealthDefence HP = col.GetComponent <HealthDefence>();
            if (HP && script.Target.netId != HP.netId)
            {
                int d = rand.Next(script.lower_bound_damage, script.upper_bound_damage) / 2;
                HP.RpcDisplayHPChange(Color.red, d);
                HP.HP -= d;
            }
        }
        script.coroutines_running--;
    }
Exemple #8
0
    // Use this for initialization

    void Awake()
    {
        SpawnTeamList.Add(AllySpawnPoints);
        SpawnTeamList.Add(EnemySpawnPoints);
        SpawnTeamList.Add(EnemySpawnPoints2);
        SpawnTeamList.Add(EnemySpawnPoints3);
        SpawnTeamList.Add(EnemySpawnPoints4);
        HP = GetComponent <HealthDefence>();
        TotalSpawnPoints.Add(this);
    }
Exemple #9
0
        /*PLayers/Spawns within radius are given more priority
         * than those outside.*/
        public override void UnitAggroReaction(Collider col)
        {
            HealthDefence target = col.gameObject.GetComponent <HealthDefence>();

            ///Debug.Log("Aggro Reaction : " + col);
            Unit.UpdateAggro(10, target.netId, false);
            Unit.StartCoroutine(GenerateGradualDistanceBasedThreat(
                                    target,
                                    guard_point,
                                    50));
        }
Exemple #10
0
    /*Deals with the process of death and respawn*/
    public static IEnumerator WaitForRespawn(HealthDefence killed)
    {
        int ORIGINAL_LAYER = killed.gameObject.layer;
        List <SpawnManager> team_spawns = GetTeamSpawns(ORIGINAL_LAYER);

        NetworkMethods.Instance.CmdSetLayer(killed.gameObject, LayerMask.NameToLayer("Invincible"));
        TotalSpawnPoints[0].RpcDisableScripts(killed.gameObject);

        AIController AI = killed.GetComponentInChildren <AIController>();

        if (AI)
        {
            yield return(new WaitForSeconds(cpu_respawn_time));
        }
        else
        {
            PlayersAlive.Instance.Players.Remove(killed.netId.Value);
            TotalSpawnPoints[0].RpcInterface(killed.netId);
            yield return(new WaitForSeconds(ally_respawn_time));
        }

        while (team_spawns.Count < 1)
        {
            yield return(new WaitForEndOfFrame());
        }

        TotalSpawnPoints[0].RpcEnableScripts(killed.gameObject);
        NetworkMethods.Instance.RpcBlink(killed.gameObject, 1.5f);
        NetworkMethods.Instance.CmdSetLayer(killed.gameObject, ORIGINAL_LAYER);
        if (AI)
        {
            killed.gameObject.transform.position = team_spawns[0].transform.position
                                                   + team_spawns[0].spawn_direction;
            while (killed.gameObject.layer != ORIGINAL_LAYER)
            {
                yield return(new WaitForEndOfFrame());
            }
            AI.ResetHateList();
        }
        else
        {
            PlayersAlive.Instance.Players.Add(killed.netId.Value);
            while (RespawnInterface.Instance.respawning)
            {
                yield return(new WaitForEndOfFrame());
            }
            int index = RespawnInterface.Instance.spawn_index;
            killed.gameObject.transform.position = team_spawns[index].transform.position
                                                   + team_spawns[index].spawn_direction;
        }
        killed.HP = killed.maxHP;
    }
Exemple #11
0
 protected virtual IEnumerator GenerateGradualThreat(HealthDefence target, NetworkInstanceId ID, int amount = 5)
 {
     /*Interestingly enough,Unity records that the distance is actually GREATER than the actual radius
      * whenever spawns enter the radius.Hence,w/o a subtraction of atleast ~.6f,the coroutine will never
      * really function how it's supposed to.*/
     while (AffirmTarget(target) &&
            Vector3.Distance(Unit.ptr.position, target.transform.position) - .75f
            < Unit.enemy_attack_detection.radius)
     {
         Unit.UpdateAggro(amount, ID, false);
         yield return(new WaitForSeconds(1));
     }
 }
Exemple #12
0
 /*Generate target's threat towards this unit each second based on their distance from the unit,
  * provided that the target is within aggro radius.The closer a target is,the more aggro
  * is generated.*/
 protected IEnumerator GenerateGradualDistanceBasedThreat(HealthDefence target, Vector3 pos, float multiplier)
 {
     //Debug.Log("Generating dist aggro...");
     while (AffirmTarget(target) &&
            Math.Abs(
                Vector3.Distance(pos, target.transform.position)) - .75f
            < Unit.enemy_attack_detection.radius)
     {
         float dist = Math.Abs(
             Vector3.Distance(pos, target.transform.position));
         float new_amount = Unit.enemy_attack_detection.radius / dist * multiplier;
         // Debug.Log((int)new_amount);
         Unit.UpdateAggro((int)new_amount, target.netId, false);
         yield return(new WaitForSeconds(1));
     }
 }
Exemple #13
0
    /*returns damage based on random rolls, the boundaries of damage set
     * by lower-bound_damage and upper_bound_damage fields,Target defence, and gun abilities
     * which can affect those fields.Also returns whether it crit or not. */
    ValueGroup <bool, int> GetDamage(HealthDefence Target)
    {
        int   damage = rand.Next(lower_bound_damage, upper_bound_damage);
        float da     = (100 - Target.defence);

        da /= 100;
        int  d    = (int)((float)damage * da);
        bool crit = false;

        if ((crit_chance - Target.crit_resistance)
            >= rand.NextDouble() + .001)//bullets with a crit chance of 0 shouldn't be able to land a crit
        {
            crit = true;
            d   *= 3;
        }
        return(new ValueGroup <bool, int>(crit, d));
    }
Exemple #14
0
        public override void UnitAggroReaction(Collider col)
        {
            HealthDefence target = col.gameObject.GetComponent <HealthDefence>();

            if (target is SpawnPointHealthDefence)
            {
                /*SpawnPoints will generate 200 aggro automatically upon entering
                 * aggro radius,but only if they're not on the list beforehand*/
                if (!Array.Exists(Unit.HateList, delegate(ValueGroup v)
                {
                    return(v.index == (int)target.netId.Value);
                }))
                {
                    Unit.UpdateAggro(200, target.netId, false);
                }
            }
        }
Exemple #15
0
        public bool AffirmTarget(HealthDefence Target)
        {
            bool result;

            /*Checks whether object still exists.Note in UpdateAggro(),the
             * info is erased only if it is chosen/kept as the current target.
             * In the function,the netId of the object to remove is
             * determined.*/
            if (!Target)
            {
                idle_count++;
                Unit.UpdateAggro();
                result = false;
            }

            /*Also check if object is on the same team or has no HP left.
             * In this case,remove their aggro from the list.*/
            else if (Target.gameObject.layer == Unit.ptr.gameObject.layer ||
                     Target.HP <= 0)
            {
                idle_count++;
                Unit.RemoveAggro(Target.netId);
                result = false;
            }
            else
            {
                idle_count = 0;
                result     = true;
            }

            /*Prevents idling if there is a desireable target not within the hatelist
             * while the hatelist has no suitable targets.*/
            if (idle_count >= Unit.HateList.Length)
            {
                ResetHateList();
            }
            return(result);
        }
Exemple #16
0
    public void UpdateAggro(int damage = 0, NetworkInstanceId player_id = new NetworkInstanceId(), bool account_attack_dist = true)
    {
        if (damage != 0)
        {
            //Debug.Log("Aggro Called");
            float     dist_multiplier = 1;
            Transform playertr        = NetworkServer.FindLocalObject(player_id).transform;
            if (account_attack_dist && Target)
            {
                /*The closer the player is to the enemy the more threat generated from
                 * the respective attack done by the player*/
                float dist_ratio = enemy_attack_detection.radius /
                                   Vector3.Distance(Target.transform.position, ptr.position);
                /*The distance only has 25% bearing on the threat,however.*/
                dist_multiplier = .75f + .25f * (dist_ratio);
            }

            /*If the player is not currently on the enemy's hatelist...
             * (netIds are used as ValueGroup indeces)*/
            if (!Array.Exists(HateList, delegate(ValueGroup g)
            {
                return(g.index == (int)(player_id.Value));
            }))
            {
                /*Find the first empty slot to store threat info
                 * in*/
                int index = Array.FindIndex(HateList, delegate(ValueGroup g)
                {
                    return(g.value == -1);
                });
                //Debug.Log(index);
                HateList[index] = new ValueGroup((int)player_id.Value, dist_multiplier * (float)damage);
            }
            else
            {
                /*If the player is in the aggro list,then simply add to the threat
                 * data stored into it*/
                int index = Array.FindIndex(HateList, delegate(ValueGroup g)
                {
                    return(g.index == (int)player_id.Value);
                });
                HateList[index].value += (float)damage * dist_multiplier;
            }
        }

        /*There needs to be a .2 times more threat to move up one place.
         * This is to prevent rapid switching of targets constantly w/o huge
         * damage changes.*/

        Array.Sort(HateList, delegate(ValueGroup lhs, ValueGroup rhs)
        {
            /*if (lhs.value == -1)
             * {
             *  return 0;
             * } */
            if (lhs.value * .9f > rhs.value)
            {
                return(-1);
            }
            else if (lhs.value * 1.1f < rhs.value)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        });
        if (HateList[0] != NOT_SET)
        {
            /*Assign target to one with most threat.The Gameobject's
             * existence is checked in event that a player disconnects.*/
            GameObject g = NetworkServer.FindLocalObject(new NetworkInstanceId((uint)HateList[0].index));
            if (g == null)
            {
                RemoveAggro(new NetworkInstanceId((uint)HateList[0].index));
            }
            else
            {
                Target = g.GetComponent <HealthDefence>();
            }
        }
        else
        {
            Target = null;
        }
    }
Exemple #17
0
    IEnumerator Damage(Collision hit, Collider col = null)
    {
        if (col == null)
        {
            Target = hit.gameObject.GetComponent <HealthDefence>();
        }
        else
        {
            Target = col.gameObject.GetComponent <HealthDefence>();
        }

        /*If the target still exist and doesn't even have this script,
         * Don't bother executing the rest of the code.As for the exception,it is there
         * in the event the object "dies" midway execution,presumably from another bullet.*/
        /*If a spawn point is hit by enemy,just run on client.*/

        /*If an enemy is hit(for enemy guns have no client user set),test whether the code is
         * running on the same client as the one who shot the bullet(for number UI to show up)
         * If a player is hit,run the code only on whoever got hit*/
        if (Target != null)
        {
            if (can_pierce)
            {
                if (hit != null)
                {
                    StartCoroutine(Pierce(hit));
                }
                else
                {
                    StartCoroutine(Pierce(col));
                }
            }
            legit_target = true;
            has_collided = true;
            //Wait until all coroutines operating on the bullet finish
            while (coroutines_running > 0)
            {
                yield return(new WaitForFixedUpdate());
            }
            int  damage = rand.Next(lower_bound_damage, upper_bound_damage);
            int  d      = (damage - Target.defence);
            bool crit   = false;
            if ((crit_chance - Target.crit_resistance) >= rand.NextDouble() + .001)//bullets with a crit chance of 0 shouldn't be able to land a crit
            {
                crit = true;
                d   *= 3;
            }
            Target.StartCoroutine(Target.DetermineChill(chill_strength));
            Target.StartCoroutine(Target.DetermineBurn(burn_strength, d));
            if (crit)
            {
                Target.RpcDisplayHPChange(new Color(114, 0, 198), d);//Violet
            }
            else
            {
                Target.RpcDisplayHPChange(Color.red, d);
            }


            if (Target.has_exp)
            {
                gun_reference.experience += d * Target.exp_rate;
            }
            if (Target.Controller)
            {
                Target.GetComponent <Rigidbody>().velocity = Vector3.zero;
            }
            AIController AI = Target.Controller as AIController;
            if (AI != null)
            {
                AI.UpdateAggro(d, gun_reference.client_user.netId);
            }
            Target.HP -= d;
            if (!can_pierce)
            {
                NetworkServer.Destroy(gameObject);
            }
        }
        /*If target is null or hit enemy detetion*/
        else if ((col && !col.isTrigger) || (hit != null && !hit.gameObject.GetComponent <Collider>().isTrigger))
        {
            /* Before destruction,Stop all coroutines(the gun_abilities operating on this instance)
             * to prevent exceptions from those coroutines*/

            StopAllCoroutines();
            NetworkServer.Destroy(gameObject);
        }
    }
Exemple #18
0
    IEnumerator Damage(Collision hit, Collider col = null)
    {
        if (!damaging)
        {
            damaging = true;
            if (col == null)
            {
                Target = hit.gameObject.GetComponent <HealthDefence>();
            }
            else
            {
                Target = col.gameObject.GetComponent <HealthDefence>();
            }

            /*If the target still exist and doesn't even have this script,
             * Don't bother executing the rest of the code.As for the exception,it is there
             * in the event the object "dies" midway execution,presumably from another bullet.*/
            /*If a spawn point is hit by enemy,just run on client.*/

            /*If an enemy is hit(for enemy guns have no client user set),test whether the code is
             * running on the same client as the one who shot the bullet(for number UI to show up)
             * If a player is hit,run the code only on whoever got hit*/
            if (Target != null)
            {
                legit_target = true;
                has_collided = true;
                //Wait until all coroutines operating on the bullet finish
                while (coroutines_running > 0)
                {
                    yield return(new WaitForFixedUpdate());
                }
                if (can_pierce)
                {
                    if (hit != null)
                    {
                        StartCoroutine(Pierce(hit));
                    }
                    else
                    {
                        StartCoroutine(Pierce(col));
                    }
                }
                ValueGroup <bool, int> v = GetDamage(Target);
                bool crit   = v.index;
                int  damage = v.value;
                if (damage > 0)
                {
                    double[] powers = { burn_strength, sunder_strength, chill_strength, mezmerize_strength };
                    Target.DetermineStatusEffects(powers, damage);
                    if (crit)
                    {
                        Target.RpcDisplayHPChange(new Color(114, 0, 198), damage);//Violet
                    }
                    else
                    {
                        Target.RpcDisplayHPChange(Color.red, damage);
                    }
                    ApplyExperience(damage, Target as UnitHealthDefence);
                    ApplyAggro(damage, Target as UnitHealthDefence);
                    ApplySpawnCounterDamage(damage, Target as SpawnPointHealthDefence);
                    Target.HP -= damage;
                }
            }
            if (!can_pierce && !can_bounce)
            {
                GetComponent <Collider>().enabled = false;
                ClearHazardCoords();
                NetworkServer.Destroy(gameObject);
            }
            damaging = false;
        }
    }