Inheritance: ToggleBehaviour
コード例 #1
0
    protected virtual void Impact(Collision collisionData)
    {
        if (collisionData != null)
        {
            string output = "";
            if (Owner != null)
            {
                if (!CanHitOwner)
                {
                    if (collisionData.gameObject == Owner.gameObject)
                    {
                        Debug.Log(name + " can't hit owner " + Owner.name);
                        return;
                    }
                }
                output += Owner.name + " with ";
            }
            output += name;
            //Debug.Log(collisionData.gameObject.name + " was hit by " + output);
            Player playerHit = collisionData.gameObject.GetComponent <Player>();
            if (playerHit != null)
            {
                //player.TakeDamage(Damage);
                if (Owner != null)
                {
                    GameManager.Instance.PlayerTakesDamage(playerHit, Damage, Owner);
                }
                else
                {
                    GameManager.Instance.PlayerTakesDamage(playerHit, Damage);
                }
                //player.Die();
            }

            Health healthComponent = collisionData.collider.GetComponentInParent <Health>();
            if (healthComponent != null)
            {
                healthComponent.UpdateValue(healthComponent.value - Damage);
            }
        }

        impactPosition = transform.position;
        hasImpacted    = true;
        Explosive explosive = GetComponent <Explosive>();

        if (explosive != null)
        {
            explosive.Explode();
        }

        if (DisappearUponImpact)
        {
            if (ServerBehaviour.HasActiveInstance())
            {
                ServerBehaviour.Instance.SendProjectileImpact(this);
            }
            //Debug.Log("Disappear");
            gameObject.SetActive(false);
        }
    }
コード例 #2
0
ファイル: Turret.cs プロジェクト: divy-kala/Who-Cares
    public void Fire()
    {
        if (ammo >= 1)
        {
            ammo--;
            //if ammo is 0, disable the turret
            if (ammo <= 0)
            {
                DisableTurret();
            }


            fired = true;
            if (timer >= timeBetweenBullets)
            {
                // Reset the timer.
                timer = 0f;

                // Play the gun shot audioclip.
                //       gunAudio.Play();

                // Enable the light.
                gunLight.enabled = true;

                // Stop the particles from playing if they were, then start the particles.
                gunParticles.Stop();
                gunParticles.Play();

                // Enable the line renderer and set it's first position to be the end of the gun.
                gunLine.enabled = true;
                gunLine.SetPosition(0, transform.position);

                // Set the shootRay so that it starts at the end of the gun and points forward from the barrel.
                shootRay.origin    = transform.position;
                shootRay.direction = transform.forward;

                // Perform the raycast against gameobjects on the shootable layer and if it hits something...
                if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
                {
                    // Try and find an EnemyHealth script on the gameobject hit.
                    Explosive explosive = shootHit.collider.GetComponent <Explosive>();

                    // Set the second position of the line renderer to the point the raycast hit.
                    gunLine.SetPosition(1, shootHit.point);
                    // If the Explosive component exist...
                    if (explosive != null)
                    {
                        explosive.Explode(shootHit.point);
                    }
                }
                // If the raycast didn't hit anything on the shootable layer...
                else
                {
                    print("hit nothing");
                    // ... set the second position of the line renderer to the fullest extent of the gun's range.
                    gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
                }
            }
        }
    }
コード例 #3
0
    public void CreateExplosion(Vector2 pos, float force, float range, float upwards)
    {
        var targets = GetRigidbodiesInRange(pos, range);

        foreach (Rigidbody2D r in targets)
        {
            Debug.Log(r);

            if (!r.gameObject.Equals(gameObject))
            {
                if (r.gameObject.GetComponent <Explosive>() != null)
                {
                    Debug.Log("Shit should work!");
                    Explosive explode = r.gameObject.GetComponent <Explosive>();
                    if (!explode.isDone() && explode.isActive())
                    {
                        explode.Explode();
                    }
                }
                else
                {
                    r.AddExplosionForce(force, pos, range, upwards);
                }
            }
        }
    }
コード例 #4
0
    private bool BeExplosive(GameObject obj, int increment)
    {
        Explosive explosive = obj.GetComponent <Explosive>();

        if (!explosive.enabled)
        {
            explosive.enabled = true;
            return(false);
        }
        else
        {
            switch (increment)
            {
            case 1:
                explosive.explosionRange += explosionRangeIncrement;
                break;

            case 2:
                explosive.cooldown -= explosionRateIncrement;
                break;

            default:
                explosive.power *= explosionPowerTimesIncrement;
                break;
            }

            return(true);
        }
    }
コード例 #5
0
    private void DetonateExplosive()
    {
        KnifeList.Clear();
        knifeDic.Clear();

        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius / 4);
        foreach (Collider collider in colliders)
        {
            if (collider.tag == "BlocksExplosive" || collider.tag == "BulletExplosive")
            {
                float     dis       = Vector3.Distance(collider.transform.position, transform.position);
                Explosive explosive = collider.gameObject.GetComponent <Explosive>();
                if (explosive != null)
                {
                    knifeDic.Add(dis, explosive);
                    if (!KnifeList.Contains(dis))
                    {
                        KnifeList.Add(dis);
                    }
                }
            }
        }
        if (KnifeList.Count > 0)
        {
            KnifeList.Sort(); //对距离进行排序
            Explosive obj;
            if (knifeDic.TryGetValue(KnifeList[0], out obj))
            {
                obj.Boom();
            }
        }
    }
コード例 #6
0
ファイル: Explosion.cs プロジェクト: WJLiddy/EK3
 public Explosion(Explosive e)
 {
     demRadius    = e.getDemolitionRadius();
     launchRadius = e.getLaunchRadius();
     force        = e.getForce();
     origin       = e.transform.localPosition;
 }
コード例 #7
0
        IEnumerator WaitForProvider()
        {
            while (Provider == null)
            {
                yield return(WaitFor.EndOfFrame);
            }
            explosiveDevice = Provider.GetComponent <Explosive>();
            if (explosiveDevice.DetonateImmediatelyOnSignal == false)
            {
                timer.Value = explosiveDevice.TimeToDetonate.ToString();
            }
            else
            {
                timer.Value  = "Waiting signal..";
                status.Value = dangerColor.ToString();
            }

            switch (explosiveDevice.ExplosiveType)
            {
            case ExplosiveType.C4:
                background.sprite = C4Graphic;
                break;

            case ExplosiveType.X4:
                background.sprite = X4Graphic;
                break;
            }

            modeToggleButton.Element.isOn = explosiveDevice.DetonateImmediatelyOnSignal;
            timerCount          = explosiveDevice.TimeToDetonate;
            explosiveDevice.GUI = this;
        }
コード例 #8
0
        private void AddPlayersAndBombsToGrid()
        {
            //List<Player> CurrentPlayers = context.Players.ToList();
            Explosive prototype = new Explosive();

            context.Players.Copy().CreateIterator().ForEach(player =>
            {
                if (!player.Bomb.Droped)
                {
                    player.Bomb.Droped = true;
                    if (IsBombValid(player) && player.BombLimit > player.BombCount)
                    {
                        Console.WriteLine(string.Format("addBombsToGrid x:{0}y:{1}", player.Bomb.GetCords().X, player.Bomb.GetCords().Y));
                        var copy = prototype.Clone();
                        copy.SetCords((Coordinates)player.Bomb.GetCords().Clone());
                        copy.Radius = player.Bomb.Radius;
                        context.AddGameObject(copy);
                        player.BombCount++;
                        RemoveBomb(copy, player);
                    }
                }
                int playerX          = player.xy.X;
                int playerY          = player.xy.Y;
                List <int> cleanTile = new List <int>();
                cleanTile.Add(player.User.Id);
                context.grid.UpdateTile(playerX, playerY, cleanTile);
            });
        }
コード例 #9
0
    public static Character CreateCharacter(int id)
    {
        Character c = null;

        switch (id)
        {   //有没有bug看单位表和各个类
        case 1:  c = new MvpTemp();    break;

        case 2:  c = new TankTemp();   break;

        case 3:  c = new WarriorTemp(); break;

        case 4:  c = new Taunter();    break;     // 嘲讽盾

        case 5:  c = new Paladin();    break;     // 奶骑

        case 6:                        break;     // 反甲

        case 7:  c = new Explosive();  break;     // 自爆卡车

        case 8:  c = new Linkage();    break;     // 联动

        case 9:  c = new TaiChi();     break;     // 打太极

        case 10: c = new Silence();    break;     // 沉默

        case 11: c = new GroupHealer(); break;    // 群体治疗

        case 12:                       break;     // 单体治疗

        case 13:                       break;     // 操控怒气

        case 14: c = new Calmer();     break;     // 频繁减怒

        case 15: c = new Buffer();     break;     // 加buff

        case 16: c = new Pierce();     break;     // 单体输出

        case 17: c = new Sputter();    break;     // 溅射

        case 18: c = new Volition();   break;     // 越打越痛

        case 19: c = new Transformer(); break;    // 变身

        case 20: c = new DoubleAgent(); break;    // 内鬼

        case 21: c = new Lazer();      break;     // 激光豆

        case 22: c = new Darius();     break;     // 人头狗

        case 23:                       break;     // 投石机

        case 24: c = new Marshall();   break;     // 黑胡子

        default: Debug.Log("输入了错误的id,找不到对应单位"); break;
        }

        return(c);
    }
コード例 #10
0
 /// This method is called when we click on the Explosive to show it in Inspector.
 public virtual void OnEnable()
 {
     explosive      = (Explosive)target;
     impactType     = serializedObject.FindProperty("impactType");
     innerRadius    = serializedObject.FindProperty("innerRadius");
     outerRadius    = serializedObject.FindProperty("outerRadius");
     explosionForce = serializedObject.FindProperty("explosionForce");
 }
コード例 #11
0
    /// <summary>
    /// Find the best target and turn the missile for a head-on collision.
    /// </summary>

    void Update()
    {
        float time = Time.time;

        if (mNextUpdate < time)
        {
            mNextUpdate = time + updateFrequency;

            // Find the most optimal target ahead of the missile
            if (currentTarget == null || !oneTarget)
            {
                currentTarget = HeatSource.Find(mTrans.position, mTrans.rotation * Vector3.forward, sensorRange, sensorAngle);
            }

            if (currentTarget != null)
            {
                // Calculate local space direction
                Vector3 dir  = (currentTarget.transform.position - mTrans.position);
                float   dist = dir.magnitude;

                dir *= 1.0f / dist;
                dir  = Quaternion.Inverse(mTrans.rotation) * dir;

                // Make the missile turn slower if it's far away from the target, and faster when it's close
                float turnSensivitity = 0.5f + 2.5f * (1.0f - dist / sensorRange);

                // Calculate the turn amount based on the direction
                mTurn.x = Mathf.Clamp(dir.y * turnSensivitity, -1f, 1f);
                mTurn.y = Mathf.Clamp(dir.x * turnSensivitity, -1f, 1f);

                // Locked on target
                mTimeSinceTarget = 0f;
            }
            else
            {
                // No target lock -- keep track of how long it has been
                mTimeSinceTarget += updateFrequency + Time.deltaTime;
            }

            mControl.turningInput = mTurn;
            mControl.moveInput    = Vector3.forward;
        }

        // If it has been too long
        if (mTimeSinceTarget > 2f)
        {
            Explosive exp = mControl.GetComponentInChildren <Explosive>();

            if (exp != null)
            {
                exp.Explode();
            }
            else
            {
                NetworkManager.RemoteDestroy(mControl.gameObject);
            }
        }
    }
コード例 #12
0
 public override void update()
 {
     base.update();
     postProcessor.update();
     if (Nez.Input.leftMouseButtonPressed)
     {
         Explosive.CreateExplosion(this, Nez.Input.mousePosition);
     }
 }
コード例 #13
0
ファイル: ExplosiveTests.cs プロジェクト: Rokaskl/doomerman
        public void ShouldReturnExplosiveTag()
        {
            // Arrange
            Explosive explosive = this.CreateExplosive();

            // Act
            System.Collections.Generic.List <string> result = explosive.GetTags();

            // Assert
            CollectionAssert.Contains(result, "Explosive");
        }
コード例 #14
0
 void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Enemy")
     {
         GameObject explode   = GameManager.Inst().ObjManager.MakeObj("Explosive");
         Explosive  explosive = explode.GetComponent <Explosive>();
         explosive.SetData(gameObject.GetComponent <Bullet>());
         explosive.SpriteRenderer.color = Bullet.color;
         explode.transform.position     = transform.position;
     }
 }
コード例 #15
0
ファイル: GameArenaTests.cs プロジェクト: Rokaskl/doomerman
        public void Should_ReturnFalse_When_Kick(int x, int y, Explosive.KickDirection dir)
        {
            //Arrange
            GameArena arena = new GameArena(0);
            Explosive bomb  = new Explosive(x, y);

            // Act
            arena.gameObjects.Add(bomb);
            //Assert
            Assert.IsFalse(arena.KickBomb(bomb.GetCords(), dir));
        }
コード例 #16
0
ファイル: GameArenaTests.cs プロジェクト: Rokaskl/doomerman
        public void Should_ReturnTrue_When_Kick(Explosive.KickDirection dir)
        {
            //Arrange
            GameArena arena = new GameArena(0);
            Explosive bomb  = new Explosive(1, 1);

            // Act
            arena.gameObjects.Add(bomb);
            //Assert
            Assert.IsTrue(arena.KickBomb(bomb.GetCords(), dir));
        }
コード例 #17
0
    public override void Attack()
    {
        //Inherits Attack method from Weapon.cs
        base.Attack();

        //Instantiates an explosive with the Explosive script, and sets the explosive off.
        GameObject explosive = Instantiate(objectToDropOrThrow, transform.position, Quaternion.identity);

        eScript        = explosive.GetComponent <Explosive>();
        eScript.setOff = true;
    }
コード例 #18
0
ファイル: ExplosiveTests.cs プロジェクト: Rokaskl/doomerman
        public void ShouldSetandGetCordsCoordinates()
        {
            // Arrange
            Explosive explosive = this.CreateExplosive();

            // Act
            explosive.SetCords(this.cords.Object);
            Coordinates result = explosive.GetCords();

            // Assert
            Assert.AreEqual(this.cords.Object, result);
        }
コード例 #19
0
    public void Destroy()
    {
        Explosive explosive = GetComponent <Explosive> ();

        if (explosive != null)
        {
            explosive.Explode();
        }

        gameController.AddScore(points);
        Destroy(gameObject);
    }
コード例 #20
0
    public void Detonate()
    {
        foreach (ParticleSystem ps in explosionParticles)
        {
            ps.Play();
        }
        AudioControl audioControl = GameController.instance.GetAudio();

        if (audioControl != null)
        {
            audioControl.SfxPlay(2);
        }
        detonated = true;
        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius);
        foreach (Collider c in colliders)
        {
            StorageSystem storage = c.GetComponent <StorageSystem>();
            if (storage != null)
            {
                List <GameObject> items = storage.RemoveAllContents();
                foreach (GameObject storageItem in items)
                {
                    Rigidbody sirb = storageItem.GetComponent <Rigidbody>();
                    if (sirb != null)
                    {
                        sirb.AddExplosionForce(explosionForce, transform.position, explosionRadius);
                    }
                    Explosive storageItemExplosive = storageItem.GetComponent <Explosive>();
                    if (storageItemExplosive != null)
                    {
                        storageItemExplosive.Explode();
                    }
                }
            }
            Rigidbody cRB = c.gameObject.GetComponent <Rigidbody>();
            if (cRB != null)
            {
                cRB.AddExplosionForce(explosionForce, transform.position, explosionRadius);
            }
            Explosive colliderExplosive = c.gameObject.GetComponent <Explosive>();
            if (colliderExplosive != null)
            {
                colliderExplosive.shouldExplode = true;
            }
        }
        try {
            GameController.instance.showGameOverUI();
        }
        catch (Exception e) {
            Debug.Log(e);
        }
    }
コード例 #21
0
ファイル: ExplosiveTests.cs プロジェクト: Rokaskl/doomerman
        public void ShouldDecreaseRadiusBy1ThanDecRadiusCalled()
        {
            // Arrange
            Explosive explosive = this.CreateExplosive();
            int       expexted  = explosive.Radius - 1;

            // Act
            explosive.DecRadius();
            int actual = explosive.Radius;

            // Assert
            Assert.AreEqual(expexted, actual);
        }
コード例 #22
0
    //Get refernce for GameManager and Explosive Script and assign rigidbody and forceMode (for explosion)
    void Start()
    {
        _PSObject = GameObject.FindGameObjectWithTag("emptyExplosions");

        _trans         = gameObject.GetComponent <Transform>();
        _rb            = GetComponent <Rigidbody>();
        _forceMode     = ForceMode.Impulse;
        _explosive     = gameObject.GetComponent <Explosive>();
        _breakingSound = _trans.parent.GetComponent <AudioSource>();
        _woodExplosion = _PSObject.transform.GetChild(0).gameObject;

        _fireEffect = _fireObject;
        _fireObject = null;
    }
コード例 #23
0
ファイル: GameArenaTests.cs プロジェクト: Rokaskl/doomerman
        public void ShouldAddGameObject()
        {
            //Arrange
            Explosive          gameObject          = new Explosive(1, 1);
            List <IGameObject> gameObjectsExpected = new List <IGameObject>();

            gameObjectsExpected.Add(gameObject);
            // Act
            GameArena arena = new GameArena(0);

            arena.gameObjects.Add(gameObject);
            //Assert
            CollectionAssert.AreEqual(gameObjectsExpected, arena.gameObjects);
        }
コード例 #24
0
    public void Shoot()
    {
        if (currentAmmo > 0 && !weaponSwitching.reloading)
        {
            currentAmmo--;
            timer = 0f;
            gunAudio.Stop();
            gunAudio.Play();
            gunLight.enabled = true;

            gunParticles.Stop();
            gunParticles.Play();

            gunLine.enabled = true;
            gunLine.SetPosition(0, transform.position);

            shootRay.origin    = transform.position;
            shootRay.direction = transform.forward;

            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                Debug.Log(shootHit);
                EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();
                if (enemyHealth != null && shootHit.point != null)
                {
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                }
                else
                {
                    Explosive explosive = shootHit.collider.GetComponent <Explosive>();
                    if (explosive != null && shootHit.point != null)
                    {
                        explosive.TakeDamage(damagePerShot);
                    }
                }


                gunLine.SetPosition(1, shootHit.point);
            }
            else
            {
                gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
            }
        }
        else if (!weaponSwitching.reloading)
        {
            Reload();
        }
    }
コード例 #25
0
        private async void RemoveBomb(Explosive bomb, Player player)
        {
            await Task.Factory.StartNew(() =>
            {
                var fc = new PowerUpFactory();

                Thread.Sleep(bomb.Time);
                Coordinates xy = bomb.GetCords();
                context.grid.RemoveFromTile(xy.X, xy.Y, (int)TileTypeEnum.Bomb);
                context.RemoveGameObject(bomb, xy.X, xy.Y);
                ExecuteExplosion(bomb);
                context.UpdateRequired = true;
                player.BombCount--;
            });
        }
コード例 #26
0
    protected override void ShootLogic()
    {
        base.ShootLogic();

        Explosive explosive = Instantiate(projectilePrefab,
                                          firingPoint.transform.position,
                                          transform.rotation).GetComponent <Explosive>();

        explosive.InitExplosive(explosionTime, explosionSize, damage, player.playerNumber,
                                initialForce, explosionSFXName, cameraShakeDuration, cameraShakeMagnitude, player.cookTime);

        if (GameManager.instance.SelectedGamemode != null)
        {
            GameManager.instance.SelectedGamemode.AddToStats(player.playerNumber, StatTypes.BulletsFired, 1);
        }
    }
コード例 #27
0
        public void ShouldReturnTrueWhenKickStrategyAndMovingIntoAllowedTiles(TileEnumerator.TileTypeEnum tileType)
        {
            player = new Player(new User());
            player.ChangeStrategy(new MoveKickStrategy());

            List <int>[,] grid = wallsAdapter.GetGrid();
            grid[1, 0].Add((int)tileType);
            Explosive go = new Explosive(1, 0);

            App.Inst.Arena.AddGameObject(go);

            bool move = player.CanMove(ArenaCommandEnum.MoveRight, grid);

            App.Inst.Arena.RemoveGameObject(go, 1, 0);
            Assert.IsTrue(move);
        }
コード例 #28
0
    private void FixedUpdate()
    {
        Vector3 sourcePosition = GetSourcePosition();

        Collider[] colliders = Physics.OverlapSphere(sourcePosition, poisoningRadius);
        foreach (Collider c in colliders)
        {
            if (c.gameObject != gameObject)
            {
                Explosive explosive = c.gameObject.GetComponent <Explosive>();
                if (explosive != null)
                {
                    explosive.AddPoisoning(GetCorrectPoisoningAmount(c, sourcePosition));
                }
            }
        }
    }
コード例 #29
0
    /// <summary>
    /// When the plasma beam hits something we want to apply damage and destroy the beam.
    /// </summary>

    void OnTriggerEnter(Collider col)
    {
        if (!mIsMine)
        {
            return;
        }

        Rigidbody rb = Tools.FindInParents <Rigidbody>(col.transform);

        if (rb != null)
        {
            Explosive exp = rb.GetComponentInChildren <Explosive>();

            if (exp != null)
            {
                exp.Explode();
            }
            else
            {
                Rigidbody myRb = rigidbody;

                if (myRb != null)
                {
                    Vector3 force = myRb.velocity * myRb.mass * forceOnCollision;
                    Vector3 pos   = transform.position;

                    NetworkRigidbody nrb = NetworkRigidbody.Find(rb);
                    if (nrb != null)
                    {
                        nrb.AddForceAtPosition(force, pos);
                    }
                }
            }
        }

        // Apply damage to the unit, if we hit one
        GameUnit unit = Tools.FindInParents <GameUnit>(col.transform);

        if (unit != null)
        {
            unit.ApplyDamage(damageOnHit);
        }

        // Destroy this beam
        NetworkManager.RemoteDestroy(gameObject);
    }
コード例 #30
0
ファイル: Weapons.cs プロジェクト: tuohai/Three-D-Velocity
        /* Fires when a weapon hits a target.
         * If sender == NULL, this mean we pseudofired this event from
         * executeServerCommand().
         * IE: what happened is that we had a hit on the server side but by the time it reached here to propogate,
         * this local Weapons class had disposed of the local copy of the projectile.
         * However, we still need to propogate the hit.
         * */
        public void eventHit(Explosive sender,
                             Projector target,
                             int damageAmount, //0 if from server or LTS
                             WeaponTypes type) //Used if weapon has been deleted by the time hit event registers on server
        {
            if (sender != null)
            {
                sender.eventHit -= eventHit;
            }

            bool killed = target.damage - damageAmount <= 0;

            if (killed)
            {
                target.indicateDestroyedBy(creator.name, creator.id);
            }
            if (!executingServerData && target.isSender())
            {
                writer.Write(sender.id.Replace(creator.id, null));
                writer.Write(target.id);
                writer.Write((byte)type);
                writer.Flush();
                weaponEvents++;
            }
            if (!executingServerData && !(sender is LaserCannonSystem)) //we already get new damage value from server.
            {
                target.hit(damageAmount, Interaction.Cause.destroyedByWeapon);
            }
            if (killed)
            {
                if (destroy != null)
                {
                    destroy(target);
                }
                return;
            }
            if (strike != null)
            {
                strike(type == WeaponTypes.laserCannonSystem);
            }
            if (sender == null)
            {
                doNullSender(type, target);
            }
        }