Exemplo n.º 1
0
	public void StoreItem(Vector2 pos, ForestItemEnum itmType)
    {
        StorageArea area;
		switch(itmType)
		{
		case ForestItemEnum.eSavage:
			{
				GameObject go = GameObject.Instantiate (savageResourcePrefab, pos, Quaternion.identity) as GameObject;
                area = SavagesArea as StorageArea;
                    area.itemsList.Add(go.GetComponent<VillageItem>());
				go.transform.parent = (SavagesArea as StorageArea).transform;
			}
			break;

		case ForestItemEnum.eAnimal:
			{
				GameObject go = GameObject.Instantiate (animalResourcePrefab, pos, Quaternion.identity) as GameObject;
                area = AnimalsArea as StorageArea;
                    area.itemsList.Add(go.GetComponent<VillageItem>());
				go.transform.parent = (AnimalsArea as StorageArea).transform;
			}
			break;

		case ForestItemEnum.eFruit:
			{
				GameObject go = GameObject.Instantiate (fruitResourcePrefab, pos, Quaternion.identity) as GameObject;
                area = FruitsArea as StorageArea;
                    area.itemsList.Add(go.GetComponent<VillageItem>());
				go.transform.parent = (FruitsArea as StorageArea).transform;
			}
			break;
		}
    }
Exemplo n.º 2
0
	public int KillForestItemsOfType(ForestItemEnum itmType, int count) {
		int nItemsKilled = 0;

		IForestItem[] allItems = forestItemsContainer.GetComponentsInChildren<IForestItem> ();

		List<IForestItem> items = new List<IForestItem> ();
		foreach (var itm in allItems) {
			if (itm.ItemType == itmType)
				items.Add (itm);
		}

		int nItems = items.Count;

		int nAttempts = nItems * 2;

		while (nItems != 0) {
			int idx = Random.Range (0, nItems);
			bool isSafe = false;
			GameObject go = null;
			{
				Critter critter = items [idx] as Critter;
				if (critter != null) {
					go = critter.gameObject;
					isSafe = critter.IsSafeToKill;
				}
				else {
					ForestItem fi = items [idx] as ForestItem;
					if (fi != null) {
						go = fi.gameObject;
						isSafe = fi.IsSafeToKill;
					}
				}
			}

			if (go != null && isSafe) {
				++nItemsKilled;

				items [idx].Kill ();

				//swap delete
				items[idx] = items[nItems - 1];
				items.RemoveAt(nItems - 1);
				--nItems;
			}

			if (nItemsKilled == count)
				break;

			--nAttempts;
			if (nAttempts == 0)
				break;
		}

		return nItemsKilled;
	}
Exemplo n.º 3
0
	public void StoreForestItem(IForestItem item)
	{
		payLoadForestItem = item.ItemType;
		actionState = State.eStoringItem;

		switch (item.ItemType)
		{
		case ForestItemEnum.eFruit:
			MoveToPoint(Village.GetGlobalInstance().FruitsArea.AnyLocation);
			Payload.ShowPayload(VillageItemEnum.eFruit);
            item.ApplePicked();
			break;

		case ForestItemEnum.eAnimal:
			MoveToPoint (Village.GetGlobalInstance ().AnimalsArea.AnyLocation);
			Payload.ShowPayload (VillageItemEnum.eAnimal);

			Forest.GetGlobalInstance ().OnAnimalTamed ();
			GameObject.Destroy ((item as Critter).gameObject);
			break;

		case ForestItemEnum.eSavage:
			MoveToPoint(Village.GetGlobalInstance().SavagesArea.AnyLocation);
			Payload.ShowPayload(VillageItemEnum.eSavage);

			Forest.GetGlobalInstance ().OnSavageCaptured ();
			GameObject.Destroy((item as Critter).gameObject);
			break;
		}

		mTarget = null;
	}