// Gets a market target otherwise public void GetMarketTarget(TileManager tileManager) { // List of market positions List<Vector2> marketPositions = tileManager.MarketPositions; // Loop through them to find the village foreach (var position in marketPositions) { // Check if the market type is village if (tileManager.GetMarketType(position) == MarketType.Village) { // Set the target to the position of the village merchant.Target = new Vector3(position.x, position.y, 0.0f); // Break out of the loop since we found a village break; } // end if } // end foreach }
// Gets a resource target if possible public void GetResourceTarget(TileManager tileManager) { // Value of the target resource int resourceValue = 0; // Get all objects within move distance sphere on layer 9 (resource layer) float radius = GPSM.GetDist() * TileUtils.PlayerMoveDistance; Collider2D[] hitColliders = Physics2D.OverlapCircleAll(merchant.Position, radius, 1 << LayerMask.NameToLayer("Resources")); // Determine highest value if possible for (int index = 0; index < hitColliders.Length; index++) { // Get ResourceType of resource hit ResourceType resourceType = tileManager.GetResourceType(hitColliders[index].gameObject.name); // Get worth/value of the resource Resource resource = (Resource)ItemDatabase.Instance.Items.Find(tempItem => tempItem.Type == resourceType.ToString()); // Check if the AI can carry the resource if (((Merchant)Entity).TotalWeight + resource.Weight <= ((Merchant)Entity).MaxWeight) { // If the value is higher than current target, replace it as the new target if (resourceValue < resource.Worth) { merchant.Target = hitColliders[index].transform.position; resourceValue = resource.Worth; } // end if resourceValue < resource.Worth } // end if } //end for // Verify there is a target, otherwise set it to a village if (merchant.Target == Vector3.zero) { // Get the proper market target GetMarketTarget(tileManager); } //end if }
// Runs when the object if first instantiated, because this object will occur once through the game, // these values are the beginning of game values // Note: Values should be updated at the EndTurn State void Start() { // Get the reference to the tile manager tileManager = GameObject.Find("TileManager").GetComponent<TileManager>(); // Generate the map tileManager.GenerateMap(); // Get HUD elements CurrentPlayer = GameObject.Find ("Canvas/CurrentPlayer"); AllPlayers = GameObject.Find("Canvas/AllPlayers"); BKG = GameObject.Find ("Canvas/Background"); guiPlayerName = GameObject.Find("CurrentPlayer/PlayerNamePanel/PlayerName").GetComponent<Text>(); guiTurnText = GameObject.Find("CurrentPlayer/TurnPhasePanel/TurnPhase").GetComponent<Text>(); guiGold = GameObject.Find("CurrentPlayer/WeightGold/Gold").GetComponent<Text>(); guiWeight = GameObject.Find("CurrentPlayer/WeightGold/Weight").GetComponent<Text>(); actionButton = GameObject.Find("CurrentPlayer/ActionButton").GetComponent<Button>(); actionButtonText = GameObject.Find("CurrentPlayer/ActionButton").GetComponentInChildren<Text>(); acceptPanel = GameObject.Find("Accept"); pauseMenu = GameObject.Find ("PauseMenu"); instructionsSet = GameObject.Find ("Instructions"); audioSet = GameObject.Find ("Options"); imageParent = GameObject.Find("AllPlayers/ImageOrganizer"); textParent = GameObject.Find("AllPlayers/TextOrganizer"); inventory = GameObject.Find("PlayerInventory").GetComponent<PlayerInventory>(); allyInventory = GameObject.Find("AllyInventory").GetComponent<AllyInventory>(); recycleInventory = GameObject.Find("RecycleBin").GetComponent<RecycleBin>(); allyTable = GameObject.Find("Allies").GetComponent<AllyTable>(); GameObject.Find ("Canvas").transform.Find ("Instructions").gameObject.SetActive (false); HUDToggle = true; actionButtonActive = true; isPaused = false; instructionsProgress = 1; // Disable the other panels by default acceptPanel.SetActive(false); pauseMenu.SetActive (false); audioSet.SetActive (false); inventory.gameObject.SetActive(false); allyInventory.gameObject.SetActive(false); recycleInventory.gameObject.SetActive(false); allyTable.gameObject.SetActive(false); // Running the end stuff defaults to true canRunEndStuff = true; // The movement class is not initialised isMovementInitialized = false; // The ally window are closed by default isAlliesOpen = false; // Get the number of players guiNumOfPlayers = GameMaster.Instance.NumPlayers; // Set the turn guiPlayerTurn = GameMaster.Instance.Turn; // Set starting values guiDiceDistVal = 0; movementCooldown = 0.0f; // The player is not an AI by default isPlayerAI = false; // Create a die die = new Die(); // Get movement and map event components guiMovement = GameObject.Find("Canvas").GetComponent<GUIMovement> (); guiMapEvent = GameObject.Find("Canvas").GetComponent<MapEvent> (); // There isn't a map event in the beginning mapEventResultString = string.Empty; // Initialise other things after Start() runs canInitAfterStart = true; // Set the state to the BeginTurn state gamePlayState = GamePlayState.BeginTurn; }