Exemple #1
0
    protected override void setHealth(int newHealth)
    {
        if (_photonView.isMine)
        {
            PhotonNetwork.player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable()
            {
                {
                    RoomLevelHelper.CUSTOM_PLAYER_PROPERTY_HEALTH,
                    newHealth
                },
            });
        }

//		print ("Archer hit");
        if (_health > newHealth)
        {
//			print ("Archer damaged");
            //Archer falls off when attacked
            PlayerCombatHandler pch = GetComponent <PlayerCombatHandler> ();

            if (pch.GetClass() == CHARACTER_CLASS.ARCHER)
            {
                foreach (var a in pch.GetAbilities())
                {
                    if (a is AbilityCoopRide)
                    {
                        AbilityCoopRide acr = (AbilityCoopRide)a;
                        if (acr.Riding)
                        {
                            acr.FallDown();
//							print ("Archer falling down");
                        }
                        break;
                    }
                }
            }
        }

        base.setHealth(newHealth);
    }
    // Update is called once per frame
    void Update()
    {
        //dev
        if (GetComponent <DevPlayerAIBehavior> () != null)
        {
            return;
        }

//		if (Input.GetButtonDown ("Interact")) {
//			GetComponent<Rigidbody> ().AddForce (Vector3.up * 300f);
//		}

        if (photonView == null || photonView.isMine)
        {
            if (!_playerCombatHandler.CheckAbilitiesInUse() &&          //if no abilities are in use, player can use ability
                GameController.GC.GetIsControlAllowed())
            {
                foreach (var a in _playerCombatHandler.GetAbilities())
                {
                    if (Input.GetButtonDown(a.GetInputName()))
                    {
                        Debug.Log(a.GetInputName() + " Pressed");
                        if (a.GetStatus() == ABILITY_STATUS.AVAILABLE)
                        {
                            a.Activate();                             //use ability
                        }
                    }
                }
            }

            //Deactivate hold abilities when letting go of a button from pressing
            foreach (var a in _playerCombatHandler.GetAbilities())
            {
                if (a is AbilityHold)
                {
                    AbilityHold ah = a as AbilityHold;
                    if (ah.GetStatus() == ABILITY_STATUS.IN_USE)
                    {
                        if (Input.GetButtonUp(ah.GetInputName()))
                        {
                            ah.Deactivate();                             //use ability
                        }
                        //Check child ability functionality
                        foreach (var cah in ah.ChildAbilities)
                        {
                            if (cah.GetStatus() == ABILITY_STATUS.IN_USE)
                            {
                                if (Input.GetButtonUp(cah.GetInputName()))
                                {
                                    ((AbilityHold)cah).Deactivate();                                     //use ability
                                }
                            }
                        }
                    }
                }
            }

            //abilities that can be used while another is active
            foreach (var a in _playerCombatHandler.GetAbilities().Where(x => x.GetStatus() == ABILITY_STATUS.IN_USE))
            {
//				print (a.name + " is in use!");
                //get all child ability of used abilities
                foreach (var c in a.ChildAbilities)
                {
//					print (c.name + " found!");
                    //if non of the child abilities are in use, ues it
//					if (a.ChildAbilities.Where (x => x.GetStatus () == ABILITY_STATUS.IN_USE).Count () < 1) {
                    if (Input.GetButtonDown(c.GetInputName()))
                    {
                        if (c.GetStatus() == ABILITY_STATUS.AVAILABLE)
                        {
                            c.Activate();                             //use ability
                        }
                    }
//					}
                }
            }

            //archer fall down from tank
            if (GameController.GC.GetIsControlAllowed())
            {
                foreach (var a in _playerCombatHandler.GetAbilities())
                {
                    if (a is AbilityCoopRide)
                    {
                        if (Input.GetButtonDown(a.GetInputName()))
                        {
                            AbilityCoopRide acr = (AbilityCoopRide)a;
                            if (acr.Riding)
                            {
                                acr.FallDown();
                            }
                        }
                    }
                }
            }
        }
    }