public void StartLevel(GameObject[] playerShips)
    {
        int shipCount = playerShips.Count(s => s != null);
        int shipsPlaced = 0;

        if (playerShips[0] != null)
        {
            playerShips[0].transform.position = new Vector3(0, SpawnDistanceToCenter);
            playerShips[0].transform.RotateAround(new Vector3(0, 0, 0), Vector3.forward, (360f / shipCount) * shipsPlaced++ + 45);
            playerShips[0].SetActive(true);
        }
        if (playerShips[1] != null)
        {
            playerShips[1].transform.position = new Vector3(0, SpawnDistanceToCenter);
            playerShips[1].transform.RotateAround(new Vector3(0, 0, 0), Vector3.forward, (360f / shipCount) * shipsPlaced++ + 45);
            playerShips[1].SetActive(true);
        }
        if (playerShips[2] != null)
        {
            playerShips[2].transform.position = new Vector3(0, SpawnDistanceToCenter);
            playerShips[2].transform.RotateAround(new Vector3(0, 0, 0), Vector3.forward, (360f / shipCount) * shipsPlaced++ + 45);
            playerShips[2].SetActive(true);
        }
        if (playerShips[3] != null)
        {
            playerShips[3].transform.position = new Vector3(0, SpawnDistanceToCenter);
            playerShips[3].transform.RotateAround(new Vector3(0, 0, 0), Vector3.forward, (360f / shipCount) * shipsPlaced++ + 45);
            playerShips[3].SetActive(true);
        }
    }
Example #2
0
    void GenRecipes()
    {
        tier_ingredient = new List<HashSet<Ingredients>>();
        System.Random rnd = new System.Random((int)System.DateTime.Now.Ticks);
        if (tier_GmO == null)
        {
            tier_GmO = new List<HashSet<GameObject>>(new HashSet<GameObject>[] { });
            foreach (Transform tiers in base_ingredients.transform)
            {
                HashSet<GameObject> h = new HashSet<GameObject>();
                tier_GmO.Add(h);
                foreach (Transform ingredient in tiers)
                {
                    h.Add(ingredient.gameObject);
                }
            }
        }
        stat_ingredient = new Dictionary<Ingredients.stats, HashSet<Ingredients>>();
        part_ingredient = new Dictionary<Ingredients.bodyParts, HashSet<Ingredients>>();
        var values = System.Enum.GetValues(typeof(Ingredients.bodyParts));
        foreach(Ingredients.bodyParts value in values)
        {
            part_ingredient.Add(value, new HashSet<Ingredients>());
        }
        values = System.Enum.GetValues(typeof(Ingredients.stats));
        foreach (Ingredients.stats value in values)
        {
            stat_ingredient.Add(value, new HashSet<Ingredients>());
        }
        for (int x = 0; x < tier_GmO.Count; x++)
        {
            List<GameObject> ingredient_l = GetIngredientsTier(x);
            GameObject[] stats = new GameObject[ingredient_l.Count];
            int[] parts_n = new int[5];
            int[] parts_v = { 2, 3, 5 };
            for (int y = 0; y < 5; y++)
            {
                parts_n[y] = 1;
                for (int z = 0; z < 2; z++)
                {
                    int chk = rnd.Next(0, ingredient_l.Count);
                    stats[y*2+z] = ingredient_l[chk];
                    ingredient_l.RemoveAt(chk);
                }

            }
            for (int y = 0; y < 3; y++)
            {
                for (int a = 0; a < 3 || (y >= 2 && a < 4); a++)
                {
                    int min = parts_n.Min();
                    int count = 0;
                    if (min > 1)
                    {
                        count = parts_n.Where(elem => elem < 6 && elem % parts_v[y] > 0).Count();
                        min = 5;
                    }
                    else
                    {
                        count = parts_n.Where(elem => elem < 2).Count();
                        min = 1;
                    }
                    int chk = rnd.Next(0, count);
                    int ct = 0;
                    for (int z = 0; z < parts_n.Count(); z++)
                    {
                        if (ct == chk && parts_n[z] <= min && parts_n[z] % parts_v[y] > 0)
                        {
                            parts_n[z] *= parts_v[y];
                            break;
                        }
                        if (parts_n[z] <= min && parts_n[z] % parts_v[y] > 0)
                        {
                            ct++;
                        }
                    }
                }
            }
            HashSet<Ingredients> tier_set = new HashSet<Ingredients>();
            for (int y = 0; y < stats.Count(); y++)
            {
                foreach(int prime in parts_v)
                {
                    if(parts_n[y/2] % prime == 0)
                    {
                        Ingredients temp = new Ingredients(stats[y].name, y / 2, prime, x, stats[y]);
                        tier_set.Add(temp);
                        name_ingredient.Add(stats[y].name, temp);
                        stat_ingredient[((Ingredients.stats)(y / 2))].Add(temp);
                        part_ingredient[((Ingredients.bodyParts)prime)].Add(temp);
                        parts_n[y / 2] /= prime;
                        break;
                    }
                }
            }
            tier_ingredient.Add(tier_set);
        }
    }
Example #3
0
	// You can choose to have random items be created or pass in a chosen list.
	// If no list is provided, then random items are chosen.
	// This gets called from ItemSpawner after it spawns this itemStorer
	// gameObject.
	public void ItemSetup(bool large, int areaNumber, GameObject[] manualItemsChosen = null)
	{
		myAreaNumber = areaNumber;
		if(manualItemsChosen == null || manualItemsChosen.Count() == 0)
		{
			if(!large) // A small itemStorer was created.
			{
				// Half values.
				transform.localScale = Vector3.one * 0.5f;
				_totalItemsToCarry = Random.Range(1, 3); // Hold up to 2 when small.
				health = Mathf.RoundToInt(health * 0.5f);
			}
			else _totalItemsToCarry = Random.Range(3, 5); // Hold up to 4 when large.
			// More random choices with a higher appear rate. Very_High = 5 and
			// Very_Low = 1
			_maxRandomToChooseFrom = (int)Manager_Game.ItemAppearRate;
			itemsCanDrop = new List<GameObject>();
			for(int i = 0; i < _maxRandomToChooseFrom || itemsCanDrop.Count == _totalItemsToCarry; i++)
			{
				if(Random.value > 0.6f)
				{
					itemsCanDrop.Add(Manager_Game.instance.ICPrefabs[Random.Range(0, Manager_Game.instance.ICPrefabs.Count)]);
					continue;
				}
				if(Random.value > 0.5f)
				{
					itemsCanDrop.Add(Manager_Game.instance.ITPrefabs[Random.Range(0, Manager_Game.instance.ITPrefabs.Count)]);
					continue;
				}
				itemsCanDrop.Add(Manager_Game.instance.IWPrefabs[Random.Range(0, Manager_Game.instance.IWPrefabs.Count)]);
			}
		}
		else // Manually items chosen to choose from
		{
			List<GameObject> itemsToCreate = manualItemsChosen.ToList();

			if(!large)
			{
				// If small we will remove half of the amount of items we have.
				transform.localScale = Vector3.one * 0.5f;
				if(itemsToCreate.Count > 1)
				{
					_totalItemsToCarry = Mathf.RoundToInt(itemsToCreate.Count / 2);
					for(int i = 0; i < _totalItemsToCarry; i++)
					{
						if(i != _totalItemsToCarry - 1)
						{
							// Random chance of removing this one if we aren't at the
							// end.
							if(Random.value > 0.5f)
								itemsToCreate.RemoveAt(i);
						}
						else itemsToCreate.RemoveAt(i);
					}
				}
			}
			// Large so keep all items chosen.
			else _totalItemsToCarry = itemsToCreate.Count;
			itemsCanDrop = itemsToCreate;
		}
		GetComponent<Rigidbody>().drag = large ? 20 : 10;
	}
Example #4
0
    private bool WaypointsAreValid(GameObject[] waypoints)
    {
        //first check whether whey all have a OrderedWaypoint component
        if (!waypoints.All(x => x.GetComponent<OrderedWaypointForEditor>() != null))
        {
            EditorUtility.DisplayDialog("Error", "All waypoints must have an ordered waypoint component", "OK");
            return false;
        }
        //check if all Order fields on the orderwaypoint components are different

        if (waypoints.Count() != waypoints.Select(x=>x.GetComponent<OrderedWaypointForEditor>().Order).Distinct().Count())
        {
            EditorUtility.DisplayDialog("Error", "All waypoints must have a different order", "OK");
            return false;
        }
        return true;
    }
Example #5
0
    //find target closest to the unit, from array
    void FindTargetClosest(GameObject[] targets, bool ignoreUnits)
    {
        foundTarget = false;

        //if stunned
        if (myUnit.remainingMove <= 0 && myUnit.actionPoints <= 0 && myUnit.movespeed == 0) {
            return;
        }

        List<Node> shortestPath = new List<Node> ();
        myUnit.currentPath = new List<Node> ();
        float currentPathCost = Mathf.Infinity;
        int tx = 0;
        int ty = 0;

        // for each character, find path
        for (int i = 0; i < targets.Count(); ++i) {
            //get the target
            Unit targetUnit = targets[i].GetComponent<Unit>();
            if (targetUnit != null) {
                //if the target is alive
                if (!targetUnit.isDead && targetUnit != myUnit && targetUnit.isActive) {

                    //find the path to the target
                    myMap.GeneratePathTo(targetUnit.tileX, targetUnit.tileY, ignoreUnits);
                    //if a path was found
                    if (myUnit.currentPath.Count > 0) {
                        //remove the targets node
                        myUnit.currentPath.Remove(myMap.GetNode (targetUnit.tileX, targetUnit.tileY));
                        //remove all unreachable tiles
                        FindFurthestTileInPath();

                        // if the target is next to the unit
                        if (myUnit.currentPath.Count == 0) {
                            // if the current closest isnt already next to
                            if (currentPathCost != 0) {
                                foundTarget = true;
                                // set shortest path
                                shortestPath = myUnit.currentPath;
                                currentPathCost = 0;
                                tx = targetUnit.tileX;
                                ty = targetUnit.tileY;
                            }
                        } //else if the target is closer than the previous
                        else if (myUnit.currentPath.Last().cost < currentPathCost) {
                            // set shortest path
                            foundTarget = true;
                            shortestPath = myUnit.currentPath;
                            currentPathCost = myUnit.currentPath.Last().cost;
                            tx = targetUnit.tileX;
                            ty = targetUnit.tileY;
                        }
                    }
                }
            }
        }

        //set the target
        target = myMap.GetNode (tx, ty);
        myUnit.currentPath = shortestPath;
    }