private static bool ShouldBeCraftable(Item item)
        {
            // a bunch of things that aren't really 'items' per se
            if (item is Skill)
            {
                return(false);
            }
            if (item is ActionbarItem)
            {
                return(false);
            }
            if (item is SkillScroll)
            {
                return(false);
            }
            if (item.Hidden)
            {
                return(false);
            }

            // items that you have other means of acquiring and therefore needn't be craftable
            if (OrganismItemManager.SourceSpeciesForItem(item.Type).Any())
            {
                return(false);
            }
            if (item is SkillBook && PlayerDefaults.GetDefaultSkills().Contains((item as SkillBook).SkillType))
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public override Result OnAreaValid(Player player, Vector3i position, Quaternion rotation)
        {
            Deed deed = PropertyManager.FindNearbyDeedOrCreate(player.User, position.XZ);

            foreach (var plot in WorldObject.GetOccupiedPropertyPositions(typeof(StarterCampObject), position, rotation))
            {
                PropertyManager.Claim(deed.Id, player.User, player.User.Inventory, plot);
            }

            var camp      = WorldObjectManager.TryToAdd(typeof(CampsiteObject), player.User, position, rotation, false);
            var stockpile = WorldObjectManager.TryToAdd(typeof(TinyStockpileObject), player.User, position + rotation.RotateVector(Vector3i.Right * 3), rotation, false);

            player.User.OnWorldObjectPlaced.Invoke(camp);
            player.User.Markers.Add(camp.Position3i + Vector3i.Up, camp.UILinkContent());
            player.User.Markers.Add(stockpile.Position3i + Vector3i.Up, stockpile.UILinkContent());
            var storage   = camp.GetComponent <PublicStorageComponent>();
            var changeSet = new InventoryChangeSet(storage.Inventory);

            PlayerDefaults.GetDefaultCampsiteInventory().ForEach(x =>
            {
                changeSet.AddItems(x.Key, x.Value, storage.Inventory);
            });
            changeSet.Apply();
            return(Result.Succeeded);
        }
Exemple #3
0
        public override void OnAreaValid(GameActionPack pack, Player player, Vector3i position, Quaternion rotation)
        {
            var deed = PropertyManager.FindConnectedDeedOrCreate(player.User, position.XZ);

            foreach (var plotPosition in PlotUtil.GetAllPropertyPos(position, virtualOccupancy))
            {
                if (!this.IsPlotAuthorized(plotPosition, player.User, out var canClaimPlot))
                {
                    return;
                }

                if (canClaimPlot)
                {
                    pack.ClaimProperty(deed, player.User, player.User.Inventory, plotPosition, requirePapers: false);
                }
            }

            if (!pack.EarlyResult)
            {
                return;
            }

            pack.AddPostEffect(() =>
            {
                var camp      = WorldObjectManager.ForceAdd(typeof(CampsiteObject), player.User, position, rotation, false);
                var stockpile = WorldObjectManager.ForceAdd(typeof(TinyStockpileObject), player.User, position + rotation.RotateVector(Vector3i.Right * 3), rotation, false);
                player.User.OnWorldObjectPlaced.Invoke(camp);
                player.User.Markers.Add(camp.Position3i + Vector3i.Up, camp.UILinkContent(), false);
                var storage   = camp.GetComponent <PublicStorageComponent>();
                var changeSet = new InventoryChangeSet(storage.Inventory);
                PlayerDefaults.GetDefaultCampsiteInventory().ForEach(x => changeSet.AddItems(x.Key, x.Value, storage.Inventory));

                //If we're running a settlement system, create the homestead item now and fill it with homestead-specific claim papers.
                if (SettlementPluginConfig.Obj.SettlementSystemEnabled)
                {
                    var marker     = WorldObjectManager.ForceAdd(typeof(HomesteadMarkerObject), player.User, position + rotation.RotateVector(new Vector3i(3, 0, 3)), rotation, false);
                    var markerComp = marker.GetComponent <SettlementMarkerComponent>();
                    markerComp.Settlement.Citizenship.AddSpawnedClaims(this.bonusPapers);
                    markerComp.UpdateSpawnedClaims();
                }
                else
                {
                    //For the old system, add the papers to the tent.
                    if (this.bonusPapers > 0)
                    {
                        changeSet.AddItems(typeof(PropertyClaimItem), this.bonusPapers);
                    }
                }
                changeSet.Apply();
            });
        }
        public override Result OnAreaValid(Player player, Vector3i position, Quaternion rotation)
        {
            Result authAtPosOne = AuthManager.IsAuthorized(position, player.User);
            Result authAtPosTwo = AuthManager.IsAuthorized((position + rotation.RotateVector(Vector3i.Right * 3)).Round, player.User);

            if (!authAtPosOne.Success)
            {
                return(authAtPosOne);
            }
            else if (!authAtPosTwo.Success)
            {
                return(authAtPosTwo);
            }

            Deed deed = PropertyManager.FindNearbyDeedOrCreate(player.User, position.XZ);
            var  dist = position.XZ - World.GetPropertyPos(position.XZ) - (World.PropertyPlotLength / 2);

            if (dist.x == 0 || dist.y == 0)
            {
                dist = rotation.RotateVector(new Vector3i(1, 0, 1)).XZi;
            }
            dist = new Vector2i(Math.Sign(dist.x), Math.Sign(dist.y));
            Vector2i.XYIter(2).ForEach(x => PropertyManager.Claim(deed.Id, player.User, position.XZ + (new Vector2i(dist.x * x.x, dist.y * x.y) * World.PropertyPlotLength)));

            var camp      = WorldObjectManager.TryToAdd(typeof(CampsiteObject), player.User, position, rotation, false);
            var stockpile = WorldObjectManager.TryToAdd(typeof(TinyStockpileObject), player.User, position + rotation.RotateVector(Vector3i.Right * 3), rotation, false);

            player.User.OnWorldObjectPlaced.Invoke(camp);
            player.User.Markers.Add(camp.Position3i + Vector3i.Up, camp.UILinkContent());
            player.User.Markers.Add(stockpile.Position3i + Vector3i.Up, stockpile.UILinkContent());
            var storage   = camp.GetComponent <PublicStorageComponent>();
            var changeSet = new InventoryChangeSet(storage.Inventory);

            PlayerDefaults.GetDefaultCampsiteInventory().ForEach(x =>
            {
                changeSet.AddItems(x.Key, x.Value, storage.Inventory);
            });
            changeSet.Apply();
            return(Result.Succeeded);
        }
Exemple #5
0
        public static void TechTreeSimulation(User user)
        {
            using (StreamWriter sw = new StreamWriter("TechTreeSimulation.txt"))
            {
                var data = new TechTreeSimData();
                sw.WriteLine("Starting Tech Tree Sim");

                sw.WriteLine("Getting Starting Skills...");
                var introSkills = PlayerDefaults.GetDefaultSkills().ToList();
                introSkills.ForEach(x => data.AddSkill(sw, x));

                sw.WriteLine("Getting Initial Tables...");
                data.craftingTables.Add(typeof(CampsiteObject));

                sw.WriteLine("Getting Recipes with No Skills...");
                var temp = Recipe.AllRecipes.Where(x => !x.RequiredSkills.Any() && x.Ingredients.Any());
                data.unusableRecipes.AddRange(Recipe.AllRecipes.Where(x => !x.RequiredSkills.Any() && x.Ingredients.Any()));

                sw.WriteLine("Getting World Resources...");
                //manually defined for now since theres no easy way of checking for these
                data.craftableItems.AddRange(new List <Type>()
                {
                    typeof(DirtItem),
                    typeof(SandItem),
                    typeof(StoneItem),
                    typeof(IronOreItem),
                    typeof(CopperOreItem),
                    typeof(GoldOreItem),
                    typeof(CoalItem)
                });

                sw.WriteLine("Getting Species Resources...");
                var seedless     = new List <Species>();
                var resourceless = new List <Species>();
                EcoSim.AllSpecies.ForEach(x =>
                {
                    sw.WriteLine("Adding Species: " + x.DisplayName);
                    if (x is PlantSpecies)
                    {
                        if ((x as PlantSpecies).SeedItem.Type != null && (x as PlantSpecies).SeedRange.Max > 0 && (x as PlantSpecies).SeedRange.Min <= (x as PlantSpecies).SeedRange.Max)
                        {
                            var item = (x as PlantSpecies).SeedItem.Type;
                            data.craftableItems.AddUnique(item);
                            sw.WriteLine(" - New Resource: " + item.Name);
                        }
                        else
                        {
                            seedless.Add(x);
                        }
                    }
                    if (x.ResourceItem.Type != null && x.ResourceRange.Max > 0 && x.ResourceRange.Min <= x.ResourceRange.Max)
                    {
                        var item = x.ResourceItem.Type;
                        data.craftableItems.AddUnique(item);
                        sw.WriteLine(" - New Resource: " + item.Name);
                    }
                    else
                    {
                        resourceless.Add(x);
                    }
                });
                sw.WriteLine("\nSimulating...\n");
                UpdateRecipes(sw, data);
                UpdateRecipesFromSkills(sw, data);
                sw.WriteLine("\nTech Tree Sim Complete");
                ChatManager.SendChat(CheckStatus(sw, data) ? "Tech Tree Complete" : "Tech Tree Failed, check the TechTreeSimulation.txt for more information.", user.Player.ID); //get issues with complete

                //PLANT DATA
                sw.WriteLine("\nPlants Missing Seeds");
                sw.WriteLine(String.Join(",", seedless));
                sw.WriteLine("Plants Missing Resources");
                sw.WriteLine(String.Join(",", resourceless));

                //CRAFTABLES
                sw.WriteLine("\nUncraftable Accessed");
                foreach (var recipe in data.unusableRecipes)
                {
                    sw.WriteLine("  " + recipe.DisplayName);
                    recipe.Ingredients.ForEach(x => sw.WriteLine("    I: " + x.Item.DisplayName));
                    recipe.Products.ForEach(x => sw.WriteLine("    P: " + x.Item.DisplayName));

                    if (!data.craftableItems.Contains(recipe.Ingredients.Select(x => x.Item.Type)))
                    {
                        sw.WriteLine("    missing ingredients");
                    }
                    if (!CraftingComponent.TablesForRecipe(recipe.GetType()).Intersect(data.craftingTables).Any())
                    {
                        sw.WriteLine("    missing crafting table");
                    }
                }
                sw.WriteLine("\nUncraftable Unaccessed");
                foreach (var recipe in Recipe.AllRecipes.Except(data.curRecipes))
                {
                    sw.WriteLine("  " + recipe.DisplayName);
                    recipe.Ingredients.ForEach(x => sw.WriteLine("    I: " + x.Item.DisplayName));
                    recipe.Products.ForEach(x => sw.WriteLine("    P: " + x.Item.DisplayName));

                    if (!data.curSkills.Contains(recipe.RequiredSkills.Select(x => x.SkillType)))
                    {
                        sw.WriteLine("    missing skills");
                    }
                    if (!data.craftableItems.Contains(recipe.Ingredients.Select(x => x.Item.Type)))
                    {
                        sw.WriteLine("    missing ingredients");
                    }
                    if (!CraftingComponent.TablesForRecipe(recipe.GetType()).Intersect(data.craftingTables).Any())
                    {
                        sw.WriteLine("    missing crafting table");
                    }
                }

                //ALL UNOBTAINABLE ITEMS
                sw.WriteLine("\nUnobtainable Items");
                foreach (var item in Item.AllItems
                         .Where(x => !(x is Skill) && !(x is ActionbarItem) && !(x is SkillScroll) && !(x.Category == "Hidden"))
                         .Select(x => x.Type)
                         .Except(data.craftableItems))
                {
                    sw.WriteLine("  " + item.Name);
                }
            }
        }
Exemple #6
0
        public static void TechTreeSimulation(User user)
        {
            var info = new InfoBuilder();
            var data = new TechTreeSimData();

            info.AppendLineLocStr("Starting Tech Tree Sim");

            info.AppendLineLocStr("Getting Starting Skills...");
            var introSkills = PlayerDefaults.GetDefaultSkills().ToList();

            introSkills.ForEach(x => data.AddSkill(x));

            info.AppendLineLocStr("Getting Initial Tables...");
            data.CraftingTables.Add(typeof(CampsiteObject));

            info.AppendLineLocStr("Getting Recipes with No Skills...");
            data.UnusableRecipes.AddRange(RecipeFamily.AllRecipes.SelectMany(x => x.Recipes).Where(x => !x.Family.RequiredSkills.Any() && x.Ingredients.Any()));

            info.AppendLineLocStr("Getting World Resources...");
            //manually defined for now since theres no easy way of checking for these
            data.AddItems(new List <Type>
            {
                typeof(DirtItem),
                typeof(SandItem),
                typeof(IronOreItem),
                typeof(CopperOreItem),
                typeof(GoldOreItem),
                typeof(CoalItem),
                typeof(ClayItem)
            });

            // Add all items with "Rock" tag
            data.AddItems(TagManager.TagToTypes[TagManager.Tag("Rock")]);

            info.AppendLineLocStr("Getting Species Resources...");
            var resourceless = new List <Species>();

            EcoSim.AllSpecies.ForEach(x =>
            {
                var speciesInfo = new InfoBuilder();
                AddNewResources(speciesInfo, x.ResourceList.Select(x => x.ResourceType), data);
                if (x is TreeSpecies treeSpecies)
                {
                    AddNewResources(speciesInfo, treeSpecies.TrunkResources.Keys, data);
                    AddNewResources(speciesInfo, treeSpecies.DebrisResources.Keys, data);
                }

                if (speciesInfo.IsEmpty)
                {
                    resourceless.Add(x);
                    speciesInfo.AppendLineLocStr("No resources");
                }

                info.AddSectionLoc($"Adding Species: {x.DisplayName}", speciesInfo);
            });

            info.AppendLine();
            info.AppendLineLocStr("Simulating...");
            info.AppendLine();

            UpdateRecipes(info, data);
            UpdateRecipesFromSkills(info, data);
            info.AppendLine();
            info.AppendLineLocStr("Tech Tree Sim Complete");
            ChatManager.SendChat(CheckStatus(info, data) ? "Tech Tree Complete" : "Tech Tree Failed, check the TechTreeSimulation.txt for more information.", user); //get issues with complete

            //PLANT DATA
            info.AppendLineLocStr("Plants Missing Resources");
            info.AppendLine(Localizer.NotLocalizedStr(string.Join(",", resourceless)));

            //CRAFTABLES
            var uncraftableAccessed = new InfoBuilder();

            foreach (var recipe in data.UnusableRecipes)
            {
                var recipeInfo = new InfoBuilder();
                ReportMissingIngredients(recipeInfo, recipe, data);

                if (!CraftingComponent.TablesForRecipe(recipe.Family.GetType()).Intersect(data.CraftingTables).Any())
                {
                    recipeInfo.AppendLineLocStr("- missing crafting table");
                }
                uncraftableAccessed.AddSection(recipe.DisplayName, recipeInfo);
            }
            info.AppendLine();
            info.AddSectionLocStr("Uncraftable Accessed", uncraftableAccessed);

            var uncraftableUnaccessed = new InfoBuilder();

            foreach (var recipe in RecipeFamily.AllRecipes.SelectMany(x => x.Recipes).Except(data.CurRecipes))
            {
                var recipeInfo        = new InfoBuilder();
                var missingSkillsInfo = new InfoBuilder();
                foreach (var skill in recipe.Family.RequiredSkills)
                {
                    if (!data.CurSkills.Contains(skill.SkillType))
                    {
                        missingSkillsInfo.AppendLine(skill.SkillItem.DisplayName);
                    }
                }
                recipeInfo.AddSectionLocStr("- missing skills:", missingSkillsInfo);

                ReportMissingIngredients(recipeInfo, recipe, data);

                // notify about missing crafting table
                if (!CraftingComponent.TablesForRecipe(recipe.Family.GetType()).Intersect(data.CraftingTables).Any())
                {
                    recipeInfo.AppendLineLocStr("- missing crafting table");
                }

                uncraftableUnaccessed.AddSection(recipe.DisplayName, recipeInfo);
            }
            info.AppendLine();
            info.AddSectionLocStr("Uncraftable Unaccessed", uncraftableUnaccessed);

            //ALL UNOBTAINABLE ITEMS
            info.AppendLine();
            info.AppendLineLocStr("Unobtainable Items");
            foreach (var item in Item.AllItems
                     .Where(x => !(x is Skill) && !(x is ActionbarItem) && !(x is SkillScroll) && !x.Hidden)
                     .Select(x => x.Type)
                     .Except(data.CraftableItems))
            {
                info.AppendLineLocStr("  " + item.Name);
            }

            using var sw = new StreamWriter("TechTreeSimulation.txt");
            sw.Write(info.ToLocString());
        }