Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1.   [Client]
  2.     void SelectionHandling() {
  3.         // click raycasting if not over a UI element & not pinching on mobile
  4.         // note: this only works if the UI's CanvasGroup blocks Raycasts
  5.         if (Input.GetMouseButtonDown(0) && !Utils.IsCursorOverUserInterface() && Input.touchCount <= 1) {
  6.             var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  7.             RaycastHit hit;
  8.             if (Physics.Raycast(ray, out hit)) {
  9.                 // valid target?
  10.                 var entity = hit.transform.GetComponent<Entity>();
  11.                 if (entity) {
  12.                     // set indicator
  13.                     SetIndicatorViaParent(hit.transform);
  14.  
  15.                     // clicked last target again? and is not self?
  16.                     if (entity != this && entity == target) {
  17.                         // attackable & alive => attack
  18.                         if (CanAttackType(entity.GetType()) && entity.health > 0) {
  19.                             // cast the first skill (if any, and if ready)
  20.                             if (skills.Count > 0 && skills[0].IsReady())
  21.                                 CmdUseSkill(0);
  22.                             // otherwise walk there if still on cooldown etc
  23.                             // use collider point(s) to also work with big entities
  24.                             else
  25.                                 CmdNavigateTo(entity.collider.ClosestPointOnBounds(transform.position), skills.Count > 0 ? skills[0].castRange : 0f);
  26.                         // npc & alive => talk
  27.                         } else if (entity is Npc && entity.health > 0) {
  28.                             // close enough to talk?
  29.                             // use collider point(s) to also work with big entities
  30.                             if (Utils.ClosestDistance(collider, entity.collider) <= interactionRange)
  31.                                 FindObjectOfType<UINpcDialogue>().Show();
  32.                             // otherwise walk there
  33.                             // use collider point(s) to also work with big entities
  34.                             else
  35.                                 CmdNavigateTo(entity.collider.ClosestPointOnBounds(transform.position), interactionRange);
  36.                         // monster & dead => loot
  37.                         } else if (entity is Monster && entity.health == 0) {
  38.                             // has loot? and close enough?
  39.                             // use collider point(s) to also work with big entities
  40.                             if (((Monster)entity).HasLoot() &&
  41.                                 Utils.ClosestDistance(collider, entity.collider) <= interactionRange)
  42.                                 FindObjectOfType<UILoot>().Show();
  43.                             // otherwise walk there
  44.                             // use collider point(s) to also work with big entities
  45.                             else
  46.                                 CmdNavigateTo(entity.collider.ClosestPointOnBounds(transform.position), interactionRange);
  47.                         }
  48.  
  49.                         // addon system hooks
  50.                         Utils.InvokeMany(typeof(Player), this, "OnSelect_", entity);
  51.                     // clicked a new target
  52.                     } else {
  53.                         // target it
  54.                         CmdSetTarget(entity.netIdentity);
  55.                     }
  56.                 // otherwise it's a movement target
  57.                 } else {
  58.                     // set indicator and navigate to the nearest walkable
  59.                     // destination. this prevents twitching when destination is
  60.                     // accidentally in a room without a door etc.
  61.                     var bestDestination = agent.NearestValidDestination(hit.point);
  62.                     SetIndicatorViaPosition(bestDestination, hit.normal);
  63.                     CmdNavigateTo(bestDestination, 0);
  64.                 }
  65.             }
  66.         }
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement