Count() public méthode

Gets the count.
This is explicitly a method rather than a property, so it is not serialized when written to JSON
public Count ( ) : int
Résultat int
	protected override bool DoResourceCalculations (ResourceTileSelection selection)
	{
		bool success = base.DoResourceCalculations (selection);
		if (success) {
			GameManager.economyController.IncreasePendingBalance(Player.CharacterClass.Conservationist, cost*selection.Count());
		}
		return success;
	}
	/// <summary>
	/// Forces a put of resource tile modifications using god mode.
	/// </summary>
	/// <remarks>
	/// This is a temporary solution for implementing actions with no server API point, and can eventually be removed.
	/// </remarks>
	/// <param name='selection'>
	/// The selection.
	/// </param>
	protected override IEnumerator Put(ResourceTileSelection selection)
	{
		m_actionProgress = 0f;
		string url;
		List<ResourceTile> tiles = new List<ResourceTile>();
		float div = 1f/selection.Count();
		for (int i=0; i<selection.Count(); ++i) {
			int id = selection[i];
			// get url for current tile
			url = WebRequests.GetURLToResourceTile(id);
			// get current tile to determine supported saplings
			WWW www = WWWX.Get(url, WebRequests.authenticatedGodModeParameters);
			while (!www.isDone) {
				m_actionProgress = (i+www.progress*0.3f)*div; // about 30% done
				yield return 0;
			}
			ResourceTile tile = JSONDecoder.Decode<IndividualResourceTile>(www.text).resource_tile;
			m_tileModifications.resource_tile = new ModifiedFields(tile.supportedSaplings);
			// add new trees
			www = WWWX.Put(url, GetActionJson(), WebRequests.authenticatedGodModeParameters);
			while (!www.isDone) {
				m_actionProgress = (i+0.3f+www.progress*0.7f)*div; // about 70% done
				yield return 0;
			}
			// get the results back and append to array
			www = WWWX.Get(url, WebRequests.authenticatedGodModeParameters);
			while (!www.isDone) {
				m_actionProgress = (i+0.7f+www.progress+0.3f)*div; // all the way done
				yield return 0;
			}
			try {
				tiles.Add(JSONDecoder.Decode<IndividualResourceTile>(www.text).resource_tile);
			}
			catch (JsonException) {
				Debug.LogError(www.text);
			}
		}
//		ConcludeActionOnResourceTiles(tiles.ToArray());
	}
	protected override bool DoResourceCalculations (ResourceTileSelection selection)
	{
		bool success = base.DoResourceCalculations (selection);
		if (success) {
			//Calculate Tree usage
			if (GameManager.worldData.timber_count >= selection.Count() * 15) {
				GameManager.economyController.UseTimber(selection.Count()*15);
				GameManager.economyController.IncreasePendingBalance(Player.CharacterClass.TimberCompany, 
					selection.Count() * EconomyController.timberRate * 15);
			} else {
				GameGUIManager.use.SetErrorMessage("There is not enough timber available to build.");
				GameGUIManager.use.PlayInvalidActionSound();
				return false;
			}
		}
		return success;
	}
	/// <summary>
	/// Refreshs the data for selection.
	/// </summary>
	/// <param name='selection'>
	/// The selection.
	/// </param>
	private IEnumerator RefreshDataForSelection(ResourceTileSelection selection)
	{
		// TODO: this is temporary. it should actually get back survey data.
		isDirty = false; // set this now so multiple downloads dont happen
		WWW www;
		int[] frequencyDistribution = new int[ResourceTile.treeSizeClassCount];
		int[] knownFreqDistribution = new int[ResourceTile.treeSizeClassCount];
		m_refreshDownloadProgress = 0f;
		float div = 1f/selection.Count();
		for (int i=0; i<selection.Count(); ++i) {
			int id = selection[i];
			www = WWWX.Get(WebRequests.GetURLToResourceTile(id), WebRequests.authenticatedGodModeParameters);
			while (!www.isDone) {
				m_refreshDownloadProgress = (i+www.progress)*div;
				yield return 0;
			}
			if (!string.IsNullOrEmpty(www.error)) {
				Debug.LogError(www.error);
				continue;
			}
			ResourceTile tile;
			try {
				tile = JSONDecoder.Decode<IndividualResourceTile>(www.text).resource_tile;
			}
			catch (JsonException e) {
				Debug.LogError(e);
				continue;
			}
			for (int j=0; j<ResourceTile.treeSizeClassCount; ++j) {
				if (tile.bought_by_timber_company) {
					knownFreqDistribution[j] += tile.treeDistribution[j];
				}
				frequencyDistribution[j] += tile.treeDistribution[j];
			}
		}
		m_knownFrequencyDistributionOfSelectedTiles = knownFreqDistribution;
		m_actualFrequencyDistributionOfSelectedTiles = frequencyDistribution;
		m_refreshDownloadProgress = 1f;
	}
	protected override WWW GetDoItWWW (ResourceTileSelection selection)
	{
		string url = string.Format("{0}build_outpost.json",WebRequests.GetResourceTileURL(selection[selection.Count()-1]));
		Debug.Log(url);
		return WWWX.Post(url,WebRequests.authenticatedParameters);
	}
Exemple #6
0
	/// <summary>
	/// Forces a put of resource tile modifications using god mode.
	/// </summary>
	/// <remarks>
	/// This is a temporary solution for implementing actions with no server API point, and can eventually be removed.
	/// </remarks>
	/// <param name='selection'>
	/// The selection.
	/// </param>
	protected virtual IEnumerator Put(ResourceTileSelection selection)
	{
		HTTP.Request request;
		m_actionProgress = 0f;
		string json = GetActionJson();
		Debug.Log(json);
		List<ResourceTile> tiles = new List<ResourceTile>();
		float div = 1f/selection.Count();
		for (int i=0; i<selection.Count(); ++i) {
			int id = selection[i];
			request = new HTTP.Request( "Put", WebRequests.GetURLToResourceTile(id) );
			request.SetText( json );
			request.AddParameters( WebRequests.authenticatedGodModeParameters );
			request.Send();
			
			while (!request.isDone) {
				//m_actionProgress = (i+www.uploadProgress)*div;
				yield return 0;
			}
			if( request.ProducedError ) {
				m_actionProgress = 1f;
				yield break;
			}
			try {
				tiles.Add(JSONDecoder.Decode<IndividualResourceTile>(request.response.Text).resource_tile);
			}
			catch (JsonException) {
				Debug.LogError(request.response.Text);
			}
		}
//		ConcludeActionOnResourceTiles(tiles.ToArray());
		//Update the world
		IEnumerator e = WebRequests.RefreshWorldData(new WebCoroutine());
		yield return e.Current;
		while(e.MoveNext()) yield return e.Current;
	}
Exemple #7
0
	/// <summary>
	/// Submits the resource tile selection.
	/// </summary>
	/// <remarks>
	/// NOTE: This may need a more sophisticated implementation if e.g., player action changes before server responds.
	/// </remarks>
	/// <param name='selection'>
	/// The resource tile selection.
	/// </param>
	protected void SubmitResourceTileSelection(ResourceTileSelection selection)
	{
		if (selection.Count() == 0) {
			GameGUIManager.use.SetErrorMessage("No tiles selected.");
			return;
		}
		if (isActionInProgress) {
			GameGUIManager.use.PlayInvalidActionSound();
			return;
		}
		
		//Check Resources
		/*
		if (!DoResourceCalculations(selection)) {
			return;
		}*/
		
		// if there is no API point, use the god mode implementation
		if (!hasServerAPIPoint) {
			StartCoroutine(Put(selection));
		}
		// otherwise use the api point on the server
		else {
			StartCoroutine(SubmitResourceTileSelectionToServerAPI(selection));
		}
	}