// Update is called once per frame void Update() { if (AtavismCursor.Instance == null || AtavismCursor.Instance.IsMouseOverUI()) { return; } if (WorldBuilder.Instance.ActiveClaim != null) { if (WorldBuilder.Instance.ActiveClaim.permissionlevel < 1 && !WorldBuilder.Instance.ActiveClaim.playerOwned) { return; } } if (GetBuildingState() == WorldBuildingState.SelectItem) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // Casts the ray and get the first game object hit if (Physics.Raycast(ray, out hit, Mathf.Infinity, objectSelectLayers)) { ClaimObject cObject = hit.transform.gameObject.GetComponent <ClaimObject>(); if (cObject == null) { cObject = hit.transform.gameObject.GetComponentInChildren <ClaimObject>(); } if (cObject == null && hit.transform.parent != null) { cObject = hit.transform.parent.GetComponent <ClaimObject>(); } if (cObject != null) { int objectID = cObject.ID; if (WorldBuilder.Instance.ActiveClaim.claimObjects.ContainsKey(objectID)) { if (hoverObject != cObject) { if (hoverObject != null) { hoverObject.ResetHighlight(); } hoverObject = cObject; cObject.Highlight(); } if (Input.GetMouseButtonDown(0)) { StopSelectObject(); //SetBuildingState(WorldBuildingState.EditItem); //objectBeingEdited = activeClaim.claimObjects[objectID].gameObject; WorldBuilder.Instance.RequestClaimObjectInfo(objectID); cObject.Highlight(); WorldBuilder.Instance.SelectedObject = cObject; } } } else if (hoverObject != null) { hoverObject.ResetHighlight(); hoverObject = null; } } else if (hoverObject != null) { hoverObject.ResetHighlight(); hoverObject = null; } } if ((GetBuildingState() == WorldBuildingState.PlaceItem || GetBuildingState() == WorldBuildingState.MoveItem) && currentReticle != null) { if (Input.GetMouseButtonDown(1)) { ClearCurrentReticle(true); WorldBuilder.Instance.BuildingState = WorldBuildingState.None; return; } GetHitLocation(); bool legalPlacement = IsLegalClaimObjectPlacement(); if (!legalPlacement) { currentReticle.GetComponentInChildren <ClaimObject>().HighlightError(); } else { currentReticle.GetComponentInChildren <ClaimObject>().ResetHighlight(); } float delta = Input.GetAxis("Mouse ScrollWheel"); if (mouseWheelBuildMode == MouseWheelBuildMode.Rotate) { Vector3 currentRotation = currentReticle.transform.rotation.eulerAngles; if (delta > 0) { //currentReticle.transform.Rotate (new Vector3 (0, -rotationAmount, 0)); currentRotation.y -= 90; } else if (delta < 0) { //currentReticle.transform.Rotate (new Vector3 (0, rotationAmount, 0)); currentRotation.y += 90; } Quaternion rotation = Quaternion.Euler(currentRotation); currentReticle.transform.rotation = rotation; } else if (mouseWheelBuildMode == MouseWheelBuildMode.MoveVertical) { if (delta > 0) { if (currentClaimObject.verticalSnapDistance > 0) { currentVerticalOffset += currentClaimObject.verticalSnapDistance; } else { currentVerticalOffset += verticalMovementAmount; } } else if (delta < 0) { if (currentClaimObject.verticalSnapDistance > 0) { currentVerticalOffset -= currentClaimObject.verticalSnapDistance; } else { currentVerticalOffset -= verticalMovementAmount; } } } //snapped = false; if ((currentReticle != null) && (WorldBuilder.Instance.ActiveClaim != null) && (WorldBuilder.Instance.InsideClaimArea(WorldBuilder.Instance.ActiveClaim, hitPoint))) { if (snap) { float newX = Mathf.Round(hitPoint.x * (1 / snapGap)) / (1 / snapGap); float newZ = Mathf.Round(hitPoint.z * (1 / snapGap)) / (1 / snapGap); float newY = hitPoint.y + currentVerticalOffset; // If the claimobject has a horizontal snap value, override default snap values if (currentClaimObject.horizontalSnapDistance > 0) { newX = Mathf.Round(hitPoint.x * (1 / currentClaimObject.horizontalSnapDistance)) / (1 / currentClaimObject.horizontalSnapDistance); newZ = Mathf.Round(hitPoint.z * (1 / currentClaimObject.horizontalSnapDistance)) / (1 / currentClaimObject.horizontalSnapDistance); } // If the claimobject has a vertical snap value, set that as well if (currentClaimObject.verticalSnapDistance > 0) { newY = Mathf.Round((hitPoint.y + currentVerticalOffset) * (1 / currentClaimObject.verticalSnapDistance)) / (1 / currentClaimObject.verticalSnapDistance); } hitPoint = new Vector3(newX, newY, newZ); // snapped = true; } if (currentClaimObject.placementType == BuildObjectPlacementType.Terrain && hitObject != null && (hitObject.GetComponent <ClaimObject>() != null || hitObject.GetComponentInParent <ClaimObject>() != null)) { // Custom snap system to line them up with each other // Get size of block Vector3 baseSize = GetSizeOfBase(currentReticle).size; // Move block along z axis by size / 2, set y to same as hit object if (hitNormal == Vector3.back) { hitPoint = hitObject.transform.position; hitPoint.z -= baseSize.z; // snapped = true; } else if (hitNormal == Vector3.forward) { hitPoint = hitObject.transform.position; hitPoint.z += baseSize.z; // snapped = true; } else if (hitNormal == Vector3.right) { hitPoint = hitObject.transform.position; hitPoint.x += baseSize.x; // snapped = true; } else if (hitNormal == Vector3.left) { hitPoint = hitObject.transform.position; hitPoint.x -= baseSize.x; // snapped = true; } // Check terrain height if (baseOverTerrainThreshold > 0) { float height = Terrain.activeTerrain.SampleHeight(hitPoint) + Terrain.activeTerrain.GetPosition().y; //Debug.Log("Hitpoint y = " + hitPoint.y + " with terrain height: " + height); if (hitPoint.y - baseOverTerrainThreshold > height) { legalPlacement = false; currentClaimObject.HighlightError(); Debug.Log("Too high above terrain"); } } } currentReticle.transform.position = hitPoint; if (currentClaimObject.autoRotateToHitNormal) { //Rotate the object to match normals Vector3 currentRotation = currentReticle.transform.rotation.eulerAngles; if (hitNormal == Vector3.back) { currentRotation.y = 180; //currentReticle.transform.rotation = Quaternion.AngleAxis(180, Vector3.up); //hitPoint = new Vector3(newX, newY, hitPoint.z); } else if (hitNormal == Vector3.forward) { currentRotation.y = 0; } else if (hitNormal == Vector3.right) { currentRotation.y = 90; } else if (hitNormal == Vector3.left) { currentRotation.y = -90; } Quaternion rotation = Quaternion.Euler(currentRotation); currentReticle.transform.rotation = rotation; } } if (Input.GetKeyDown(KeyCode.LeftShift)) { if (mouseWheelBuildMode == MouseWheelBuildMode.MoveVertical) { mouseWheelBuildMode = MouseWheelBuildMode.Rotate; #if AT_I2LOC_PRESET ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("Changed to Rotate Mode")); #else ClientAPI.Write("Changed to Rotate Mode"); #endif } else { mouseWheelBuildMode = MouseWheelBuildMode.MoveVertical; #if AT_I2LOC_PRESET ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("Changed to Move Vertical Mode")); #else ClientAPI.Write("Changed to Move Vertical Mode"); #endif } } if (Input.GetMouseButtonDown(0) && !AtavismUiSystem.IsMouseOverFrame()) { if (!legalPlacement) { string[] args = new string[1]; #if AT_I2LOC_PRESET args[0] = I2.Loc.LocalizationManager.GetTranslation("That object cannot be placed there"); #else args[0] = "That object cannot be placed there"; #endif AtavismEventSystem.DispatchEvent("ERROR_MESSAGE", args); } else if (GetBuildingState() == WorldBuildingState.PlaceItem) { int parent = -1; if (currentClaimObject.canHaveParent && hitObject.GetComponentInParent <ClaimObject>() != null) { parent = hitObject.GetComponentInParent <ClaimObject>().ID; } WorldBuilder.Instance.SendPlaceClaimObject(buildTemplate.id, itemBeingPlaced, currentReticle.transform, parent); // Play a coord effect if (placementCoordEffect != null) { Dictionary <string, object> props = new Dictionary <string, object>(); props["gameObject"] = ClientAPI.GetPlayerObject().GameObject; CoordinatedEffectSystem.ExecuteCoordinatedEffect(placementCoordEffect.name, props); } #if AT_I2LOC_PRESET ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("Send place claim object message")); #else ClientAPI.Write("Send place claim object message"); #endif ClearCurrentReticle(true); itemBeingPlaced = null; SetBuildingState(WorldBuildingState.Standard); AtavismCursor.Instance.ClearItemClickedOverride(WorldBuilder.Instance.StartPlaceClaimObject); } else if (GetBuildingState() == WorldBuildingState.MoveItem) { int parent = -1; if (hitObject.GetComponent <ClaimObject>() != null) { parent = hitObject.GetComponent <ClaimObject>().ID; } WorldBuilder.Instance.SendEditObjectPosition(WorldBuilder.Instance.SelectedObject, parent); //SetBuildingState(WorldBuildingState.EditItem); SetBuildingState(WorldBuildingState.Standard); ClearCurrentReticle(false); itemBeingPlaced = null; //objectBeingEdited.GetComponent<ClaimObject>().ResetHighlight(); //objectBeingEdited = null; } } } }
public bool IsMouseOverUI() { return(EventSystem.current.IsPointerOverGameObject() || AtavismUiSystem.IsMouseOverFrame()); }
public void OnLeftClick(bool down, AtavismNode mouseOverObject) { // Item delete check first if (mouseOverObject == null && _mouseDownObject1 == null) { if (_cursorItem != null && !down && !AtavismUiSystem.IsMouseOverFrame()) { StartItemThrowaway(); } return; } if (down) { // ClientAPI.Write("Mouse down object = " + str(worldObj)) // store the mouse down object _mouseDownObject1 = mouseOverObject; return; } else { if (mouseOverObject != _mouseDownObject1) { return; } _mouseDownObject1 = null; } if (ClientAPI.GetPlayerObject() == null) { return; } // mouse up over the same object as the mouse down // that means this is a 'click' on the object float dist = (mouseOverObject.Position - ClientAPI.GetPlayerObject().Position).magnitude; // First check if this is an arena object if (mouseOverObject.PropertyExists("arena_portal")) { if (dist < 6.0) { #if AT_I2LOC_PRESET ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("Retrieving available arenas...")); #else ClientAPI.Write("Retrieving available arenas..."); #endif long playerOid = ClientAPI.GetPlayerObject().Oid; Dictionary <string, object> props = new Dictionary <string, object>(); props.Add("playerOid", playerOid); props.Add("type", (int)mouseOverObject.GetProperty("arena_portal")); NetworkAPI.SendExtensionMessage(0, false, "arena.getTypes", props); } else { #if AT_I2LOC_PRESET ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); #else ClientAPI.Write("That object is too far away (" + dist + " meters)"); #endif } } else if (mouseOverObject.PropertyExists("itemstosell")) { /*if (dist < 6.0) * MarsContainer.GetMerchantTable ((mouseOverObject.GetProperty ("itemstosell"))); * else * ClientAPI.Write ("That object is too far away (" + dist + " meters)");*/ } else if (mouseOverObject.PropertyExists("arena_flag")) { if (dist < 6.0) { long playerOid = ClientAPI.GetPlayerObject().Oid; Dictionary <string, object> props = new Dictionary <string, object>(); props.Add("playerOid", playerOid); props.Add("team", mouseOverObject.GetProperty("arena_flag")); NetworkAPI.SendExtensionMessage(0, false, "arena.pickupFlag", props); } else { #if AT_I2LOC_PRESET ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); #else ClientAPI.Write("That object is too far away (" + dist + " meters)"); #endif } } else if (mouseOverObject.PropertyExists("specialUse")) { string use = (string)mouseOverObject.GetProperty("specialUse"); if (use == "Intro") { if (dist < 6.0) { AtavismEventSystem.DispatchEvent("SHOW_INTRO", null); } } } else if (mouseOverObject.PropertyExists("DomeWarden")) { // int dome = (int)mouseOverObject.GetProperty ("DomeWarden"); if (dist < 6.0) { long playerOid = ClientAPI.GetPlayerObject().Oid; Dictionary <string, object> props = new Dictionary <string, object>(); props.Add("domeID", mouseOverObject.GetProperty("DomeWarden")); NetworkAPI.SendExtensionMessage(playerOid, false, "ao.DOME_ENQUIRY", props); } } else if (mouseOverObject.CheckBooleanProperty("Usable")) { if (dist < 6.0) { long playerOid = ClientAPI.GetPlayerObject().Oid; Dictionary <string, object> props = new Dictionary <string, object>(); props.Add("object", mouseOverObject.Oid); NetworkAPI.SendExtensionMessage(playerOid, false, "ao.OBJECT_ACTIVATED", props); } } if (mouseOverObject.PropertyExists("targetable")) { if ((bool)mouseOverObject.GetProperty("targetable") == false || (string)mouseOverObject.GetProperty("targetable") == "False") { return; } } if (mouseOverObject.Oid != ClientAPI.GetTargetOid()) { ClientAPI.SetTarget(mouseOverObject.Oid); MobSoundSet soundSet = mouseOverObject.gameObject.GetComponent <MobSoundSet>(); if (soundSet != null && ClientAPI.GetTargetOid() != ClientAPI.GetPlayerOid()) { soundSet.PlaySoundEvent(MobSoundEvent.Response); } } //MarsTarget.TargetByOID (mouseOverObject.OID); }
public void OnRightClick(bool down, AtavismNode mouseOverObject) { if (ClientAPI.GetPlayerObject() == null) { return; } // Handle the right click event (perhaps over an object). // For now, we can just always reset the cursor on a right click. // At some point, perhaps picking up an item or ability and right clicking // on an object in the world will do something, but it doesn't now. // Make right mouse up reset the cursor if (!down && !AtavismUiSystem.IsMouseOverFrame()) { ResetCursor(); } if (down) { // ClientAPI.Write("Mouse down object = " + str(objNode)) // store the mouse down object _mouseDownObject2 = mouseOverObject; return; } if (mouseOverObject == null) { return; } if (mouseOverObject != _mouseDownObject2) { return; } if (mouseOverObject.PropertyExists("targetable")) { if ((bool)mouseOverObject.GetProperty("targetable") == true) { ClientAPI.SetTarget(mouseOverObject.Oid); bool dead = false; if (mouseOverObject.PropertyExists("deadstate")) { dead = (bool)mouseOverObject.GetProperty("deadstate"); } MobSoundSet soundSet = mouseOverObject.gameObject.GetComponent <MobSoundSet>(); if (!dead && soundSet != null && ClientAPI.GetTargetOid() != ClientAPI.GetPlayerOid()) { soundSet.PlaySoundEvent(MobSoundEvent.Response); } } } else { ClientAPI.SetTarget(mouseOverObject.Oid); bool dead = false; if (mouseOverObject.PropertyExists("deadstate")) { dead = (bool)mouseOverObject.GetProperty("deadstate"); } MobSoundSet soundSet = mouseOverObject.gameObject.GetComponent <MobSoundSet>(); if (!dead && soundSet != null && ClientAPI.GetTargetOid() != ClientAPI.GetPlayerOid()) { soundSet.PlaySoundEvent(MobSoundEvent.Response); } } float dist = (mouseOverObject.Position - ClientAPI.GetPlayerObject().Position).magnitude; // On a right click, do the context sensitive action if (mouseOverObject.PropertyExists("click_handler")) { //ClientAPI.Write ("Invoking custom click handler for object"); //mouseOverObject.GetProperty ("click_handler") (mouseOverObject, None); } else if (mouseOverObject.CheckBooleanProperty("lootable")) { if (dist < 4.0) { NetworkAPI.SendTargetedCommand(mouseOverObject.Oid, "/getLootList"); } else #if AT_I2LOC_PRESET { ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); } #else { ClientAPI.Write("That object is too far away (" + dist + " meters)"); } #endif } else if (mouseOverObject.CheckBooleanProperty("questconcludable")) { AtavismLogger.LogDebugMessage("questconcludable"); //NetworkAPI.SendQuestConcludeRequestMessage (mouseOverObject.Oid); if (dist < 6.0) { NpcInteraction.Instance.GetInteractionOptionsForNpc(mouseOverObject.Oid); } else #if AT_I2LOC_PRESET { ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); } #else { ClientAPI.Write("That object is too far away (" + dist + " meters)"); } #endif } else if (mouseOverObject.CheckBooleanProperty("questavailable")) { AtavismLogger.LogDebugMessage("questavailable"); // NetworkAPI.SendQuestInfoRequestMessage (mouseOverObject.Oid); if (dist < 6.0) { NpcInteraction.Instance.GetInteractionOptionsForNpc(mouseOverObject.Oid); } else #if AT_I2LOC_PRESET { ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); } #else { ClientAPI.Write("That object is too far away (" + dist + " meters)"); } #endif } else if (mouseOverObject.CheckBooleanProperty("questinprogress")) { AtavismLogger.LogDebugMessage("questinprogress"); // NetworkAPI.SendQuestInfoRequestMessage (mouseOverObject.Oid); if (dist < 6.0) { NpcInteraction.Instance.GetInteractionOptionsForNpc(mouseOverObject.Oid); } else #if AT_I2LOC_PRESET { ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); } #else { ClientAPI.Write("That object is too far away (" + dist + " meters)"); } #endif } else if (mouseOverObject.CheckBooleanProperty("itemstosell")) { if (dist < 6.0) { NpcInteraction.Instance.GetInteractionOptionsForNpc(mouseOverObject.Oid); } else #if AT_I2LOC_PRESET { ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); } #else { ClientAPI.Write("That object is too far away (" + dist + " meters)"); } #endif } else if (mouseOverObject.PropertyExists("dialogue_available")) { int dialogueID = (int)mouseOverObject.GetProperty("dialogue_available"); if (dialogueID > 0) { if (dist < 6.0) { NpcInteraction.Instance.GetInteractionOptionsForNpc(mouseOverObject.Oid); } } } else if (mouseOverObject.CheckBooleanProperty("bankteller")) { if (dist < 6.0) { NpcInteraction.Instance.GetInteractionOptionsForNpc(mouseOverObject.Oid); } else #if AT_I2LOC_PRESET { ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); } #else { ClientAPI.Write("That object is too far away (" + dist + " meters)"); } #endif } else if (mouseOverObject.CheckBooleanProperty("attackable")) { int targetType = -1; if (mouseOverObject.PropertyExists("targetType")) { targetType = (int)mouseOverObject.GetProperty("targetType"); } if (!mouseOverObject.IsPlayer() && targetType < 1) { NetworkAPI.SendAttackMessage(mouseOverObject.Oid, "strike", true); } } else if (mouseOverObject.PropertyExists("specialUse")) { string use = ""; if (mouseOverObject.PropertyExists("specialUse")) { use = (string)mouseOverObject.GetProperty("specialUse"); } if (use == "arenaMaster") { if (dist < 6.0) { AtavismEventSystem.DispatchEvent("ARENA_MASTER_CLICK", null); } else #if AT_I2LOC_PRESET { ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); } #else { ClientAPI.Write("That object is too far away (" + dist + " meters)"); } #endif } else if (use == "Intro") { if (dist < 6.0) { AtavismEventSystem.DispatchEvent("SHOW_INTRO", null); } } } else if (mouseOverObject.PropertyExists("arena_portal")) { if (dist < 6.0) { //ClientAPI.Write ("Retrieving available arenas..."); long playerOid = ClientAPI.GetPlayerObject().Oid; Dictionary <string, object> props = new Dictionary <string, object>(); props.Add("playerOid", playerOid); props.Add("type", (int)mouseOverObject.GetProperty("arena_portal")); NetworkAPI.SendExtensionMessage(0, false, "arena.getTypes", props); } else { #if AT_I2LOC_PRESET ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); #else ClientAPI.Write("You need to be closer to the portal to activate it"); #endif } } else if (mouseOverObject.PropertyExists("arena_flag")) { if (dist < 6.0) { long playerOid = ClientAPI.GetPlayerObject().Oid; Dictionary <string, object> props = new Dictionary <string, object>(); props.Add("playerOid", playerOid); props.Add("team", mouseOverObject.GetProperty("arena_flag")); NetworkAPI.SendExtensionMessage(0, false, "arena.pickupFlag", props); } else { #if AT_I2LOC_PRESET ClientAPI.Write(I2.Loc.LocalizationManager.GetTranslation("That object is too far away (") + dist + " " + I2.Loc.LocalizationManager.GetTranslation("meters)")); #else ClientAPI.Write("That object is too far away (" + dist + " meters)"); #endif } } else if (mouseOverObject.CheckBooleanProperty("Usable")) { if (dist < 6.0) { long playerOid = ClientAPI.GetPlayerObject().Oid; Dictionary <string, object> props = new Dictionary <string, object>(); props.Add("object", mouseOverObject.Oid); NetworkAPI.SendExtensionMessage(playerOid, false, "ao.OBJECT_ACTIVATED", props); } } else if (mouseOverObject.CheckBooleanProperty("itemavailable")) { if (dist < 6.0) { NetworkAPI.SendTargetedCommand(mouseOverObject.Oid, "/openMob"); } } else if (mouseOverObject.PropertyExists("skinnableLevel")) { if (dist < 6.0) { int id = (int)mouseOverObject.Oid * -1; Crafting.Instance.HarvestResource(id); } } }