Ejemplo n.º 1
0
        private ITool GetTool(Building building)
        {
            // Get the appropriate build tool for the selected building
            var buildingType = building.GetType();

            if (buildingType == typeof(RailStation))
            {
                _logger.Log("Returning Station");
                return(new RailStationBuilderTool((RailStation)building));
            }
            if (buildingType == typeof(Road))
            {
                _logger.Log("Returning RoadBuilderTool");
                return(new RoadBuilderTool((Road)building));
            }

            if (buildingType == typeof(Rail))
            {
                _logger.Log("Returning RailBuilderTool");
                return(new RailBuilderTool((Rail)building));
            }

            // Fetch the building recipe by its asset_id
            BuildingRecipe buildingRecipe = BuildingRecipeManager.Current.Get(building.AssetId);
            BuilderTool    builderTool    = BuilderToolManager.Current.GetTool(buildingRecipe);

            return(builderTool);
        }
Ejemplo n.º 2
0
        private void CalculateMinedItemsPerMonth()
        {
            List <Mine> mines = Manager <AssetLibrary> .Current.GetAll <Mine>();

            BuildingRecipeManager buildMan = LazyManager <BuildingRecipeManager> .Current;

            _minedItemsPerMonth = new Dictionary <Item, ValueTuple <int, Mine> >();
            foreach (Mine mine in mines)
            {
                BuildingRecipe recipe = buildMan.Get(mine.AssetId);
                if (recipe.Hidden == false && recipe.IsUnlocked == true)
                {
                    int itemsPerMonth = (int)Math.Round(1 / mine.SharedData.OutputInterval / TimeManager.GameMonthsPerSecond);
                    var storages      = LazyManager <StorageManager> .Current.GetStorages(mine.AssetId);

                    if (storages != null)
                    {
                        foreach (Storage storage in storages.ToList())
                        {
                            bool noChange;
                            if (noChange = _minedItemsPerMonth.TryGetValue(storage.Item, out (int count, Mine itemMine)itemData))
                            {
                                if (itemData.count < itemsPerMonth)
                                {
                                    noChange = false;
                                }
                            }
                            if (!noChange)
                            {
                                _minedItemsPerMonth[storage.Item] = (itemsPerMonth, mine);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static public object Rit_RefreshUpgradeIdol(Thea2.Server.Group target, RitualsTask sourceTask)
        {
            if (target != null && target.items != null)
            {
                BuildingRecipe br = (BuildingRecipe)BUILD_REC.IDOL;

                var oldIdol = target.items.Find(o => o.GetItem().GetSource() == br);
                if (oldIdol == null)
                {
                    return(null);
                }

                var oldDemon = oldIdol.GetItem().superConnection;

                #region Create new idol
                List <ItemBase> ibs = ItemBase.items.Where(o =>
                                                           o.GetSource() == br &&
                                                           (o as ItemCrafted).recipeIngredientCount[0] == sourceTask.GetMaterial1Count() &&
                                                           (o as ItemCrafted).recipeIngreadients[0].Get() == sourceTask.GetMaterial1()).ToList();

                if (ibs.Count != 1)
                {
                    Debug.LogError("[ERROR]Number of options in upgrade idol is different than 1: " + ibs.Count);
                    return(null);
                }

                ItemCrafted ib    = ibs[0] as ItemCrafted;
                ItemBase    inst  = ib.Clone <ItemBase>(true);
                Skill       skill = null;
                if (br.skills != null)
                {
                    if (!SkillInstance.skillPacks.ContainsKey(br.skills))
                    {
                        Debug.LogError("[ERROR]Missing skillpack " + br.skills);
                        return(null);
                    }

                    List <Skill>           si            = SkillInstance.skillPacks[br.skills];
                    HashSet <Tag>          essences      = new HashSet <Tag>();
                    Dictionary <Tag, FInt> essenceCounts = new Dictionary <Tag, FInt>();
                    List <Skill>           valid         = new List <Skill>();

                    CountedResource material1 = null;
                    CountedResource material2 = null;
                    if (ib.recipeIngreadients.Length > 0)
                    {
                        material1 = new CountedResource();
                        material1.resourceName  = ib.recipeIngreadients[0].Get();
                        material1.resourceCount = ib.recipeIngredientCount[0];
                    }
                    if (ib.recipeIngreadients.Length > 1)
                    {
                        material2 = new CountedResource();
                        material2.resourceName  = ib.recipeIngreadients[1].Get();
                        material2.resourceCount = ib.recipeIngredientCount[1];
                    }

                    if (material1 != null)
                    {
                        foreach (var v in material1.resourceName.essences)
                        {
                            FInt count = new FInt(v.amount) * material1.resourceCount;
                            if (count <= 0)
                            {
                                continue;
                            }

                            essences.Add(v.tag);
                            essenceCounts[v.tag] = count;
                        }
                    }
                    if (material2 != null)
                    {
                        foreach (var v in material2.resourceName.essences)
                        {
                            FInt count = new FInt(v.amount) * material2.resourceCount;
                            if (count <= 0)
                            {
                                continue;
                            }

                            if (!essences.Contains(v.tag))
                            {
                                essences.Add(v.tag);
                            }

                            if (!essenceCounts.ContainsKey(v.tag))
                            {
                                essenceCounts[v.tag] = count;
                            }
                            else
                            {
                                essenceCounts[v.tag] += count;
                            }
                        }

                        if (essences.Count > 0)
                        {
                            Tag g = (Tag)TAG.ESSENCE_GRAY;
                            essences.Add(g);
                        }
                    }

                    foreach (var v in si)
                    {
                        bool b = true;
                        foreach (var e in v.baseEssence)
                        {
                            if (!essences.Contains(e.tag))
                            {
                                b = false;
                                break;
                            }
                        }

                        if (!b)
                        {
                            continue;
                        }

                        valid.Add(v);
                    }

                    if (valid.Count < 1)
                    {
                        Debug.LogError("[ERROR]No valid skill during upgrade of the idol in skillpack " + br.skills);
                        return(null);
                    }
                    skill = valid[0];
                }

                if (skill != null)
                {
                    inst.skill = SkillInstance.Instantiate(skill, inst);
                }
                #endregion
                #region Destroy old idol
                //destroy old idol
                var ceb = target.TakeItem(oldIdol.GetItem(), 1);
                ceb.GetItem().Destroy();
                #endregion

                //Add new idol
                var cebNewIdol = target.AddItem(inst, 1);

                //super connect with old demon to keep it alive if one was still there, otherwise it will create new one.
                if (oldDemon != null && oldDemon.Valid())
                {
                    cebNewIdol.GetItem().SuperConnectWith(oldDemon);
                }
            }

            return(null);
        }