Beispiel #1
0
    public void Build(BuildableData buildable)
    {
        Vector3 avgPos = Vector3.zero;

        for (int i = 0; i < placedInArea.Count; i++)
        {
            avgPos += placedInArea[i].transform.position;
            Destroy(placedInArea[i].gameObject);
        }
        avgPos /= placedInArea.Count;
        placedInArea.Clear();
        areaDirty = true;
        if (placementLocation != null)
        {
            PlacementManager.Instance.SetTempArea(AreaType.Play);
            placementLocation.SetPlacable(buildable);
            PlacementManager.Instance.RestoreArea();
        }
        else
        {
            PlayerManager.Instance.AddInventory(buildable);
        }
        if (upgrading != null)
        {
            SetUpgrading(buildable as UpgradableData);
            builtObj = null;
        }
        else
        {
            builtObj = Instantiate(buildable.Prefab, avgPos, Quaternion.identity, transform);
        }
        StartCoroutine(StoreBuilt());
    }
    public void Show(BuildArea buildArea, BuildableData buildable)
    {
        this.buildArea = buildArea;
        this.buildable = buildable;
        amount         = 0;
        built          = false;

        PlacementManager.Instance.enabled = false;
        //UIManager.Instance.ShowUI(gameObject);
        tool.SetActive(true);
        particles.gameObject.SetActive(true);
    }
    public void AddWeightedRandomLetter(CatData cat)
    {
        List <CatData> unfoundCats = new List <CatData>();

        for (int i = 0; i < DataManager.Instance.Cats.Length; i++)
        {
            if (!CatManager.Instance.IsFound(DataManager.Instance.Cats[i]))
            {
                unfoundCats.Add(DataManager.Instance.Cats[i]);
            }
        }
        Dictionary <PlacableData, int> weights = new Dictionary <PlacableData, int>();
        int totalWeight = 0;

        for (int i = 0; i < DataManager.Instance.Cats.Length; i++)
        {
            int weight = 1;
            if (unfoundCats.Count > 0 && DataManager.Instance.Cats[i] == unfoundCats[0])
            {
                weight = 20;
            }
            else if (unfoundCats.Count > 1 && DataManager.Instance.Cats[i] == unfoundCats[1])
            {
                weight = 7;
            }
            else if (unfoundCats.Count > 2 && DataManager.Instance.Cats[i] == unfoundCats[2])
            {
                weight = 2;
            }
            AddWeight(weights, DataManager.Instance.TowerComponents[(int)DataManager.Instance.Cats[i].RequiredTowerType], weight * DataManager.Instance.GetTowerMatAmount(DataManager.Instance.Cats[i].RequiredTowerType, DataManager.Instance.Cats[i].RequiredTowerLevel) / 2, ref totalWeight);
            for (int j = 0; j < DataManager.Instance.Cats[i].OtherRequirements.Length; j++)
            {
                BuildableData buildable = DataManager.Instance.Cats[i].OtherRequirements[j] as BuildableData;
                if (!buildable.Unlimited)
                {
                    if (!PlayerManager.Instance.HasRecipe(buildable) && !HasRecipe(buildable))
                    {
                        for (int k = 0; k < DataManager.Instance.ToyRecipes.Length; k++)
                        {
                            if (DataManager.Instance.ToyRecipes[k].Product == buildable)
                            {
                                AddWeight(weights, DataManager.Instance.ToyRecipes[k], weight, ref totalWeight);
                                break;
                            }
                        }
                        for (int k = 0; k < DataManager.Instance.TreatRecipes.Length; k++)
                        {
                            if (DataManager.Instance.TreatRecipes[k].Product == buildable)
                            {
                                AddWeight(weights, DataManager.Instance.TreatRecipes[k], weight, ref totalWeight);
                                break;
                            }
                        }
                    }
                    for (int k = 0; k < buildable.BuildRequirements.Length; k++)
                    {
                        AddWeight(weights, buildable.BuildRequirements[k], weight, ref totalWeight);
                    }
                }
            }
        }
        Dictionary <PlacableData, int> gifts = new Dictionary <PlacableData, int>();

        for (int i = 0; i < 4; i++)
        {
            int randWeight = Random.Range(0, totalWeight);
            int currWeight = 0;
            foreach (KeyValuePair <PlacableData, int> pair in weights)
            {
                currWeight += pair.Value;
                if (currWeight > randWeight)
                {
                    if (gifts.ContainsKey(pair.Key))
                    {
                        if (pair.Key.DataType != PlacableDataType.ToyRecipe && pair.Key.DataType != PlacableDataType.TreatRecipe)
                        {
                            gifts[pair.Key]++;
                        }
                    }
                    else
                    {
                        gifts.Add(pair.Key, 1);
                    }
                    break;
                }
            }
        }
        AddLetter(new Letter(cat, gifts));
    }