/// <summary> /// This will check to see if target is near the player. /// </summary> public static bool TargetNearPlayer(GameObject target, int maxDistance) { ////////////////////////////////////////////////// //Local Variables GameObject player; int distance; ////////////////////////////////////////////////// player = GameObject.FindWithTag(TagKeys.PLAYER_KEY); distance = NPCMover.DistanceTo(player, target); if (distance <= maxDistance) { return(true); } else { return(false); } }
override public void Execute(GameObject main) { ///////////////////////////////////////////// //Local Variables GameObject player; GameObject collidedObject; MonsterAI myAI; ///////////////////////////////////////////// player = GameObject.FindWithTag(TagKeys.PLAYER_KEY); myAI = main.GetComponent <MonsterAI>(); collidedObject = NPCMover.MoveTowards(main, player); if (collidedObject != null) { AttackCheck(main, collidedObject); } if (NPCMover.DistanceTo(main, player) > myAI.ViewRange) { myAI.ChangeState(new IdleAI()); } }
override public void OnUse(GameObject main, GameObject itemTarget) { /////////////////////////////////////// //Local Variables GameObject messageWindow = GameObject.FindWithTag(TagKeys.MESSAGE_WINDOW_KEY); GameObject closestMonster = null; GameObject player; MonsterController monsterController; int closestDistance = int.MaxValue; int monsterDistance; int damage; /////////////////////////////////////// monsterController = GameObject.FindWithTag(TagKeys.MAIN_CONTROLLER_KEY).GetComponent <MonsterController>(); player = GameObject.FindWithTag(TagKeys.PLAYER_KEY); foreach (GameObject monster in monsterController.GetMonsters()) { monsterDistance = NPCMover.DistanceTo(player, monster); if ((monsterDistance <= RANGE) && (monsterDistance < closestDistance)) { closestMonster = monster; closestDistance = monsterDistance; } } if (closestMonster == null) { messageWindow.GetComponent <MessageWindow>().AddText("The scroll does nothing but fizzles!"); } else { damage = Dice.BetweenRange(MIN_DAMAGE, MAX_DAMAGE); messageWindow.GetComponent <MessageWindow>().AddText(String.Format("{0} is shocked for {1} damage!", closestMonster.name, damage)); closestMonster.GetComponent <Fighter>().TakeDamage(damage); } DestroyItem(main); }
override public void OnUse(GameObject main, GameObject itemTarget) { /////////////////////////////////////// //Local Variables GameObject messageWindow = GameObject.FindWithTag(TagKeys.MESSAGE_WINDOW_KEY); GameObject closestMonster = null; GameObject player; MonsterController monsterController; int closestDistance = int.MaxValue; int monsterDistance; /////////////////////////////////////// monsterController = GameObject.FindWithTag(TagKeys.MAIN_CONTROLLER_KEY).GetComponent <MonsterController>(); player = GameObject.FindWithTag(TagKeys.PLAYER_KEY); foreach (GameObject monster in monsterController.GetMonsters()) { monsterDistance = NPCMover.DistanceTo(player, monster); if ((monsterDistance <= SPELL_DISTANCE) && (monsterDistance < closestDistance)) { closestMonster = monster; closestDistance = monsterDistance; } } if (closestMonster == null) { messageWindow.GetComponent <MessageWindow>().AddText("The scroll does nothing but fizzles!"); } else { closestMonster.GetComponent <MonsterAI>().ChangeState(new ConfusionAI()); } DestroyItem(main); }
override public void Execute(GameObject main) { //////////////////////////////////////////// //Local Variables GameObject player; MonsterAI myAI; //////////////////////////////////////////// player = GameObject.FindWithTag(TagKeys.PLAYER_KEY); myAI = main.GetComponent <MonsterAI>(); if (NPCMover.DistanceTo(main, player) <= myAI.ViewRange) { myAI.ChangeState(new MeleeAttackAI()); } }
private void activateMover(bool aFirstTurn) { if(debugOnlyGameObject.Length==0||debugOnlyGameObject==this.gameObject.name) Debug.Log("<color="+color+">Trying to activate mover on: "+this.gameObject.name+"</color>"); moverHasBeenActivated = true; if(mover==null) { mover = this.GetComponent<NPCMover>(); if(mover==null) { // No mover available, must have been destroyed already. return; } } mover.enabled = true; if(!aFirstTurn) { mover.firstUpdate = false; } this.disableBoxColliders(); if(aFirstTurn) { if(debugOnlyGameObject.Length==0||debugOnlyGameObject==this.gameObject.name) Debug.Log("<color="+color+">Mover is on First Turn</color>"); mover.firstUpdate = aFirstTurn; if(aFirstTurn) mover.FirstTurnWalkerHandler(); mover.FixedUpdate(); } else { appearObject(0.01f); } GameObject avatar = GameObject.FindGameObjectWithTag("Player"); ProximitySelector ps = avatar.GetComponent<ProximitySelector>(); ps.CheckTriggerExit(this.gameObject); }