public bool UseSpell(SpellCaster sc) { if (actor.unit && !actor.unit.isAlive) { // error = "can't attack when you're dead... noob"; return(false); } RaycastHit hit = PlayerEntityController.GetClickedRaycast(); sc.actorTarget = hit.transform.GetComponent <Actor>(); sc.pointTarget = hit.point; string error; return(sc.TryCast(out error)); }
// Update is called once per frame void Update() { if (timer < 1.0f && !dashing) { // jumping in the air caster.transform.position += new Vector3(0, 100.0f * Time.deltaTime, 0); timer += Time.deltaTime; } else if (!dashing) { // looking for a ground target sight.SetActive(true); PlayerEntityController.instance.followCamera.verticalAngle += Input.GetAxis("Mouse X"); PlayerEntityController.instance.followCamera.horizontalAngle -= Input.GetAxis("Mouse Y"); var hit = PlayerEntityController.GetClickedRaycast(); caster.transform.LookAt(hit.point); if (hit.collider) { if (Input.GetMouseButtonDown(0)) { timer = 0; sight.SetActive(false); dashing = true; pointTarget = hit.point; transform.position = caster.transform.position; totalDistance = Vector3.Distance(transform.position, pointTarget); PlayerEntityController.instance.followCamera.offset = Vector3.zero; } } } else { timer += Time.deltaTime; caster.transform.position = Vector3.MoveTowards(transform.position, pointTarget, timer * totalDistance); // dashing to the ground if (timer >= 1.0f) { caster.ReleaseMove(); Cursor.lockState = CursorLockMode.None; PlayerEntityController.instance.followCamera.verticalAngle = savedVerticalAngle; PlayerEntityController.instance.followCamera.horizontalAngle = savedHorizontalAngle; caster.agent.enabled = true; casterCollider.enabled = true; Destroy(gameObject); } } }
internal void TargetReceiveUpdate(NetworkConnection conn, StoreInventory inventory) { if (debug) { Debug.Log("StoreManager Client: We received a single update for store " + storeNumber); } this.currentStoreInventory.Apply(inventory); /* Get the main player */ PlayerEntityController player = SojournGameManager.GetMainPlayer(); Debug.Assert(player != null); /* Get the bartering menu manager */ PlayerBarteringManager menu = player.GetComponent <PlayerBarteringManager>(); /* Let the manager know that the inventory changed. */ menu.StoreInventoryChanged(this); }
internal void RpcUpdateClientStoreInventory(StoreInventory currentInventory) { if (debug) { Debug.Log("StoreManager Client: We got an update for store " + storeNumber); } this.currentStoreInventory.Apply(currentInventory); /* Get the main player */ PlayerEntityController player = SojournGameManager.GetMainPlayer(); Debug.Assert(player != null); /* Get the bartering menu manager */ PlayerBarteringManager menu = player.GetComponent <PlayerBarteringManager>(); /* Let the manager know that the inventory changed. */ menu.StoreInventoryChanged(this); }
void Update() { RaycastHit hit = PlayerEntityController.GetClickedRaycast(); if (hit.collider && hit.collider.gameObject.layer != LayerMask.NameToLayer("World") && !MenuManager.OnInterface()) { hover = hit.collider.GetComponent <Actor>(); if (hover) { canvas.enabled = false; } ShowItemInfo(hit.collider.GetComponent <ItemEntity>()); highlightNode.transform.position = hit.transform.position; highlightNode.SetActive(true); } else { highlightNode.SetActive(false); canvas.enabled = false; } }
internal void CmdTransferFromInventoryToStore(NetworkInstanceId store_id, int row, int col) { if (debug) { Debug.Log("BarteringMenuManager Server: Got a request to move an item from the inventory to the store."); } /* Get the player's attribute manager */ PlayerEntityController attrib = GetComponent <PlayerEntityController>(); /* Get this player's inventory */ PlayerInventory inventory = attrib.GetComponent <PlayerInventoryManager>().GetInventory(); /* Get the item from the player's inventory */ Item item = inventory.Get(row, col); if (Item.IsNull(item)) { Debug.LogError("BarteringMenuManager Server: Can't take null item from inventory!"); return; } GameObject storeObject = NetworkServer.FindLocalObject(store_id); if (storeObject == null) { Debug.LogError("BarteringMenuManager Server: The client send us a bad object id!"); return; } /* Get the store manager for this store */ StoreManager storeManager = storeObject.GetComponent <StoreManager>(); if (storeManager == null) { Debug.LogError("BarteringMenuManager Server: The client sent us an ID for something that isn't a store!"); return; } /* Take coins from player and give them to the store */ long value = item.item_value; if (storeManager.GetCoins() < value) { if (debug) { Debug.LogWarning("BarteringMenuManager Server: The store doesn't have enough coins to buy this item!"); } /* Reduce the value to the amount of coins remaining in the shop */ value = storeManager.GetCoins(); } inventory.gold += value; storeManager.RemoveCoins(value); /* Remove the item from the player's inventory */ if (inventory.Remove(row, col) == null) { Debug.LogError("BarteringMenuManager Server: Failed to remove item from player inventory!"); return; } /* Give the item to the store */ if (!storeManager.AddItem(item)) { Debug.LogError("BarteringMenuManager Server: Failed to add item to the shop!!"); /* If this happens we should really restore the player's item. */ if (inventory.Add(item)) { Debug.LogWarning("BarteringMenuManager Server: We were able to restore the player's item."); } else { Debug.LogError("BarteringMenuManager Server: We failed to restore the player's item!!"); } return; } /* The player's inventory has been updated */ // attrib.UpdateClientInventory(); if (debug) { Debug.Log("BarteringMenuManager Server: Item transferred to the player inventory."); } }
internal void CmdTransferFromStoreToInventory(NetworkInstanceId store_id, string item_name) { /* Get the item that the player is trying to purchase */ Item item = SojournDBM.odbm.GetItemByName(item_name); if (Item.IsNull(item)) { Debug.LogError("BarteringMenuManager Server: Client sent us a bad item uuid."); return; } if (debug) { Debug.Log("BarteringMenuManager Server: Got a request to move an item from the inventory to the store."); } /* Get the player's attribute manager */ PlayerEntityController attrib = GetComponent <PlayerEntityController>(); /* Get this player's inventory */ PlayerInventory inventory = attrib.GetComponent <PlayerInventoryManager>().GetInventory(); /* Get the object for the store */ GameObject storeObject = NetworkServer.FindLocalObject(store_id); if (storeObject == null) { Debug.LogError("BarteringMenuManager Server: The client send us a bad object id!"); return; } /* Get the store manager for this store */ StoreManager storeManager = storeObject.GetComponent <StoreManager>(); if (storeManager == null) { Debug.LogError("BarteringMenuManager Server: The client sent us an ID for something that isn't a store!"); return; } /* Does the store carry the given item? */ if (storeManager.GetCurrentInventory().GetQuantity(item) <= 0) { Debug.LogError("BarteringMenuManager Server: The store doesn't carry this item."); return; } /* Take coins from store and give them to the player */ long value = item.item_value; if (inventory.gold < value) { if (debug) { Debug.LogWarning("BarteringMenuManager Server: The player doesn't have enough coins to buy this item!"); } return; } inventory.gold -= value; storeManager.AddCoins(value); /* Remove the item from the store */ if (!storeManager.RemoveItem(item)) { Debug.LogError("BarteringMenuManager Server: Failed to remove the item from the store!"); return; } /* Give the item to the player */ if (!inventory.Add(item)) { Debug.LogError("BarteringMenuManager Server: Failed to add item to the player's inventory!!"); /* If this happens we should really restore the store's item. */ if (storeManager.AddItem(item)) { Debug.LogWarning("BarteringMenuManager Server: We were able to restore the store's item."); } else { Debug.LogError("BarteringMenuManager Server: We failed to restore the store's item!!"); } return; } /* The player's inventory has been updated */ // attrib.UpdateClientInventory(); if (debug) { Debug.Log("BarteringMenuManager Server: Item transferred to the inventory."); } }
void Awake() { instance = this; actor = GetComponent <Actor>(); unit = GetComponent <Unit>(); }
private void CmdPickupItem(NetworkInstanceId handId, NetworkInstanceId socketManagerId, int socketNumber) { if (debug) { Debug.Log("PlayerToolbeltManager Server: The client has asked us to swap items between their hand and their toolbelt"); } /* Get our hand manager */ HandManager hand = InternalGetHand(handId); if (hand == null) { return; } /* Get the socket that the client provided */ SojournSocket socket = GetSojournSocket(socketManagerId, socketNumber); if (socket == null) { return; } /* Convert the socket into a toolbelt slot */ PlayerToolbeltSlot toolbeltSlot = (PlayerToolbeltSlot)socket; if (toolbeltSlot == null) { Debug.LogError("PlayerToolbeltManager Server: The client sent us a bad toolbelt slot!"); return; } /* Get the attached object from the toolbelt slot */ GameObject attachedObj = toolbeltSlot.GetAttachedObject(); if (attachedObj == null) { Debug.LogError("SojournToolbeltManager Server: There is nothing attached to this toolbelt slot!"); return; } /* Get the toolbelt item from the socket */ SojournItem toolbeltItem = attachedObj.GetComponent <SojournItem>(); if (toolbeltItem == null) { return; } /* Make the toolbelt item pickupable */ toolbeltItem.SetCanBePickedUp(true); /* Get the player controller for this player */ PlayerEntityController player = hand.GetPlayerController(); if (player == null) { throw new System.Exception("Why is there no player controller for this hand?"); } /* Get the player pickup manager for this hand */ PlayerPickupManager pickup = player.GetComponent <PlayerPickupManager>(); if (!pickup.ServerPickUp(hand, toolbeltItem)) { throw new System.Exception("Failed to have player pickup item on toolbelt!"); } if (debug) { Debug.Log("PlayerToolbeltManager Server: Player picked up item from their toolbelt."); } }