Example #1
0
 public void SetBuildInfo(BuildInfo info, TrapViewListWnd wnd, TrapState trapState, int ItemType = 1)
 {
     myParent    = wnd;
     m_Info      = info;
     m_ItemType  = ItemType;
     m_TrapState = trapState;
 }
Example #2
0
 protected void Start()
 {
     currentState              = TrapState.Active;
     reset                     = Instantiate(resetSign, gameObject.transform);
     reset.transform.position += new Vector3(0, 2, 0);
     reset.SetActive(false);
 }
Example #3
0
    // Use this for initialization
    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player");
        Saw.transform.position = startPosition.transform.position;

        state = TrapState.Idle;
    }
Example #4
0
 public void OnTriggerEnter(Collider other)
 {
     if (m_State == TrapState.IDLE)
     {
         GameObject gO = other.gameObject;
         if (gO.CompareTag(ConstValues.PLAYER_TAG))
         {
             //TODO: Kill Player
             PlayerController playerControl = gO.GetComponent <PlayerController>();
             if (playerControl != null)
             {
                 playerControl.OnDeath();
             }
             m_State = TrapState.TRIGGERED;
         }
         else if (gO.CompareTag(ConstValues.AI_RUNNER_TAG))
         {
             //TODO: Kill Runner
             AIRunnerBehaviour aiBehav = gO.GetComponent <AIRunnerBehaviour>();
             if (aiBehav != null)
             {
                 aiBehav.Kill();
             }
             m_State = TrapState.TRIGGERED;
         }
     }
 }
Example #5
0
    void checkState()
    {
        switch (m_State)
        {
        case TrapState.ACTIVE:
            m_FireParticles.SetActive(true);
            m_Timer -= Time.deltaTime;
            if (m_Timer <= 0.0f)
            {
                m_FireParticles.SetActive(false);
                m_State = TrapState.RESETTING;
            }
            break;

        case TrapState.DISABLED:
            break;

        case TrapState.IDLE:
            break;

        case TrapState.RESETTING:
            m_Timer         = m_ResetTimer;
            m_State         = TrapState.IDLE;
            m_DetectedTimer = m_ResetTimer;
            break;

        case TrapState.TRIGGERED:
            m_State = TrapState.ACTIVE;
            break;
        }
    }
Example #6
0
	// Update is called once per frame
	void Update () {
		if (trapState == TrapState.Ready) {
			spring.distance = 0.25f;
			spring.enabled = true;
			trapBody.constraints = RigidbodyConstraints2D.FreezeAll;
		}

		if (trapState == TrapState.Falling || trapState == TrapState.Down) {
			spring.enabled = false;
			trapBody.constraints = RigidbodyConstraints2D.FreezeAll ^ RigidbodyConstraints2D.FreezePositionY;
		}

//		if (trapState == TrapState.Falling && trapBody.velocity.magnitude < 1e-2f) {
//			trapState = TrapState.Down;
//		}

		if (trapState == TrapState.Rising) {
			trapBody.constraints = RigidbodyConstraints2D.FreezeAll ^ RigidbodyConstraints2D.FreezePositionY;
			spring.distance = 0.25f;
			spring.enabled = true;
			if (trapBody.velocity.magnitude < 1e-2f && Vector2.Distance (spring.connectedBody.transform.TransformPoint(spring.connectedAnchor), trapBody.position) < 1f) {
				trapState = TrapState.Ready;
			}
		}
	}
Example #7
0
	// Use this for initialization
	void Start () {
		trapBody = this.transform.GetComponent<Rigidbody2D> ();
		trapState = TrapState.Ready;
		spring = this.transform.GetComponent<SpringJoint2D> ();
		spring.distance = 0.25f;
		spring.enabled = true;
	}
Example #8
0
        public void SetTrapState(TrapComponent comp, TrapState state)
        {
            SmartEntity       smartEntity  = (SmartEntity)comp.Entity;
            TrapViewComponent trapViewComp = smartEntity.TrapViewComp;
            TrapState         currentState = comp.CurrentState;

            if (currentState != state)
            {
                comp.CurrentState = state;
                IState currentState2 = Service.Get <GameStateMachine>().CurrentState;
                if (TrapUtils.IsCurrentPlayerInDefensiveBattle(currentState2))
                {
                    smartEntity.BuildingComp.BuildingTO.CurrentStorage = ((state == TrapState.Armed) ? 1 : 0);
                }
                Service.Get <TrapViewController>().UpdateTrapVisibility((SmartEntity)comp.Entity);
                switch (state)
                {
                case TrapState.Spent:
                    Service.Get <EventManager>().SendEvent(EventId.TrapDisarmed, comp);
                    break;

                case TrapState.Active:
                    Service.Get <EventManager>().SendEvent(EventId.TrapTriggered, comp);
                    break;

                case TrapState.Destroyed:
                    comp.CurrentState = TrapState.Spent;
                    Service.Get <EventManager>().SendEvent(EventId.TrapDestroyed, comp);
                    break;
                }
            }
            Service.Get <TrapViewController>().SetTrapViewState(trapViewComp, state);
        }
Example #9
0
 public void OnTriggerEnter(Collider other)
 {
     if (m_State == TrapState.IDLE)
     {
         GameObject gO = other.gameObject;
         if (gO.CompareTag(ConstValues.PLAYER_TAG))
         {
             //TODO: Kill Player
             PlayerController playerControl = gO.GetComponent<PlayerController>();
             if (playerControl != null)
             {
                 playerControl.OnDeath();
             }
             m_State = TrapState.TRIGGERED;
         }
         else if (gO.CompareTag(ConstValues.AI_RUNNER_TAG))
         {
             //TODO: Kill Runner
             AIRunnerBehaviour aiBehav = gO.GetComponent<AIRunnerBehaviour>();
             if (aiBehav != null)
             {
                 aiBehav.Kill();
             }
             m_State = TrapState.TRIGGERED;
         }
     }
 }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        if (trapState == TrapState.Ready)
        {
            spring.distance      = 0.25f;
            spring.enabled       = true;
            trapBody.constraints = RigidbodyConstraints2D.FreezeAll;
        }

        if (trapState == TrapState.Falling || trapState == TrapState.Down)
        {
            spring.enabled       = false;
            trapBody.constraints = RigidbodyConstraints2D.FreezeAll ^ RigidbodyConstraints2D.FreezePositionY;
        }

//		if (trapState == TrapState.Falling && trapBody.velocity.magnitude < 1e-2f) {
//			trapState = TrapState.Down;
//		}

        if (trapState == TrapState.Rising)
        {
            trapBody.constraints = RigidbodyConstraints2D.FreezeAll ^ RigidbodyConstraints2D.FreezePositionY;
            spring.distance      = 0.25f;
            spring.enabled       = true;
            if (trapBody.velocity.magnitude < 1e-2f && Vector2.Distance(spring.connectedBody.transform.TransformPoint(spring.connectedAnchor), trapBody.position) < 1f)
            {
                trapState = TrapState.Ready;
            }
        }
    }
Example #11
0
 /// <summary>
 /// Меняет состояние ловушки с временной задержкой
 /// </summary>
 /// <returns></returns>
 IEnumerator ChangeState()
 {
     while (true)
     {
         if (state == TrapState.down)
         {
             state             = TrapState.middle;
             _collider.enabled = false;
             if (light != null)
             {
                 light.enabled = false;
             }
         }
         else if (state == TrapState.middle)
         {
             state             = TrapState.up;
             _collider.enabled = true;
             if (light != null)
             {
                 light.enabled = true;
             }
         }
         else
         {
             state             = TrapState.down;
             _collider.enabled = false;
             if (light != null)
             {
                 light.enabled = false;
             }
         }
         sr.sprite = sprites[(int)state];
         yield return(new WaitForSecondsRealtime(1f));
     }
 }
    private void SetTrapState(TrapState value)
    {
        switch (value)
        {
        case TrapState.Open:
            trapOpen.SetActive(true);
            trapClosed.SetActive(false);
            m_trapCooldown        = 0f;
            openAnimation.enabled = true;
            break;

        case TrapState.Closed:
            trapOpen.SetActive(false);
            trapClosed.SetActive(true);
            trapClosed.layer       = LayerMask.NameToLayer("Robots");
            m_trapCooldown         = trapCooldown;
            closeAnimation.enabled = true;
            break;

        case TrapState.ClosedTrapped:
            trapOpen.SetActive(false);
            trapClosed.SetActive(true);
            trapClosed.layer       = LayerMask.NameToLayer("Blocker");
            closeAnimation.enabled = true;
            break;

        default:
            throw new ArgumentOutOfRangeException("value", value, null);
        }

        m_trapState = value;
    }
Example #13
0
    private void InitialzeStateManager()
    {
        _stateManager = new StateManager(_muffinAnimator);

        IdleState 		idle = new IdleState(_stateManager, transform);
        MoveState 		move = new MoveState(_stateManager, transform);
        TrapState 		trap = new TrapState(_stateManager, transform);
        DieState 		die	= new DieState(_stateManager, transform);
        SpinState		spin = new SpinState(_stateManager, transform);
        BlastState		blast = new BlastState(_stateManager, transform);
        ChocoRushState	chocoRush = new ChocoRushState(_stateManager, transform);

        PauseState		pause = new PauseState(_stateManager, transform);

        _stateManager.AddCharacterState(idle);
        _stateManager.AddCharacterState(move);
        _stateManager.AddCharacterState(trap);
        _stateManager.AddCharacterState(die);
        _stateManager.AddCharacterState(spin);
        _stateManager.AddCharacterState(blast);
        _stateManager.AddCharacterState(chocoRush);

        _stateManager.AddCharacterState(pause);

        _stateManager.SetDefaultState("Pause");
    }
Example #14
0
 // Use this for initialization
 void Start()
 {
     TriggerRange  = transform.parent.GetComponent <GenericTrigger>();
     startPosition = this.transform.position;
     player        = GameObject.FindGameObjectWithTag("Player");
     state         = TrapState.Idle;
 }
Example #15
0
    void checkState()
    {
        switch (m_State)
        {
        case TrapState.ACTIVE:
            // Make Block Fall / Disappear
            //Debug.Log("PITFALLLLLL");
            m_Parent.GetComponent <MeshRenderer>().enabled = false;
            m_Parent.GetComponent <BoxCollider>().enabled  = false;
            m_State = TrapState.DISABLED;
            break;

        case TrapState.DISABLED:
            // Pitfall forever
            break;

        case TrapState.IDLE:
            break;

        case TrapState.RESETTING:
            m_Parent.GetComponent <MeshRenderer>().enabled = true;
            m_Parent.GetComponent <BoxCollider>().enabled  = true;
            m_State = TrapState.IDLE;
            break;

        case TrapState.TRIGGERED:
            m_State = TrapState.ACTIVE;
            break;
        }
    }
Example #16
0
        public bool TriggerTrap(int[] explorerPosition)
        {
            if (Position[0] != explorerPosition[0] || Position[1] != explorerPosition[1])
            {
                return(false);
            }

            if (PlayScene.Random.Next(1, 3) == 1)
            {
#if DEBUG
                Main.InsertLog("Explorer: Agrrrr!!!");
#endif
                SoundController.PlaySound(PlayContentHolder.Instance.SoundRock);
                rock   = new CModel(PlayContentHolder.Instance.ModelRock, new Vector3(Position[1] * 10 + 5, 36, Position[0] * 10 + 5));
                _state = TrapState.Rock;
                _parent.Explorer.Shock();
                timeline = 90;
            }
            else
            {
#if DEBUG
                Main.InsertLog("Explorer: Aaaaa....");
#endif
                SoundController.PlaySound(PlayContentHolder.Instance.SoundPit);
                _state = TrapState.Hole;
                _parent.Floor.HideMesh(Position[0] * _parent.MazeSize + Position[1]);
                _parent.Explorer.Fall();
            }

            return(true);
        }
Example #17
0
 public void TriggerTrap()
 {
     if (State == TrapState.Armed)
     {
         activationTime = Time.time;
         State          = TrapState.Triggered;
     }
 }
Example #18
0
        public void AddTrapComponentsToEntity(Entity buildingEntity, BuildingTypeVO buildingType)
        {
            TrapTypeVO    type           = Service.Get <IDataController>().Get <TrapTypeVO>(buildingType.TrapUid);
            TrapState     currentStorage = (TrapState)buildingEntity.Get <BuildingComponent>().BuildingTO.CurrentStorage;
            TrapComponent component      = new TrapComponent(type, currentStorage);

            buildingEntity.Add(component);
        }
Example #19
0
 void OnCollisionEnter(Collision collision)
 {
     Debug.Log("WE HIT LAND!");
     if (state == TrapState.Active)
     {
         state = TrapState.Reload;
     }
 }
Example #20
0
 public void RaiseTrap()
 {
     if (trapState == TrapState.Down)
     {
         Debug.Log("Raising trap");
         trapState = TrapState.Rising;
     }
 }
Example #21
0
 void Awake()
 {
     _collider = GetComponent <BoxCollider2D>();
     light     = GetComponentInChildren <Light>();
     sr        = GetComponent <SpriteRenderer>();
     state     = TrapState.down;
     StartCoroutine(ChangeState());
 }
Example #22
0
 protected void TryReset()
 {
     if (CanReset && ResetRequested && Time.time > activationTime + HoldAnimTime)
     {
         activationTime = Time.time;
         State          = TrapState.Resetting;
     }
 }
Example #23
0
 public void DropTrap()
 {
     if (trapState == TrapState.Ready)
     {
         Debug.Log("Dropping trap");
         trapState = TrapState.Falling;
     }
 }
Example #24
0
 private void TryFire()
 {
     if (Time.time > activationTime + TriggerDelay)
     {
         activationTime = Time.time;
         State          = TrapState.Firing;
     }
 }
Example #25
0
 // Use this for initialization
 void Start()
 {
     trapBody        = this.transform.GetComponent <Rigidbody2D> ();
     trapState       = TrapState.Ready;
     spring          = this.transform.GetComponent <SpringJoint2D> ();
     spring.distance = 0.25f;
     spring.enabled  = true;
 }
Example #26
0
 protected override void OnDisable()
 {
     base.OnDisable();
     state = TrapState.NormalState;
     enemiesInRange.Clear();
     hasWaitedForAttackHitDelay = false;
     isWaitingForCooldown       = false;
     currentEnemy = null;
 }
Example #27
0
 void OnTriggerEnter(Collider other)
 {
     Debug.Log("SawBlade Triggered!");
     if (other.tag == "Player")
     {
         //Player is here, fire the Saw
         state = TrapState.Active;
     }
 }
Example #28
0
 void SetTrapGrounded()
 {
     trapParabola.enabled = false;
     //slimeAnim.SetBool("IsOnGround", true);//set the animator to do the ground animation
     slimeRB.velocity = Vector2.zero; //no sliding
     landed           = true;         //set the ice cream to armed
     audioManager.PlaySound(landSound);
     _stateOfTrap = TrapState.grounded;
 }
Example #29
0
        protected void TriggerComplete()
        {
            //No longer triggering
            state = TrapState.Idle;

            if (autoRearm)
            {
                Rearm();
            }
        }
Example #30
0
 void Idle()
 {
     //Is the player nearby?
     if (TriggerRange.isTouchingPlayer)
     {
         //Yes, trigger the trap
         state    = TrapState.Active;
         this.tag = "HurtBox";
     }
 }
Example #31
0
 void OnTriggerExit(Collider other)
 {
     Debug.Log("SawBlade Exit");
     if (other.tag == "Player")
     {
         //Player left, reset the trap
         //Saw.transform.position = startPosition.transform.position;
         state = TrapState.Reload;
     }
 }
Example #32
0
    /// <summary>
    /// 创建已召唤炮弹兵
    /// </summary>
    private void CreateTrap(List <BuildInfo> BuildList, TrapState trapState)
    {
        if (trapState == TrapState.Exit)
        {
            m_canShengji = null;
        }
        if (BuildList == null || BuildList.Count == 0)
        {
            return;
        }
        if (MyHead.Parent == null)
        {
            NGUIUtil.DebugLog("ShipCanvasDialogWnd ListParent!!!");
            return;
        }

        if (trapState == TrapState.CanNotSum)
        {
            CreateBanner();
        }

        PdbbbItem pbbItem = null;
        int       count   = 0;

        for (int i = 0; i < BuildList.Count; i++)
        {
            if (count % 4 == 0)
            {
                pbbItem = null;
                GameObject go = NDLoad.LoadWndItem("PdbbbItem", MyHead.Parent.transform);
                pbbItem = go.GetComponent <PdbbbItem>();
            }
            count++;
            if (pbbItem != null && pbbItem.MyHead.Table != null)
            {
                GameObject viewgo = NDLoad.LoadWndItem("TrapViewItem", pbbItem.MyHead.Table.transform);
                if (viewgo != null)
                {
                    TrapViewItem item = viewgo.GetComponent <TrapViewItem>();
                    if (item != null)
                    {
                        item.SetBuildInfo(BuildList[i], this, trapState);
                        if (null == m_canShengji && trapState == TrapState.Exit)
                        {
                            CanLevelResult LevResult = buildingM.GetLevelCanUP(BuildList[i]);
                            if (LevResult == CanLevelResult.CanUp)
                            {
                                m_canShengji = item;
                            }
                        }
                    }
                }
            }
        }
    }
Example #33
0
 public void SetTrapViewState(TrapViewComponent view, TrapState state)
 {
     if (view != null)
     {
         if (view.PendingStates.Count == 0)
         {
             view.Anim.SetInteger("trapAnimState", (int)state);
         }
         view.PendingStates.Add(state);
         this.RegisterObservers();
     }
 }
Example #34
0
 void Reload()
 {
     if (transform.position == startPosition)
     {
         state    = TrapState.Idle;
         this.tag = "Environment";
     }
     else
     {
         transform.position = Vector3.MoveTowards(transform.position, startPosition, reloadSpeed * Time.deltaTime);
     }
 }
Example #35
0
 /// <summary>
 /// A method to determine what happens to the trap after an actor entered the TrapTile.
 /// </summary>
 /// <returns>The damage the trap deals or 0.</returns>
 public int Trigger()
 {
     if (_state == TrapState.On)
     {
         if ((_type & TrapType.OnlyOnce) == TrapType.OnlyOnce)
         {
             _state = TrapState.Disabled; // Trap was sprung and will be disabled
         }
         if ((_type & TrapType.Hidden) == TrapType.Hidden)
         {
             _type &= ~TrapType.Hidden; // Trap was hidden and now becomes visible
         }
         return _damage;
     }
     return 0;
 }
Example #36
0
        /// <summary>
        /// Update method for the trap.
        /// If the repeatTime passed since the last action the trap can again deal damage.
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            if (((_type & TrapType.Changing) == TrapType.Changing) && (_state != TrapState.Destroyed) && (_state != TrapState.NoDisplay) && (_state != TrapState.Disabled) && ((_type & TrapType.Hidden) != TrapType.Hidden))
            {
                _elapsed += (uint)gameTime.ElapsedGameTime.Milliseconds;
                if (_elapsed > _repeatTime)
                {
                    _elapsed = 0;
                    if (_state == TrapState.Off)
                    {
                        _state = TrapState.On;
                    }
                    else _state = TrapState.Off;
                    ((FloorTile)_parent).HandleEvent(false, Backend.Events.TrapActivate, coords);
                }

            }
        }
Example #37
0
 void checkState()
 {
     switch (m_State)
     {
         case TrapState.ACTIVE:
             // raise spikes
             updateSpikes(true);
             // timer for raising spikes then lowering spikes
             m_Timer -= Time.deltaTime;
             if (m_Timer <= 0.0f)
             {
                 m_State = TrapState.DISABLED;
                 m_Timer = m_ResetTimer;
             }
             break;
         case TrapState.DISABLED:
             updateSpikes(false);
             m_Timer -= Time.deltaTime;
             if (m_Timer <= 0.0f)
             {
                 m_State = TrapState.RESETTING;
             }
             break;
         case TrapState.IDLE:
             // waiting for trigger
             break;
         case TrapState.RESETTING:
             m_Timer = m_ResetTimer;
             m_State = TrapState.IDLE;
             break;
         case TrapState.TRIGGERED:
             m_State = TrapState.ACTIVE;
             break;
     }
 }
Example #38
0
 void checkState()
 {
     switch (m_State)
     {
         case TrapState.ACTIVE:
             // Make Block Fall / Disappear
             //Debug.Log("PITFALLLLLL");
             m_Parent.GetComponent<MeshRenderer>().enabled = false;
             m_Parent.GetComponent<BoxCollider>().enabled = false;
             m_State = TrapState.DISABLED;
             break;
         case TrapState.DISABLED:
             // Pitfall forever
             break;
         case TrapState.IDLE:
             break;
         case TrapState.RESETTING:
             m_Parent.GetComponent<MeshRenderer>().enabled = true;
             m_Parent.GetComponent<BoxCollider>().enabled = true;
             m_State = TrapState.IDLE;
             break;
         case TrapState.TRIGGERED:
             m_State = TrapState.ACTIVE;
             break;
     }
 }
Example #39
0
 public void ResetTraps()
 {
     m_State = TrapState.RESETTING;
 }
Example #40
0
 void checkState()
 {
     switch (m_State)
     {
         case TrapState.ACTIVE:
             m_FireParticles.SetActive(true);
             m_Timer -= Time.deltaTime;
             if (m_Timer <= 0.0f)
             {
                 m_FireParticles.SetActive(false);
                 m_State = TrapState.RESETTING;
             }
             break;
         case TrapState.DISABLED:
             break;
         case TrapState.IDLE:
             break;
         case TrapState.RESETTING:
             m_Timer = m_ResetTimer;
             m_State = TrapState.IDLE;
             m_DetectedTimer = m_ResetTimer;
             break;
         case TrapState.TRIGGERED:
             m_State = TrapState.ACTIVE;
             break;
     }
 }
Example #41
0
	void OnCollisionEnter2D(Collision2D coll) {
		if (targets.ContainsKey(coll.gameObject)) {
			// Collided with target, need to see if target is enclosed
			EdgeCollider2D myCollider = gameObject.GetComponent<EdgeCollider2D> ();
			Collider2D otherCollider = coll.collider;
			if (myCollider.bounds.Contains (otherCollider.bounds.min) 
				&& myCollider.bounds.Contains (otherCollider.bounds.max)) {
				HashSet<System.Func<TrapManager, bool>> toRemove = new HashSet<System.Func<TrapManager, bool>> ();
				foreach (System.Func<TrapManager, bool> responder in targets[coll.gameObject]) {
					bool shouldRemove = responder.Invoke (this);
					if (shouldRemove) {
						toRemove.Add (responder);
					}
				}

				foreach (System.Func<TrapManager, bool> responder in toRemove) {
					targets[coll.gameObject].Remove (responder);
				}
				if (targets [coll.gameObject].Count == 0) {
					targets.Remove (coll.gameObject);
				}
			}
		}

		if (coll.gameObject.tag == "Ground") {
			if (trapState == TrapState.Falling) {
				trapState = TrapState.Down;
			}
		}
	}
Example #42
0
	public void RaiseTrap() {
		if (trapState == TrapState.Down) {
			Debug.Log ("Raising trap");
			trapState = TrapState.Rising;
		}
	}
Example #43
0
	public void DropTrap () {
		if (trapState == TrapState.Ready) {
			Debug.Log ("Dropping trap");
			trapState = TrapState.Falling;
		}
	}