Esempio n. 1
0
        void OnTriggerEnter(Collider col)
        {
            if (_started || !StaticUtil.LayerMatchTest(CanUseThis, col.gameObject))
            {
                return;
            }
            _started = true;

            int i = 0;

            if (SpawnPoints.Length == 0)
            {
                Debug.LogWarning("Spawn Trigger Warning: No spawn points are specified so this trigger effectively does nothing.");
                return;
            }
            foreach (GameObject point in SpawnPoints)
            {
                if (!SpawnerPrefabs[i])
                {
                    Debug.LogError("Spawn Trigger Error: You specify a spawn point, but no Spawner Prefab. Can't proceed without a valid Prefab of the Spawner that you to create.");
                    break;
                }
                GameObject s = (GameObject)StaticUtil.Spawn(SpawnerPrefabs[i], point.transform.position, point.transform.rotation);
                Spawner    x = s.GetComponent <Spawner>();
                _remainingSpawners.Add(x);
                x.Owner = this;
                i++;
            }

            StartCoroutine(CloseDoors());
            StartCoroutine(VictoryLoop());
        }
Esempio n. 2
0
        // Melee
        void OnTriggerEnter(Collider theColliderWeHit)
        {
            // Add hits to a list to prevent damage stacking in the same swing.
            // Empty the list when swing finishes.
            if (_hitsDuringThisSwing.Contains(theColliderWeHit))
            {
                return;
            }

            _victimGameObject = theColliderWeHit.gameObject;
            _victimSubject    = _victimGameObject.GetComponent <Subject>();

            Vector3 impactPos = theColliderWeHit.transform.position + Vector3.up; // would be nice to get more accurate with this.

            // if what we hit is on a layer in our mask, plow into it.
            if (!StaticUtil.LayerMatchTest(Mask, _victimGameObject))
            {
                return;
            }
            if (_victimSubject != null)
            {
                DoMeleeDamage(theColliderWeHit.GetComponent <Subject>());
            }

            DoMeleeDamage(theColliderWeHit.GetComponent <Subject>());
            DoImpactEffects(impactPos);
            _hitsDuringThisSwing.Add(theColliderWeHit);
        }
Esempio n. 3
0
        /// <summary>
        /// Drops the current Weapon into the scene
        /// </summary>
        public IEnumerator DropCurrentWeapon()
        {
            _switchingWeapons = true;
            if (LogDebug)
            {
                Debug.Log("Dropping current weapon in slot " + _currentWeapon);
            }
            if (GetCurrentWeaponGo() == null || GetCurrentWeaponComponent().PickupReference == null)
            {
                Debug.Log("Either there is no weapon equippped or the weapon doesn't have a Pickup Reference defined.");
                _switchingWeapons = false;
                yield break;
            }
            StaticUtil.SpawnLoot(WeaponListRuntime[_currentWeapon].GetComponent <Weapon>().PickupReference, transform.position);

            GameObject droppingThis = WeaponListRuntime[_currentWeapon];

            WeaponListRuntime.RemoveAt(_currentWeapon);
            if (WeaponListRuntime.Count == _currentWeapon)
            {
                _currentWeapon -= 1;
            }

            yield return(StartCoroutine(ChangeWeaponToSlot(_currentWeapon)));

            _switchingWeapons = true;

            StaticUtil.DeSpawn(droppingThis);
            while (_myControls.GetInputDropWeapon)
            {
                yield return(null);
            }
            _switchingWeapons = false;
        }
Esempio n. 4
0
        /// <summary>
        /// Starts the pickup sequence
        /// </summary>
        void CreateNewWeapon(GameObject weaponPrefab)
        {
            if (weaponPrefab == null)
            {
                return;
            }
            if (_hand == null)
            {
                Debug.LogError("Incorrect Rig Type on " + gameObject.name + "! Must be Humanoid. Check the Import Settings for this model and correct the type. Also confirm the Avatar Configuration has no errors.");
                return;
            }

            GameObject newToy = (GameObject)StaticUtil.Spawn(weaponPrefab, _hand.position, _hand.rotation);
            Weapon     wx     = newToy.GetComponent <Weapon>();

            wx.Owner = this;

            WeaponListRuntime.Add(newToy);

            newToy.transform.SetParent(gameObject.transform);
            newToy.SetActive(false);

            if (LogDebug)
            {
                Debug.Log("Adding Weapon to Subject " + newToy.name + "...");
            }
        }
Esempio n. 5
0
        void OnEnable()
        {
            if (Stats.SpawnFx)
            {
                StaticUtil.Spawn(Stats.SpawnFx, transform.position, transform.rotation);
            }

            // Pooling... ?
        }
Esempio n. 6
0
 public void DeSpawn()
 {
     // using DeSpawn() to apply aoe dmg?... not sure if that is okay...
     if (Stats.CauseAoeDamage && Stats.Bouncer && !_despawning)
     {
         _despawning = true;
         DoDamageAoe();
     }
     StaticUtil.DeSpawn(gameObject);
 }
Esempio n. 7
0
 void OnTriggerExit(Collider col)
 {
     if (ManuallyTriggered || Locked || !DoorMesh)
     {
         return;
     }
     if (!StaticUtil.LayerMatchTest(CanUseThisDoor, col.gameObject))
     {
         return;
     }
     _occupancy--;
 }
Esempio n. 8
0
        private IEnumerator FireRanged()
        {
            if (Stats.CurrentAmmo >= Stats.AmmoCost)
            {
                DoFireEffect();

                Vector3    pos = Stats.ProjectileSpawnPoints[_nextSpawnPt].transform.position;
                Quaternion rot = Stats.ProjectileSpawnPoints[_nextSpawnPt].transform.rotation;

                if (Stats.Accuracy < 1.0f)
                {
                    float a = Mathf.Clamp(Stats.Accuracy, 0, 1) - 1;
                    rot.x += Random.Range(-0.2f * a, 0.2f * a);
                    rot.y += Random.Range(-0.2f * a, 0.2f * a);
                    rot.z += Random.Range(-0.2f * a, 0.2f * a);
                }

                GameObject thisBullet = StaticUtil.Spawn(Stats.FiresProjectile, pos, rot) as GameObject;
                if (thisBullet != null)
                {
                    thisBullet.GetComponent <Projectile>().Owner = Owner; // assign the bullet owner, for points, etc.
                }
                if (_ejector != null)
                {
                    _ejector.Emit(1);                      // if there is a shell casing ejector, use it.
                }
                if (Stats.ProjectileSpawnPoints.Count > 1) // if using multiple spawn points, iterate through them.
                {
                    _nextSpawnPt++;
                    if (_nextSpawnPt > Stats.ProjectileSpawnPoints.Count - 1)
                    {
                        _nextSpawnPt = 0;
                    }
                }

                Stats.CurrentAmmo -= Stats.AmmoCost;

                Owner.DoWeaponFire();
                yield return(StartCoroutine(FireCooldown()));

                yield break;
            }

            if (MagIsEmpty() && Stats.AutoReload)
            {
                yield return(StartCoroutine(Reload()));

                yield break;
            }

            // the IFs failed [and did not yield break], so this code is reached and we are indeed out of ammo.
            yield return(StartCoroutine(NoAmmo()));
        }
Esempio n. 9
0
 public void SpawnWave()
 {
     foreach (KeyValuePair <GameObject, int> key in EnemyReferences)
     {
         for (int i = 0; i < key.Value; i++)
         {
             Transform t = Positions[Random.Range(0, (Positions.Count))].transform;
             if (Owner)
             {
                 Owner.AddToEnemies(StaticUtil.Spawn(key.Key, t.position, t.rotation) as GameObject);
             }
         }
     }
 }
Esempio n. 10
0
        public IEnumerator StartLifetimer(float time)
        {
            yield return(new WaitForSeconds(time));

            if (CallDespawn)
            {
                gameObject.SendMessage("DeSpawn", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                StaticUtil.DeSpawn(gameObject);
            }
            Destroy(this); // remove this script - important!
        }
Esempio n. 11
0
        IEnumerator SpawnerLoop()
        {
            while (!Completed)
            {
                _curWave++;
                SpawnWave();

                if (SpawnerType == SpawnerStyle.FixedCount && _curWave >= FixedWaveCount)
                {
                    StaticUtil.DeSpawn(gameObject);
                }
                yield return(_waveGap);
            }
        }
Esempio n. 12
0
        void OnTriggerEnter(Collider col)
        {
            if (!StaticUtil.LayerMatchTest(CanPickThisUp, col.gameObject))
            {
                return;
            }
            _subject  = col.GetComponent <Subject>();
            _controls = col.GetComponent <PlayerController>();
            if (_subject == null || _controls == null)
            {
                return;
            }

            _canPickup = true;
        }
Esempio n. 13
0
        public void LevelUp()
        {
            if (Stats.Level.Actual >= Stats.Level.Max)
            {
                return;
            }

            if (OnLevelChange != null)
            {
                OnLevelChange();
            }
            if (Stats.LevelUpFx)
            {
                StaticUtil.Spawn(Stats.LevelUpFx, transform.position, Quaternion.identity);
            }
            SetLevelAndStats((int)Stats.Level.Actual + 1);
        }
Esempio n. 14
0
        private void PopFx(int entry, Vector3 position)
        {
            if (ImpactSounds[entry] != null)
            {
                AudioSource.PlayClipAtPoint(ImpactSounds[entry], position);
            }
            else
            {
                Debug.LogWarning(gameObject.name + " cannot spawn Impact sound because it is null. Check the Impact Tag List.");
            }

            if (ImpactEffects[entry] != null)
            {
                StaticUtil.Spawn(ImpactEffects[entry], position, Quaternion.identity);
            }
            else
            {
                Debug.LogWarning(gameObject.name + " cannot spawn Impact effect because it is null. Check the Impact Tag List.");
            }
        }
Esempio n. 15
0
        private void PopFx(int index)
        {
            if (ImpactSounds[index] != null)
            {
                AudioSource.PlayClipAtPoint(ImpactSounds[index], _endPoint);
            }
            else
            {
                Debug.LogWarning(gameObject.name + " cannot spawn Impact sound because it is null. Check the Impact Tag List.");
            }

            if (ImpactEffects[index] != null)
            {
                StaticUtil.Spawn(ImpactEffects[index], _endPoint, Quaternion.LookRotation(_endNormal));
            }
            else
            {
                Debug.LogWarning(gameObject.name + " cannot spawn Impact effect because it is null. Check the Impact Tag List.");
            }
        }
Esempio n. 16
0
        private void DoDamageAoe()
        {
            // could use foo.SendMessage, but it is sloppy... Rather pay for GetComponent instead.
            RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, Stats.AoeRadius, Vector2.up, 0.1f, Mask);
            foreach (RaycastHit2D thisHit in hits)
            {
                _victimGo = thisHit.collider.gameObject;
                _victim   = _victimGo.GetComponent <Subject>();

                if (Stats.AoeForce > 0)
                {
                    Rigidbody2D rb      = _victimGo.GetComponent <Rigidbody2D>();
                    Vector3     dir     = (rb.transform.position - transform.position);
                    float       wearoff = 1 - (dir.magnitude / Stats.AoeRadius);
                    if (rb != null)
                    {
                        rb.AddForce(dir.normalized * Stats.AoeForce * wearoff);
                    }
                }

                if (_victim != null)
                {
                    _victim.DoDamage(Stats.Damage, Owner);
                    Owner.Stats.DamageDealt += Stats.Damage;
                }

                // TODO Hit FX
                // Hit FX per AoE contact not yet working.
                //
                // _endPoint = thisHit.point;
                // SetupImpactNormal(thisHit.normal);
                // PopFx(GetCorrectFx(thisHit.collider.gameObject));

                FinishImpact();
            }

            if (Stats.AoeEffect != null)
            {
                StaticUtil.Spawn(Stats.AoeEffect, transform.position, Quaternion.identity);
            }
        }
Esempio n. 17
0
        public void SetLevelAndStats(int level)
        {
            // Set the level and handle excess experience by looping here.
            int carryOverXp = (int)(Stats.Experience.Actual - Stats.Experience.Max);

            Stats.Experience.Actual = Stats.Experience.Min + carryOverXp;
            Stats.Level.Actual      = level;
            Stats.Experience.Max    = StaticUtil.StatShouldBe(Stats.Experience, (int)Stats.Level.Actual);
            if (Stats.Experience.Actual > Stats.Experience.Max)
            {
                LevelUp();
            }

            // The level is correct, now calculate all of the stats.
            Stats.XpReward.Actual = StaticUtil.StatShouldBe(Stats.XpReward, (int)Stats.Level.Actual);
            Stats.Health.Max      = StaticUtil.StatShouldBe(Stats.Health, (int)Stats.Level.Actual);
            Stats.Armor.Max       = StaticUtil.StatShouldBe(Stats.Armor, (int)Stats.Level.Actual);

            Stats.Agility.Actual   = StaticUtil.StatShouldBe(Stats.Agility, (int)Stats.Level.Actual);
            Stats.Dexterity.Actual = StaticUtil.StatShouldBe(Stats.Dexterity, (int)Stats.Level.Actual);
            Stats.Endurance.Actual = StaticUtil.StatShouldBe(Stats.Endurance, (int)Stats.Level.Actual);
            Stats.Strength.Actual  = StaticUtil.StatShouldBe(Stats.Strength, (int)Stats.Level.Actual);
        }
Esempio n. 18
0
        /// <summary>
        /// Timed period of downage (mostly dead). Could be revived. DeSpawn after timer ends - then totally dead.
        /// </summary>
        private IEnumerator CrippleAndDie()
        {
            // Drop to a crippled state and wait.
            if (Stats.CrippledTime > 0)
            {
                yield return(new WaitForSeconds(Stats.CrippledTime));
            }
            if (Stats.DeathFx)
            {
                StaticUtil.Spawn(Stats.DeathFx, transform.position, transform.rotation);
            }
            for (int i = 0; i < transform.childCount; i++)
            {
                transform.GetChild(i).gameObject.SetActive(false);
            }
            // Detatch the corpse model and give it an expiration timer.
            Stats.DeadBodyObj.SetActive(true);
            Lifetimer c = Stats.DeadBodyObj.AddComponent <Lifetimer>();

            c.Lifetime = Stats.CorpseTime;

            DeSpawn();
        }
Esempio n. 19
0
        void ScanForAllSubjects()                           // get all subjects in the Sight Range
        {
            _scanClock = 0;
            Collider2D[] scanHits = Physics2D.OverlapCircleAll(transform.position, SightRange, ThreatMask);

            if (LogDebug)
            {
                Debug.Log("Scanning " + scanHits.Length + " hits.");
            }
            foreach (Collider2D thisHit in scanHits)
            {
                if (thisHit.gameObject == gameObject)
                {
                    continue;                                                    // is it me?
                }
                Subject otherSubject = thisHit.GetComponentInParent <Subject>(); // TODO this is unfortunately frequent...
                if (!otherSubject)
                {
                    continue;                // is it null?
                }
                if (AllyList.Contains(otherSubject) || ThreatList.ContainsKey(otherSubject))
                {
                    continue;                                                                          // is it a duplicate?
                }
                // none of that? then sort the new entry as Ally or Threat.
                if (StaticUtil.SameTeam(ThisSubject, otherSubject))
                {
                    DefineAsAlly(otherSubject);
                }
                else
                {
                    DefineAsThreat(otherSubject, (MyProvokeType == ProvokeType.TargetIsInRange) ? 1 : 0);
                }
            }

            CleanLists();
        }
Esempio n. 20
0
        /// <summary>
        /// Begins the Subject's death. Subjects can be 'down-but-not-out' for a period of time, then completely die.
        /// </summary>
        void Die()
        {
            // Deny controls, reset velocity, turn off ai, turn off collider
            if (_isControllable)
            {
                SetInputPermission(false, false, false);
            }

            _myRigidbody.velocity        = Vector3.zero;
            _myRigidbody.angularVelocity = 0f;

            if (GetComponent <Intellect>() != null)
            {
                GetComponent <Agent>().enabled = false;
            }

            GetComponent <Collider2D>().enabled = false;

            if (Stats.DeathFx)
            {
                StaticUtil.Spawn(Stats.DeathFx, transform.position, Quaternion.identity);
            }
            if (OnDeath != null)
            {
                OnDeath();
            }

            // Update stats
            Stats.Deaths++;
            LastAttacker.Stats.Kills++;
            StaticUtil.GiveXp((int)Stats.XpReward.Actual, LastAttacker);
            //

            IsDead = true;
            StartCoroutine(CrippleAndDie());
        }
Esempio n. 21
0
        void OnCollisionEnter2D(Collision2D col) // Handles hits for Standard Type.
        {
            if (!Stats.CauseAoeDamage)           // I cause damage to what I collided into.
            {
                _victimGo = col.gameObject;
                _victim   = _victimGo.GetComponent <Subject>();

                if (StaticUtil.LayerMatchTest(Mask, _victimGo))
                {
                    if (_victim != null)
                    {
                        DoDamageToVictim();
                    }

                    _endPoint = col.contacts[0].point;
                    SetupImpactNormal(col.contacts[0].normal);
                    PopFx(GetCorrectFx(col.gameObject));
                    if (_endNormal != null)
                    {
                        _victim.ShowHitIndicator(_endNormal);
                    }
                    FinishImpact(); -------------------------------------------------------------------------------------------------------- ö - pöpö
                }
                else
                {
                    foreach (Collider2D z in _myColliders)
                    {
                        Physics2D.IgnoreCollision(z, col.collider);
                    }
                }
            }
            else if (Stats.CauseAoeDamage && !Stats.Bouncer)
            {
                DoDamageAoe();                                              // I cause AoE immediately when I hit something.
            }
        }
Esempio n. 22
0
 void Done()
 {
     StaticUtil.DeSpawn(gameObject);
 }
Esempio n. 23
0
        private void Start()
        {
            if (IsOwner)
            {
                SetInputPermission(true, true, true);
                OnHealthChanged  += Subject_OnHealthChanged;
                OnSwitchedWeapon += Subject_OnSwitchedWeapon;
                OnReload         += Subject_OnReload;
                OnFire           += Subject_OnFire;
            }
            isPlayer          = true;
            serializePosition = SerializeVector3Properties.XY;
            serializeRotation = SerializeVector3Properties.Z;
            serializeScale    = SerializeVector3Properties.None;
            StartCoroutine(InputLoop());

            if ((int)Stats.Level.Actual == 0)
            {
                StaticUtil.GiveXp((int)Stats.Experience.Max, this);
            }

            // TODO Cleanup
            // Different (terrible) formatting to save vertical space... Was getting pointlessly long.
            _currentWeapon = 0;
            bool weaponSetupIsOkay = true;

            if (Stats.WeaponMountPoint != null)
            {
                _hand = Stats.WeaponMountPoint.transform;
            }
            else
            {
                weaponSetupIsOkay = false;
                if (WeaponListEditor.Count != 0)
                {
                    Debug.LogWarning("No Weapon Mount Point is specified! Assign it on the Subject.");
                }
            }

            // Initialize if there were no problems.
            if (!weaponSetupIsOkay)
            {
                return;
            }
            if (LogDebug)
            {
                Debug.Log(".... Weapon setup is okay");
            }

            // Create the predefined weapons, if any
            if (WeaponListEditor.Count == 0)
            {
                return;
            }
            foreach (GameObject boomboom in WeaponListEditor)
            {
                PickupWeapon(boomboom);
            }
            StartCoroutine(ChangeWeaponToSlot(0));
            _initialized = true;
        }
Esempio n. 24
0
 private void DoMuzzleFlash()
 {
     // TODO should muzzle flash be on the projectile or the weapon? Poll users for suggestions.
     StaticUtil.Spawn(AttackEffect, transform.position, transform.rotation);
 }
Esempio n. 25
0
        IEnumerator Life()
        {
            yield return(new WaitForSeconds(Duration));

            StaticUtil.DeSpawn(gameObject);
        }
Esempio n. 26
0
 void Disappear()
 {
     StaticUtil.DeSpawn(gameObject);
 }
Esempio n. 27
0
 public void DeSpawn()
 {
     // Pooling TBD
     StaticUtil.DeSpawn(gameObject);
 }
Esempio n. 28
0
        /// <summary>
        /// Inflict damage to this subject
        /// </summary>
        public void DoDamage(int damage, Subject dealer)
        {
            if (IsDead)
            {
                return;
            }
            if (!Options.Data.FriendlyFire && StaticUtil.SameTeam(this, dealer))
            {
                return;
            }

            LastAttacker = dealer;
            if (Stats.HitSound != null)
            {
                AudioSource.PlayClipAtPoint(Stats.HitSound, transform.position);
            }
            int damageProcessed = damage;

            #region #### Armor Calculation Block
            if (Armor > 0)
            {
                if (Stats.ArmorType == ArmorType.Absorb)
                {
                    Armor = Armor - damage; // Absorb damage
                    if (Armor < 0)          // If any armor is left, count as excess
                    {
                        damageProcessed = -Armor;
                        Armor           = 0;
                    }
                    else
                    {
                        damageProcessed = 0;
                    }
                }
                else
                {
                    damageProcessed = damage - Armor; // Nullify damage
                    if (Armor < 0)                    // if any is left, count as excess
                    {
                        damageProcessed = -Armor;
                        Armor           = 0;
                    }
                }
            }
            #endregion

            if (damageProcessed < 0)
            {
                damageProcessed = 0;
            }
            else if (damageProcessed > Stats.Health.Actual)
            {
                damageProcessed = (int)Stats.Health.Actual;
            }
            Health    -= damageProcessed;
            LastDamage = damageProcessed;

            Stats.DamageTaken += damageProcessed;
            LastAttacker.Stats.DamageDealt += damageProcessed;
            LastAttacker.Stats.ShotsConnected++;

            StaticUtil.SpawnFloatingText(this, transform.position, damageProcessed.ToString());

            if (OnAttacked != null)
            {
                OnAttacked();
            }
        }
Esempio n. 29
0
        public void ShowHitIndicator(Vector2 normal)
        {
            Quaternion rot = Quaternion.AngleAxis(Mathf.Atan2(normal.y, normal.x) * Mathf.Rad2Deg, Vector3.forward);

            StaticUtil.Spawn(Stats.HitIndicator, transform.position, rot);
        }
Esempio n. 30
0
        void OnTriggerEnter(Collider col)
        {
            _collector = col.gameObject;
            if (!StaticUtil.LayerMatchTest(Mask, _collector))
            {
                return;
            }
            _keeper = col.GetComponent <Subject>();
            if (_keeper == null)
            {
                return;
            }

            if (TargetStat == Target.Health)
            {
                switch (Act)
                {
                case ActionType.Add:
                {
                    _keeper.Health += Value;
                    break;
                }

                case ActionType.Subtract:
                {
                    _keeper.Health -= Value;
                    break;
                }

                case ActionType.Set:
                {
                    _keeper.Health = Value;
                    break;
                }
                }
            }

            if (TargetStat == Target.Armor)
            {
                switch (Act)
                {
                case ActionType.Add:
                {
                    _keeper.Armor += Value;
                    break;
                }

                case ActionType.Subtract:
                {
                    _keeper.Armor -= Value;
                    break;
                }

                case ActionType.Set:
                {
                    _keeper.Armor = Value;
                    break;
                }
                }
            }

            if (TargetStat == Target.Ammo)
            {
                if (Pickup == PickupAffect.Current)
                {
                    Weapon w = _keeper.GetCurrentWeaponComponent();
                    AffectWeaponAmmo(w);
                }
                else
                {
                    foreach (GameObject wpn in _keeper.WeaponListRuntime)
                    {
                        Weapon w = wpn.GetComponent <Weapon>();
                        AffectWeaponAmmo(w);
                    }
                }
            }

            if (TargetStat == Target.Magazines)
            {
                if (Pickup == PickupAffect.Current)
                {
                    Weapon w = _keeper.GetCurrentWeaponComponent();
                    AffectWeaponMags(w);
                }
                else
                {
                    foreach (GameObject wpn in _keeper.WeaponListRuntime)
                    {
                        Weapon w = wpn.GetComponent <Weapon>();
                        AffectWeaponMags(w);
                    }
                }
            }

            _keeper.DoGrabPowerup();
            Disappear();
        }