示例#1
0
    public void placeTrap(int type)
    {
        /* PARAMETERS:
         * type = type of the trap that is placed
         * DO:
         * Places a trap on this tile
         */

        trapType = type;
        //mark the trap type of the block to the type of the trap

        ready = true;
        //note that the trap is ready to trap an enemy
        Vector3 dropLocation = transform.position;
        //define where the trap is to be placed
        GameObject tempTrap = Instantiate(GameController.main.trapClasses[trapType].prefab, dropLocation, Quaternion.identity, GameController.main.trapContainer.transform) as GameObject;

        //spawn the trap at the dropLocation inside the trapContainer

        trapRef = tempTrap.GetComponent <TrapController>();
        //obtain a reference to the trap that is placed on this tile

        //trapRef.setTileReference(this);
        //pass a reference of this TileController object to the placed tile
    }
示例#2
0
    void getValues()
    {
        GameObject en  = GameObject.FindWithTag("Enemy");
        GameObject en1 = GameObject.FindWithTag("Boulder");
        GameObject en2 = GameObject.FindWithTag("Enemy");

        if (en != null)
        {
            enemy = en.GetComponent <EnemyController>();
        }
        if (enemy == null)
        {
            Debug.Log("Cannot find 'EnemyController' script");
        }
        if (en1 != null)
        {
            boulder = en1.GetComponent <Boulder>();
        }
        if (boulder == null)
        {
            Debug.Log("Cannot find 'Boulder script");
        }
        if (en2 != null)
        {
            villagerdamage = en2.GetComponent <VillagerDamageController>();
        }
        if (villagerdamage == null)
        {
            Debug.Log("Cannot find 'VillagerdamageController' script");
        }
        gameController = GameObject.FindWithTag("GameController").GetComponent <GameController> ();
        trapcontrol    = GameObject.FindWithTag("TrapController").GetComponent <TrapController> ();
    }
示例#3
0
 // Use this for initialization
 void Start()
 {
     nodeController = GetComponent <NodeController>();
     trapController = GetComponent <TrapController>();
     uiController   = GameObject.Find("In-game UI").GetComponent <UI_Controller>();
     loader         = GameObject.Find("SceneManager").GetComponent <SceneLoader>();
 }
示例#4
0
    private Vector3 FindRandomDestination(TrapController trap)
    {
        Vector3 target = Vector3.zero;

        NavMeshQueryFilter filterBird = new NavMeshQueryFilter();

        filterBird.areaMask    = birdNavAgent.areaMask;
        filterBird.agentTypeID = birdNavAgent.agentTypeID;

        float radius = UnityEngine.Random.Range(0.8f, 1.5f);
        float angle  = UnityEngine.Random.Range(0f, 360f);

        Vector3 randomPosition = new Vector3(radius * Mathf.Cos(angle), 0, radius * Mathf.Sin(angle));

        randomPosition += trap.transform.position;
        NavMeshHit hit;

        if (NavMesh.SamplePosition(randomPosition, out hit, 0.2f, filterBird))
        {
            target = hit.position;
        }
        else
        {
            Debug.Log("random dest failed");
        }

        return(target);
    }
 void OnTriggerEnter(Collider obj)
 {
     Instantiate(effect, transform.position, Quaternion.identity);
     Collider[] colliders = Physics.OverlapSphere(transform.position, 5f);
     foreach (Collider hit in colliders)
     {
         if (hit.tag == "Enemy")
         {
             Rigidbody rb = hit.GetComponent <Rigidbody> ();
             if (rb != null)
             {
                 rb.AddExplosionForce(650f, transform.position, 20f, 2f);
             }
             EnemyController ec = hit.GetComponent <EnemyController> () as EnemyController;
             ec.startDestroy();
         }
         else if (hit.tag == "Trap")
         {
             Rigidbody rb = hit.GetComponent <Rigidbody> ();
             if (rb != null)
             {
                 rb.AddExplosionForce(650f, transform.position, 20f, 2f);
             }
             TrapController ec = hit.GetComponent <TrapController> () as TrapController;
             ec.startDestroy();
         }
     }
     Destroy(this.gameObject);
 }
示例#6
0
    public void CreateTrapSpeed()
    {
        GameObject     obj = Instantiate(this.trapSpeed, this.trapPin.transform.position, this.trapPin.transform.rotation);
        TrapController tc  = obj.GetComponent <TrapController>();

        tc.onAir  = true;
        tc.trapID = 2;
    }
    void CreateEnemy()
    {
        Vector3        pos            = transform.position + new Vector3(0, 0, 1);
        TrapController trapController = Instantiate(trapPrefab, pos, transform.rotation * Quaternion.Euler(0f, 0f, 45f))
                                        .GetComponent <TrapController>();

        trapController.velocity = objectVelocity;
    }
示例#8
0
    // Use this for initialization
    void Start()
    {
        trapCtrl = transform.parent.gameObject.GetComponent<TrapController>();
        ghostCtrl = GameObject.Find("GameController").GetComponent<GhostWorldController>();

        player = GameObject.FindGameObjectWithTag("Player");

        disarm = transform.Find("Disarm").GetComponent<TrapDisarm>();
    }
示例#9
0
    private void Start()
    {
        _rootParent = gameObject;
        while (!_rootParent.CompareTag("Trap") && _rootParent.transform.parent != null)
        {
            _rootParent = _rootParent.transform.parent.gameObject;
        }

        _trapController = _rootParent.GetComponent <TrapController>();
    }
示例#10
0
 public void TrapInteract(TrapController contr)
 {
     if (playerInventory.Count > 0)
     {
         // here it would be very helpful if I had made an enum out of the possible items,
         // and used that as a key instead of the Item itself.
         Debug.Log("Trap disabled!");
         contr.isDisabled = true;
     }
 }
示例#11
0
    // Use this for initialization
    void Start()
    {
        trapCtrl = GetComponent<TrapController> ();
                targetsHit = new List<GameObject> ();

                Transform parent = transform.parent;
                while (trapCtrl == null) {
                        trapCtrl = parent.GetComponent<TrapController> ();
                        parent = parent.parent;
                }
    }
示例#12
0
    public override void Activate()
    {
        GameObject trap = instigator.AbilityWantsObject("P_BasicTrap", instigator.transform.position - spawnOffset);

        instigator.EndMoveCrouch();

        TrapController trapController = trap.GetComponent <TrapController>();

        if (trapController != null)
        {
            trapController.SetTrap(instigator);
        }

        base.Activate();
    }
示例#13
0
 void OnTriggerEnter2D(Collider2D coll)
 {
     // The following destroys This trap if a newer one is laid on top
     //Debug.Log ("entered trigger - TRAP");
     if (coll.gameObject.tag == "Trap")         //if a trap is laid over this one
     {
         //Debug.Log ("this trigger is a trap!");
         TrapController tc = coll.gameObject.GetComponent <TrapController>();
         if (age >= tc.GetAge())              //if this is the trap laid down first
         {
             Debug.Log("destroyed old trap!");
             Collide();
         }
     }
 }
 public void ActivateTrap()
 {
     if (thecooldown.trapIsCooldown == false && isEnoughStarTrap == true)
     {
         trapTemp = Instantiate(trap, new Vector3(transform.position.x, transform.position.y, transform.position.z + 0.5f), transform.rotation);
         theTrap  = trapTemp.GetComponent <TrapController>();
         theTrap.setTrapValue(stunTime);
         starUsed = starUsedSet(stunTime);
         thecooldown.trapIsCooldown = true;
         starValue -= starUsed;
         ChekStarValue();
         theUiStarCount.changeStarText(starValue);
     }
     //Debug.Log("Trap Button Pressed");
 }
    // Use this for initialization
    void Start()
    {
        isPromoted  = false;
        MaxEvilness = 100f;
        MinEvilness = 0f;
        //resetting health after every completed level
        currentEvilness = MinEvilness;

        Evilbar.value = calculateEvilness();
        try {
            traps = GameObject.FindWithTag("TrapController").GetComponent <TrapController> ();
            //voice = GameObject.FindWithTag ("TrapController").GetComponent<VoiceCommandController> ();
        } catch (System.Exception ex) {
            print(ex);
        }
    }
示例#16
0
    public PlayState()
    {
        posRecord       = new List <Vector3>();
        ghostController = GameObject.Find("GhostController").GetComponent <GhostController>();
        trapController  = GameObject.Find("TrapController").GetComponent <TrapController>();
        playerCollision = player.GetComponent <PlayerCollision>();

        //プレイヤーがトラップに当たったらステートをDEADにするイベント
        playerCollision.OnDead += delegate(object sender, EventArgs e)
        {
            stateMachine.currentState = StageSequenceMachine.State_StageSequence.DEAD;
        };
        playerCollision.OnReachGoal += delegate(object sender, EventArgs e)
        {
            stateMachine.currentState = StageSequenceMachine.State_StageSequence.EXIT;
        };
    }
示例#17
0
    void ResetGame()
    {
        foreach (GameObject trap in traps)
        {
            TrapController control = trap.GetComponent <TrapController>();
            control.Reset();
        }
        foreach (var storyitem in storyItems)
        {
            storyitem.Reset();
        }
        StoryTextBoxController.Reset();

        gameState = State.Running;
        GameOverText.SetActive(false);
        GameWonText.SetActive(false);
        Player.transform.position = PlayerStartPosition;
        Player.SetActive(true);
    }
    // Start is called before the first frame update
    void Start()
    {
        spriteRenderer = GetComponent <SpriteRenderer>();

        Ballista         = GetComponent <Ballista>();
        Bat              = GetComponent <BatController>();
        BoundTrap        = GetComponent <BoundTrapController>();
        Bush             = GetComponent <BushController>();
        Button           = GetComponent <ButtonController>();
        Crocodile        = GetComponent <CrocodileController>();
        Drop             = GetComponent <DropController>();
        FallingPlataform = GetComponent <FallingPlataform>();
        //Pajaro = GameObject.FindGameObjectsWithTag("").GetComponent<ButtonController>();
        Mole       = GetComponent <MoloController>();
        Mushroom   = GetComponent <MushroomController>();
        Rat        = GetComponent <RatController>();
        Rock       = GetComponent <RockController>();
        RotateTrap = GetComponent <RotateTrapController>();
        Spawner    = GetComponent <Spawner>();
        Spikes     = GetComponent <SpikesController>();
        Thorms     = GetComponent <ThormsController>();
        Trap       = GetComponent <TrapController>();

        spriteRenderer.enabled = false;
        //Ballista.enabled = false;
        Bat.enabled              = false;
        BoundTrap.enabled        = false;
        Bush.enabled             = false;
        Button.enabled           = false;
        Crocodile.enabled        = false;
        Drop.enabled             = false;
        FallingPlataform.enabled = false;
        //Pajaro.enabled = false;
        Mole.enabled       = false;
        Mushroom.enabled   = false;
        Rat.enabled        = false;
        Rock.enabled       = false;
        RotateTrap.enabled = false;
        Spawner.enabled    = false;
        Spikes.enabled     = false;
        Thorms.enabled     = false;
        Trap.enabled       = false;
    }
示例#19
0
    private IEnumerator AllAtOnceTrapsCoroutine(int xStart, int numOfTraps)
    {
        TrapController[] traps = new TrapController[numOfTraps * 2];
        for (int i = 0; i < numOfTraps * 2; i += 2)
        {
            traps[i]            = CreateSpikeTrap(xStart + i / 2, 0, false).GetComponent <TrapController>();
            traps[i + 1]        = CreateSpikeTrap(xStart + i / 2, 1, false).GetComponent <TrapController>();
            traps[i].timeToFire = traps[i + 1].timeToFire = 2;
        }

        while (true)
        {
            for (int i = 0; i < numOfTraps * 2; i += 2)
            {
                traps[i].trigger = traps[i + 1].trigger = true;
            }
            yield return(new WaitForSeconds(4f));
        }
    }
示例#20
0
    private void SendBirdsToTrap(TrapController trap)
    {
        //HashSet<GameObject> trees = gridCon.FindTreeNextToTrap(trap);
        //foreach(GameObject go in trees)
        //{
        //    GrownTree gt = GrownTrees.Concat(OccupiedTrees).ToList().Find(t => t.tree == go);
        //    foreach(GameObject bird in gt.birds)
        //    {
        //        Vector3 randDest = FindRandomDestination(trap);
        //        bird.GetComponent<BirdAI>().AddTrap(trap, randDest);
        //    }
        //}

        foreach (GameObject bird in trap.TargetTree.birds)
        {
            Vector3 randDest = FindRandomDestination(trap);
            bird.GetComponent <BirdAI>().AddTrap(trap, randDest);
        }
    }
示例#21
0
    public HashSet <GameObject> FindTreeNextToTrap(TrapController trap)
    {
        HashSet <GameObject> trees = new HashSet <GameObject>();

        GetXZ(trap.transform.position, out int x, out int z);
        for (int xi = x - 1; xi <= x + 1; xi++)
        {
            for (int zi = z - 1; zi <= z + 1; zi++)
            {
                if (xi != x || zi != z)
                {
                    GameObject go = gridArray[xi, zi].GetGridObject();
                    if (go != null)
                    {
                        trees.Add(go);
                    }
                }
            }
        }
        return(trees);
    }
示例#22
0
 //Assigns skill values to traps
 private void ConfigureTrap(TrapController bc)
 {
     if (range == 0 || dmg == 0)
     {
         print("Check your range and/or dmg!  One might be 0!");
     }
     bc.dmg           = dmg;
     bc.range         = range;
     bc.knockback     = knockback;
     bc.lifeDrain     = lifeDrain;
     bc.poison        = poison;
     bc.poisonDur     = poisonDur;
     bc.splash        = splash;
     bc.splashRad     = splashRad;
     bc.stun          = stun;
     bc.slowdown      = slowdown;
     bc.slowDur       = slowDur;
     bc.penetration   = penetration;
     bc.shieldShred   = shieldShred;
     bc.maxArmingTime = trapArmTime;
 }
示例#23
0
        private void UpdateDps()
        {
            SliderControl  sliderControl           = this.sliders[0];
            TrapController trapController          = Service.Get <TrapController>();
            int            trapDamageForUIDisplay  = trapController.GetTrapDamageForUIDisplay(this.trapVO);
            int            trapDamageForUIDisplay2 = trapController.GetTrapDamageForUIDisplay(this.maxTrapVO);

            sliderControl.DescLabel.Text = this.lang.Get("DAMAGE_DPS", new object[]
            {
                ""
            });
            sliderControl.CurrentLabel.Text   = this.lang.ThousandsSeparated(trapDamageForUIDisplay);
            sliderControl.CurrentSlider.Value = ((trapDamageForUIDisplay2 == 0) ? 0f : ((float)trapDamageForUIDisplay / (float)trapDamageForUIDisplay2));
            if (this.useUpgradeGroup && this.nextTrapVO != null)
            {
                int trapDamageForUIDisplay3 = trapController.GetTrapDamageForUIDisplay(this.nextTrapVO);
                sliderControl.NextLabel.Text = this.lang.Get("PLUS", new object[]
                {
                    this.lang.ThousandsSeparated(trapDamageForUIDisplay3 - trapDamageForUIDisplay)
                });
                sliderControl.NextSlider.Value = ((trapDamageForUIDisplay2 == 0) ? 0f : ((float)trapDamageForUIDisplay3 / (float)trapDamageForUIDisplay2));
            }
        }
示例#24
0
        public TrapCombatTrigger(TrapNode node)
        {
            this.controller        = Service.Get <TrapController>();
            this.comp              = node.TrapComp;
            this.transform         = node.TransformComp;
            this.health            = node.HealthComp;
            this.Owner             = node.Entity;
            this.Type              = CombatTriggerType.Area;
            this.AreaRadius        = 0u;
            this.triggerConditions = node.TrapComp.Type.ParsedTrapConditions;
            int i     = 0;
            int count = this.triggerConditions.Count;

            while (i < count)
            {
                if (this.triggerConditions[i] is RadiusTrapCondition)
                {
                    this.Type       = CombatTriggerType.Area;
                    this.AreaRadius = ((RadiusTrapCondition)this.triggerConditions[i]).Radius;
                }
                i++;
            }
        }
示例#25
0
 public void ScaleProps(float pcent)
 {
     Debug.Log("called ScaleProps");
     if (aoeBulletCon != null)
     {
         BulletController bc = aoeBulletCon;
         Debug.Log("old slowdown: " + bc.slowdown);
         bc.dmg         *= pcent;
         bc.poison      *= pcent;
         bc.lifeDrain   *= pcent;
         bc.slowdown    *= pcent;
         bc.shieldShred *= pcent;
         Debug.Log("new slowdown: " + bc.slowdown);
     }
     else if (aoeTrapCon != null)
     {
         TrapController tc = aoeTrapCon;
         tc.dmg         *= pcent;
         tc.poison      *= pcent;
         tc.lifeDrain   *= pcent;
         tc.slowdown    *= pcent;
         tc.shieldShred *= pcent;
     }
 }
示例#26
0
 private void Start()
 {
     Controller = GetComponentInParent <TrapController>();
     Trap       = GetComponent <Transform>();
 }
示例#27
0
 // Use this for initialization
 void Start()
 {
     trapController = GetComponent <TrapController>();
 }
示例#28
0
    // private bool m_cursorState = false;

    // Start is called before the first frame update
    void Start()
    {
        // initialize handtrap
        var pos = this.transform.position + this.transform.forward * 4.0f;

        pos.y                           = 1.5f;
        m_handTrap                      = GameObject.Instantiate(m_trap, pos, this.transform.rotation);
        m_handTrapController            = m_handTrap.GetComponent <TrapController>();
        m_handTrapController.IsHandTrap = true;
        m_handTrap.SetActive(false);

        m_animator = GetComponent <Animator>();

        MessageDispacher.Instance.Register(GameObjectMessage.QueryPlayerPosition, msg =>
        {
            var result = msg as PlayerPositionQueryResult;
            if (Vector3.Distance(this.transform.position, StrongPoint.Instance.Position) < EnemyConfigure.StrongPointAttackDistance &&
                PlayerInfo.LocalPlayer.Hp > 0)
            {
                result.PlayerInfoList.Add(PlayerInfo.LocalPlayer);
                result.PlayerPositionList.Add(this.transform.position);
            }
        });

        var shoottingOverBehaviour = m_animator.GetBehaviour <ShootingOverBehaviour>();

        shoottingOverBehaviour.CallBack = () =>
        {
            m_animator.SetBool("Shooting", false);
        };

        var rechargeOverBehaiour = m_animator.GetBehaviour <RechargeOverBehaviour>();

        rechargeOverBehaiour.CallBack = () =>
        {
            m_animator.SetBool("Recharge", false);
        };

        var deathOverBehaviour = m_animator.GetBehaviour <DeathOverBehaviour>();

        deathOverBehaviour.CallBack = () =>
        {
            // m_animator.SetBool("Death", false);
        };

        var damagedBehaviour = m_animator.GetBehaviour <DamangedOverBehaviour>();

        damagedBehaviour.CallBack = () =>
        {
            m_animator.SetBool("Damaged", false);
        };

        var throwBehaviour = m_animator.GetBehaviour <ThrowOverBehaviour>();

        throwBehaviour.CallBack = () =>
        {
            m_animator.SetBool("Throw", false);
        };


        m_networkService.Register(NetWorkCommandType.RechargeResult, cmd =>
        {
            m_animator.SetBool("Recharge", true);

            var cmdRechargeResult = cmd as RechargeResultCommand;

            PlayerInfo.LocalPlayer.CurrentBulletCapacity = cmdRechargeResult.CurrentBulletCount;
            PlayerInfo.LocalPlayer.MaxBulletCapacity     = cmdRechargeResult.MaxBulletCount;

            // update ui
            MessageDispacher.Instance.Send(UIMessage.UpdateBulletUI, new BulletUpdateMessage
            {
                CurrentBulletCount = cmdRechargeResult.CurrentBulletCount,
                MaxBulletCount     = cmdRechargeResult.MaxBulletCount,
            });

            m_isWaitingResult = false;
        });

        m_networkService.Register(NetWorkCommandType.RecoverHp, cmd =>
        {
            var cmdRecover = cmd as RecoverHpCommand;

            // update ui
            if (cmdRecover.UserID == PlayerInfo.LocalPlayer.UserID)
            {
                PlayerInfo.LocalPlayer.Hp = cmdRecover.Hp;
                MessageDispacher.Instance.Send(UIMessage.UpdateHpUI, cmdRecover.Hp / 1000.0f);
            }
        });

        m_networkService.Register(NetWorkCommandType.SupplyBullets, cmd =>
        {
            var cmdSupply = cmd as SupplyBulletsCommand;
            if (cmdSupply.UserID == PlayerInfo.LocalPlayer.UserID)
            {
                PlayerInfo.LocalPlayer.CurrentBulletCapacity = cmdSupply.CurrentBulletCapacity;
                PlayerInfo.LocalPlayer.MaxBulletCapacity     = cmdSupply.MaxBulletCapacity;

                // update ui
                MessageDispacher.Instance.Send(UIMessage.UpdateBulletUI, new BulletUpdateMessage
                {
                    CurrentBulletCount = cmdSupply.CurrentBulletCapacity,
                    MaxBulletCount     = cmdSupply.MaxBulletCapacity,
                });
            }
        });

        m_networkService.Register(NetWorkCommandType.RunningShooting, cmd =>
        {
            var cmdFan = cmd as RunningShootingCommand;
            if (cmdFan.UserID == PlayerInfo.LocalPlayer.UserID)
            {
                PlayerInfo.LocalPlayer.ShootingType = ShoottingType.Running;
            }
        });

        m_networkService.Register(NetWorkCommandType.EnemyBulletHitResult, cmd =>
        {
            var cmdHit = cmd as EnemyBulletHitResultCommand;
            if (cmdHit.PlayerID == PlayerInfo.LocalPlayer.UserID)
            {
                PlayerInfo.LocalPlayer.Hp = cmdHit.PlayerHp;

                // update ui
                MessageDispacher.Instance.Send(UIMessage.UpdateHpUI, cmdHit.PlayerHp / 1000.0f);
                m_animator.SetBool("Damaged", true);
            }
        });

        m_networkService.Register(NetWorkCommandType.PlayerDie, cmd =>
        {
            var cmdDie = cmd as PlayerDieCommand;
            if (cmdDie.PlayerID == PlayerInfo.LocalPlayer.UserID)
            {
                m_animator.SetBool("Death", true);
                // m_deathCount = PlayerConfigure.RebornWaitingTime;

                // MessageDispacher.Instance.Send(UIMessage.ShowRebornProgress, null);
                // MessageDispacher.Instance.Send(UIMessage.UpdateRebornProgress, 1.0f);
            }
        });

        m_networkService.Register(NetWorkCommandType.PlayerRebornResult, cmd =>
        {
            var cmdReborn = cmd as PlayerRebornResultCommand;
            if (cmdReborn.PlayerID == PlayerInfo.LocalPlayer.UserID)
            {
                PlayerInfo.LocalPlayer.Hp = cmdReborn.Hp;
                PlayerInfo.LocalPlayer.MaxBulletCapacity     = cmdReborn.MaxBulletCount;
                PlayerInfo.LocalPlayer.CurrentBulletCapacity = cmdReborn.CurBulletCount;

                m_animator.SetBool("Death", false);

                // update ui
                MessageDispacher.Instance.Send(UIMessage.UpdateHpUI, cmdReborn.Hp / 1000.0f);
                MessageDispacher.Instance.Send(UIMessage.UpdateBulletUI, new BulletUpdateMessage
                {
                    CurrentBulletCount = cmdReborn.CurBulletCount,
                    MaxBulletCount     = cmdReborn.MaxBulletCount,
                });

                MessageDispacher.Instance.Send(
                    UIMessage.HideRebornProgress, null);
            }
        });

        m_networkService.Register(NetWorkCommandType.GunShootResult, cmd =>
        {
            var cmdGunShootResult = cmd as GunShootResultCommand;
            if (cmdGunShootResult.ShooterID == PlayerInfo.LocalPlayer.UserID)
            {
                PlayerInfo.LocalPlayer.MaxBulletCapacity     = cmdGunShootResult.MaxBullet;
                PlayerInfo.LocalPlayer.CurrentBulletCapacity = cmdGunShootResult.CurrentBullet;

                // update ui
                MessageDispacher.Instance.Send(UIMessage.UpdateBulletUI, new BulletUpdateMessage
                {
                    CurrentBulletCount = cmdGunShootResult.CurrentBullet,
                    MaxBulletCount     = cmdGunShootResult.MaxBullet,
                });

                m_isWaitingResult = false;
            }
        });

        m_networkService.Register(NetWorkCommandType.PutTrapResult, cmd =>
        {
            var cmdPutTrapResult = cmd as PutTrapResultCommand;
            if (cmdPutTrapResult.BuilderID == PlayerInfo.LocalPlayer.UserID)
            {
                GameObject trapObject = null;
                if (cmdPutTrapResult.TrapType == TrapType.Damage)
                {
                    trapObject = m_damageTrap;
                    PlayerInfo.LocalPlayer.DamageTrapCount = cmdPutTrapResult.TrapCount;
                }
                else if (cmdPutTrapResult.TrapType == TrapType.SlowDown)
                {
                    trapObject = m_slowDownTrap;
                    PlayerInfo.LocalPlayer.SlowTrapCount = cmdPutTrapResult.TrapCount;
                }

                // update ui
                MessageDispacher.Instance.Send(UIMessage.UpdateTrapCount, new TrapCountUpdateMessage
                {
                    DamageTrapCount = PlayerInfo.LocalPlayer.DamageTrapCount,
                    SlowTrapCount   = PlayerInfo.LocalPlayer.SlowTrapCount
                });

                var newTrap           = GameObject.Instantiate(trapObject, cmdPutTrapResult.Position, Quaternion.AngleAxis(cmdPutTrapResult.Rotation, Vector3.up));
                var scriptComp        = newTrap.GetComponent <TrapController>();
                scriptComp.IsHandTrap = false;
                scriptComp.TrapInfo   = new TrapInfo()
                {
                    TrapType = cmdPutTrapResult.TrapType,
                    ID       = cmdPutTrapResult.TrapID,
                };

                m_isWaitingResult = false;
            }
        });

        m_networkService.Register(NetWorkCommandType.EnemyAttackResult, OnEnemyAttackResult);

        m_networkService.Register(NetWorkCommandType.EnemyGunShootResult, OnEnemyGunShootResult);

        m_networkService.Register(NetWorkCommandType.SelfDestructResult, OnSelfDestructResult);

        m_networkService.Register(NetWorkCommandType.DriveTankResult, OnDriveTankResult);

        m_networkService.Register(NetWorkCommandType.ShootResult, OnShootResult);

        m_networkService.Register(NetWorkCommandType.BuyTrapResult, cmd =>
        {
            var cmdResult = cmd as BuyTrapResultCommand;

            PlayerInfo.LocalPlayer.DamageTrapCount = cmdResult.DamageTrapCount;
            PlayerInfo.LocalPlayer.SlowTrapCount   = cmdResult.SlowTrapCount;
            PlayerInfo.LocalPlayer.Gold            = cmdResult.Gold;

            MessageDispacher.Instance.Send(UIMessage.UpdateGold, PlayerInfo.LocalPlayer.Gold);
            MessageDispacher.Instance.Send(UIMessage.UpdateTrapCount, new TrapCountUpdateMessage
            {
                DamageTrapCount = PlayerInfo.LocalPlayer.DamageTrapCount,
                SlowTrapCount   = PlayerInfo.LocalPlayer.SlowTrapCount
            });
            m_isWaitingResult = false;
        });

        m_networkService.Register(NetWorkCommandType.BuyGrenateResult, cmd =>
        {
            var cmdResult = cmd as BuyGrenadeResultCommand;

            PlayerInfo.LocalPlayer.GrenadeCount = cmdResult.GrenateCount;
            PlayerInfo.LocalPlayer.Gold         = cmdResult.Gold;

            MessageDispacher.Instance.Send(UIMessage.UpdateGold, PlayerInfo.LocalPlayer.Gold);
            MessageDispacher.Instance.Send(UIMessage.UpdateGrenate, PlayerInfo.LocalPlayer.GrenadeCount);

            m_isWaitingResult = false;
        });

        MessageDispacher.Instance.Register(GameObjectMessage.SwitchCursorState, msg =>
        {
            var state = (bool)msg;
            // m_cursorState = state;
        });
    }
示例#29
0
    public void HandleEvent(GameEvent ge)
    {
        //various conditions under which bullet shouldn't fire
        if ((int)ge.args [0] != buttonID)
        {
            //Debug.Log ("not tower " + buttonID);
            return;
        }
        if (cooldown > 0)
        {
            Debug.Log("cooldown > 0");
            return;
        }
        if (GameObject.Find("Dial").GetComponent <SpinScript> ().IsSpinning())
        {
            Debug.Log("dial is spinning");
            return;
        }
        if (transform.gameObject.activeSelf != true)
        {
            Debug.Log("we're not active");
            return;
        }

        cooldown = maxcool;         //start cooldown

        //Decide what to do based on tower type ("Bullet", "Trap", or "Shield")
        switch (towerType)
        {
        case "Bullet":
            switch (spread)
            {
            case 1:
                SpawnBulletI();
                break;

            case 2:
                SpawnBulletV();
                break;

            case 3:
                if (shootingV)
                {
                    SpawnBulletV();
                    shootingV = false;
                }
                else if (!shootingV)
                {
                    SpawnBulletI();
                    shootingV = true;
                }
                break;

            case 4:
                SpawnBulletI();
                SpawnBulletWideV();
                break;

            default:
                Debug.Log("Spread error in GunController Bullet firing");
                break;
            }
            //Debug.Log ("it's a bullet yo (spread is " + spread + ")");

            /*
             * if (spread == 1 || spread == 2 || spread == 4)
             * {
             *      if (spread == 4)
             *      {
             *              for (int i = 1; i <= 3; i++)
             *              {
             *                      Debug.Log ("called instantiate bullet");
             *                      GameObject bullet = Instantiate (Resources.Load ("Prefabs/Bullet")) as GameObject; //make a bullet
             *                      BulletController bc = bullet.GetComponent<BulletController>();
             *                      //make it the type of bullet this thing fires
             *                      ConfigureBullet (bc);
             *                      //find your angle
             *                      float ownangle = this.transform.eulerAngles.z;
             *                      float angle = (ownangle +  90) % 360 ;
             *                      angle *= (float)Math.PI / 180;
             *                      Debug.Log ("original angle: " + angle);
             *                      angle = (angle - (float)Math.PI / 6f) + ((((float)Math.PI / 3f) / (spread + 1)) * i); //handles spread effect
             *                      //find where to spawn the bullet
             *                      float gunDistFromCenter = (float)Math.Sqrt (transform.position.x*transform.position.x + transform.position.y*transform.position.y);
             *                      gunDistFromCenter += 0.47f;
             *                      bc.spawnx = gunDistFromCenter * (float)Math.Cos (angle);
             *                      bc.spawny = gunDistFromCenter * (float)Math.Sin (angle);
             *                      //Debug.Log (bc.speed);
             *                      bc.transform.position = new Vector3(bc.spawnx,bc.spawny,bc.transform.position.z);
             *                      bc.transform.rotation = transform.rotation;
             *                      bc.vx = bc.speed * (float)Math.Cos(angle);
             *                      bc.vy = bc.speed * (float)Math.Sin(angle);
             *              }
             *      }
             *
             *      else if (spread == 1 || spread == 2)
             *      {
             *              for (int i = 1; i <= spread; i++)
             *              {
             *                      Debug.Log ("called instantiate bullet");
             *                      GameObject bullet = Instantiate (Resources.Load ("Prefabs/Bullet")) as GameObject; //make a bullet
             *                      BulletController bc = bullet.GetComponent<BulletController>();
             *                      //make it the type of bullet this thing fires
             *                      ConfigureBullet (bc);
             *                      //find your angle
             *                      float ownangle = this.transform.eulerAngles.z;
             *                      float angle = (ownangle +  90) % 360 ;
             *                      angle *= (float)Math.PI / 180;
             *                      Debug.Log ("original angle: " + angle);
             *                      angle = (angle - (float)Math.PI / 6f) + ((((float)Math.PI / 3f) / (spread + 1)) * i); //handles spread effect
             *                      //find where to spawn the bullet
             *                      float gunDistFromCenter = (float)Math.Sqrt (transform.position.x*transform.position.x + transform.position.y*transform.position.y);
             *                      gunDistFromCenter += 0.47f;
             *                      bc.spawnx = gunDistFromCenter * (float)Math.Cos (angle);
             *                      bc.spawny = gunDistFromCenter * (float)Math.Sin (angle);
             *                      //Debug.Log (bc.speed);
             *                      bc.transform.position = new Vector3(bc.spawnx,bc.spawny,bc.transform.position.z);
             *                      bc.transform.rotation = transform.rotation;
             *                      bc.vx = bc.speed * (float)Math.Cos(angle);
             *                      bc.vy = bc.speed * (float)Math.Sin(angle);
             *              }
             *      }
             *
             * }
             */

            break;

        case "Trap":
            for (int i = 1; i <= spread; i++)
            {
                GameObject     trap = Instantiate(Resources.Load("Prefabs/Trap")) as GameObject;               //make a trap
                TrapController tp   = trap.GetComponent <TrapController>();
                //make it the type of trap this thing deploys
                ConfigureTrap(tp);
                //find your angle
                float trapOwnangle = this.transform.eulerAngles.z;
                float trapAngle    = (trapOwnangle + 90) % 360;
                trapAngle *= (float)Math.PI / 180;
                trapAngle  = (trapAngle - (float)Math.PI / 6f) + ((((float)Math.PI / 3f) / (spread + 1)) * i);                //handles spread effect
                //find where to spawn the trap *****IMPLEMENT LANE-LENGTH AT SOME POINT
                float trapSpawnRange = range;
                trapSpawnRange *= TRACK_LENGTH;
                tp.spawnx       = trapSpawnRange * (float)Math.Cos(trapAngle);
                tp.spawny       = trapSpawnRange * (float)Math.Sin(trapAngle);
            }
            break;

        case "Shield":
            DialController dialCon = GameObject.Find("Dial").gameObject.GetComponent <DialController>();
            if (dialCon.IsShielded(GetCurrentLaneID() - 1))              //if there's already a shield there
            {
                dialCon.DestroyShield(GetCurrentLaneID() - 1);           //destroy that shield
                Debug.Log("destroyed previous shield");
            }
            GameObject       shield = Instantiate(Resources.Load("Prefabs/Shield")) as GameObject;         //make a shield
            ShieldController sc     = shield.GetComponent <ShieldController>();
            //make it the type of shield this thing deploys
            ConfigureShield(sc);
            //find your angle
            float shieldOwnangle = this.transform.eulerAngles.z;
            float shieldAngle    = (shieldOwnangle + 90) % 360;
            shieldAngle *= (float)Math.PI / 180;
            //find where to spawn the shield
            float shieldSpawnRange = shieldRange;
            shieldSpawnRange += 0.5f;
            sc.spawnx         = shieldSpawnRange * (float)Math.Cos(shieldAngle);
            sc.spawny         = shieldSpawnRange * (float)Math.Sin(shieldAngle);
            sc.gameObject.transform.rotation = this.gameObject.transform.rotation;
            dialCon.PlaceShield(GetCurrentLaneID() - 1, shield);              //mark current lane as shielded (placed in array)
            break;

        default:
            print("Uh oh, I didn't receive a valid towerType string value!");
            Debug.Log("value is: " + towerType);
            break;
        }
    }
示例#30
0
 public void AddTrapInGame(TrapController aTrap)
 {
     trapsInGame.Add(aTrap);
 }
示例#31
0
 public void AddTrap(TrapController trap)
 {
     traps.Add(trap);
     SendBirdsToTrap(trap);
 }
示例#32
0
 //Assigns skill values to traps
 private void ConfigureTrap(TrapController bc)
 {
     if (range == 0 || dmg == 0)
         print ("Check your range and/or dmg!  One might be 0!");
     bc.dmg = dmg;
     bc.range = range;
     bc.knockback = knockback;
     bc.lifeDrain = lifeDrain;
     bc.poison = poison;
     bc.poisonDur = poisonDur;
     bc.splash = splash;
     bc.splashRad = splashRad;
     bc.stun = stun;
     bc.slowdown = slowdown;
     bc.slowDur = slowDur;
     bc.penetration = penetration;
     bc.shieldShred = shieldShred;
     bc.maxArmingTime = trapArmTime;
 }
示例#33
0
 public void RemoveTrap(TrapController trap)
 {
     traps.Remove(trap);
 }