Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Client]
- void SelectionHandling() {
- // click raycasting if not over a UI element & not pinching on mobile
- // note: this only works if the UI's CanvasGroup blocks Raycasts
- if (Input.GetMouseButtonDown(0) && !Utils.IsCursorOverUserInterface() && Input.touchCount <= 1) {
- var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit)) {
- // valid target?
- var entity = hit.transform.GetComponent<Entity>();
- if (entity) {
- // set indicator
- SetIndicatorViaParent(hit.transform);
- // clicked last target again? and is not self?
- if (entity != this && entity == target) {
- // attackable & alive => attack
- if (CanAttackType(entity.GetType()) && entity.health > 0) {
- // cast the first skill (if any, and if ready)
- if (skills.Count > 0 && skills[0].IsReady())
- CmdUseSkill(0);
- // otherwise walk there if still on cooldown etc
- // use collider point(s) to also work with big entities
- else
- CmdNavigateTo(entity.collider.ClosestPointOnBounds(transform.position), skills.Count > 0 ? skills[0].castRange : 0f);
- // npc & alive => talk
- } else if (entity is Npc && entity.health > 0) {
- // close enough to talk?
- // use collider point(s) to also work with big entities
- if (Utils.ClosestDistance(collider, entity.collider) <= interactionRange)
- FindObjectOfType<UINpcDialogue>().Show();
- // otherwise walk there
- // use collider point(s) to also work with big entities
- else
- CmdNavigateTo(entity.collider.ClosestPointOnBounds(transform.position), interactionRange);
- // monster & dead => loot
- } else if (entity is Monster && entity.health == 0) {
- // has loot? and close enough?
- // use collider point(s) to also work with big entities
- if (((Monster)entity).HasLoot() &&
- Utils.ClosestDistance(collider, entity.collider) <= interactionRange)
- FindObjectOfType<UILoot>().Show();
- // otherwise walk there
- // use collider point(s) to also work with big entities
- else
- CmdNavigateTo(entity.collider.ClosestPointOnBounds(transform.position), interactionRange);
- }
- // addon system hooks
- Utils.InvokeMany(typeof(Player), this, "OnSelect_", entity);
- // clicked a new target
- } else {
- // target it
- CmdSetTarget(entity.netIdentity);
- }
- // otherwise it's a movement target
- } else {
- // set indicator and navigate to the nearest walkable
- // destination. this prevents twitching when destination is
- // accidentally in a room without a door etc.
- var bestDestination = agent.NearestValidDestination(hit.point);
- SetIndicatorViaPosition(bestDestination, hit.normal);
- CmdNavigateTo(bestDestination, 0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement