public override void OnNPCAtStockpile(ref NPCBase.NPCState state) { if (state.Inventory.IsEmpty) { Assert.IsTrue(shouldTakeItems); } else { state.Inventory.Dump(usedNPC.Colony.UsedStockpile); } state.SetCooldown(0.5); state.JobIsDone = true; if (shouldTakeItems) { shouldTakeItems = false; ScienceManagerPlayer scienceManager; if (!ScienceManager.TryGetPlayerManager(owner, out scienceManager)) { return; } ResearchProgress active = scienceManager.ActiveResearch; if (active.research != null && !active.IsCompleted) { var requirements = active.research.GetScienceRequirements(); if (Stockpile.GetStockPile(owner).TryRemove(requirements)) { state.Inventory.Add(requirements); } } } }
public ResearchResult(long completedCount, double investedPoints, ResearchProgress item, double leftoverPoints) { this.CompletedCount = completedCount; this.InvestedPoints = investedPoints; this.Item = item; this.LeftoverPoints = leftoverPoints; }
internal ResearchCompleteController(Player owner, ResearchTopic topic, GameController gameController, MainGame game) { this.game = game; this.gameController = gameController; this.Owner = owner; this.TopicProgress = this.game.States.ResearchAdvances.Of[owner].First(x => x.Topic == topic); this.priorities.AddRange(this.TopicProgress.Topic.Unlocks[this.TopicProgress.NextLevel]); }
internal ResearchTopicInfo(ResearchProgress tech, ResearchResult investmentResult) { this.Topic = tech.Topic; this.textVars = new Var(DevelopmentTopic.LevelKey, tech.NextLevel).Get; this.Cost = tech.Topic.Cost.Evaluate(textVars); this.InvestedPoints = tech.InvestedPoints; this.Investment = investmentResult.InvestedPoints; this.Level = tech.Level; this.NextLevel = investmentResult.CompletedCount > 1 ? tech.Level + (int)investmentResult.CompletedCount : tech.NextLevel; }
internal ResearchTopicInfo(ResearchProgress tech) { this.Topic = tech.Topic; this.textVars = new Var(DevelopmentTopic.LevelKey, tech.NextLevel).Get; this.Cost = tech.Topic.Cost.Evaluate(textVars); this.InvestedPoints = tech.InvestedPoints; this.Investment = 0; this.Level = tech.Level; this.NextLevel = tech.NextLevel; }
internal ResearchTopicInfo(ResearchProgress tech, ResearchResult investmentResult, IEnumerable <DevelopmentTopic> developmentTopics) { this.topic = tech.Topic; this.textVars = new Var(DevelopmentTopic.LevelKey, tech.NextLevel).Get; this.Cost = tech.Topic.Cost.Evaluate(textVars); this.InvestedPoints = tech.InvestedPoints; this.Investment = investmentResult.InvestedPoints; this.Level = tech.Level; this.NextLevel = investmentResult.CompletedCount > 1 ? tech.Level + (int)investmentResult.CompletedCount : tech.NextLevel; this.Unlocks = tech.Topic.Unlocks[tech.NextLevel].Select(id => new DevelopmentTopicInfo(new DevelopmentProgress( developmentTopics.First(x => x.IdCode == id), tech.Owner) )).ToArray(); }
public override void OnNPCAtJob(ref NPCBase.NPCState state) { usedNPC.LookAt(position.Vector); ScienceManagerPlayer scienceManager; if (!ScienceManager.TryGetPlayerManager(owner, out scienceManager)) { state.SetIndicator(new Shared.IndicatorState(6f, BuiltinBlocks.ErrorIdle)); state.JobIsDone = false; return; } ResearchProgress active = scienceManager.ActiveResearch; if (state.Inventory.IsEmpty) { if (active.research != null && !active.IsCompleted) { // no items, but valid research -> try to get items IList <InventoryItem> requirements = active.research.GetScienceRequirements(); Stockpile stockpile = Stockpile.GetStockPile(owner); if (Stockpile.GetStockPile(owner).Contains(requirements)) { shouldTakeItems = true; state.SetCooldown(0.3); state.JobIsDone = true; } else { ushort missing = 0; for (int i = 0; i < requirements.Count; i++) { if (!stockpile.Contains(requirements[i])) { missing = requirements[i].Type; break; } } float cooldown = Random.NextFloat(8f, 16f); state.SetIndicator(new Shared.IndicatorState(cooldown, missing, true, false)); state.JobIsDone = false; } } else { float cooldown = Random.NextFloat(8f, 16f); // no items, no research -> wait for research state.SetIndicator(new Shared.IndicatorState(cooldown, BuiltinBlocks.ErrorIdle)); state.JobIsDone = false; } } else { if (active.research == null || active.IsCompleted) { // items, but no valid research -> go dump items shouldTakeItems = true; state.SetCooldown(0.3); state.JobIsDone = true; } else { // items, valid research -> try progress IResearchable researchable = active.research; IList <InventoryItem> requirements = researchable.GetScienceRequirements(); if (state.Inventory.TryRemove(requirements)) { int recycled = 0; for (int i = 0; i < requirements.Count; i++) { ushort type = requirements[i].Type; if (type == BuiltinBlocks.ScienceBagLife || type == BuiltinBlocks.ScienceBagBasic || type == BuiltinBlocks.ScienceBagMilitary) { recycled += requirements[i].Amount; } } for (int i = recycled; i > 0; i--) { if (Random.NextDouble() > RECYCLE_CHANCE) { recycled--; } } state.Inventory.Add(BuiltinBlocks.LinenBag, recycled); scienceManager.AddActiveResearchProgress(1); state.SetIndicator(new Shared.IndicatorState(CraftingCooldown, NPCIndicatorType.Science)); } else { state.SetCooldown(0.3); } shouldTakeItems = true; state.JobIsDone = true; } } }
private static Tuple <StatesDB, Player[], Player> loadSaveData(IkonComposite saveData, ObjectDeindexer deindexer, StaticsDB statics) { var stateData = saveData[MainGame.StatesKey].To <IkonComposite>(); var ordersData = saveData[MainGame.OrdersKey].To <IkonArray>(); var stars = new StarCollection(); foreach (var rawData in stateData[StatesDB.StarsKey].To <IEnumerable <IkonComposite> >()) { stars.Add(StarData.Load(rawData, deindexer)); } var planets = new PlanetCollection(); foreach (var rawData in stateData[StatesDB.PlanetsKey].To <IEnumerable <IkonComposite> >()) { planets.Add(Planet.Load(rawData, deindexer)); } var wormholes = new WormholeCollection(); foreach (var rawData in stateData[StatesDB.WormholesKey].To <IEnumerable <IkonComposite> >()) { wormholes.Add(Wormhole.Load(rawData, deindexer)); } var players = new List <Player>(); foreach (var rawData in saveData[MainGame.PlayersKey].To <IEnumerable <IkonComposite> >()) { players.Add(Player.Load(rawData, deindexer)); } var organellePlayer = Player.Load(saveData[MainGame.OrganellePlayerKey].To <IkonComposite>(), deindexer); var developments = new DevelopmentProgressCollection(); foreach (var rawData in stateData[StatesDB.DevelopmentAdvancesKey].To <IEnumerable <IkonComposite> >()) { developments.Add(DevelopmentProgress.Load(rawData, deindexer)); } var research = new ResearchProgressCollection(); foreach (var rawData in stateData[StatesDB.ResearchAdvancesKey].To <IEnumerable <IkonComposite> >()) { research.Add(ResearchProgress.Load(rawData, deindexer)); } var treaties = new TreatyCollection(); foreach (var rawData in stateData[StatesDB.TreatiesKey].To <IEnumerable <IkonComposite> >()) { treaties.Add(Treaty.Load(rawData, deindexer)); } var reports = new ReportCollection(); foreach (var rawData in stateData[StatesDB.ReportsKey].To <IEnumerable <IkonComposite> >()) { reports.Add(ReportFactory.Load(rawData, deindexer)); } var designs = new DesignCollection(); foreach (var rawData in stateData[StatesDB.DesignsKey].To <IEnumerable <IkonComposite> >()) { var design = Design.Load(rawData, deindexer); design.CalcHash(statics); designs.Add(design); deindexer.Add(design.ConstructionProject, design.ConstructionProject.IdCode); } var colonizations = new ColonizationCollection(); foreach (var rawData in stateData[StatesDB.ColonizationKey].To <IEnumerable <IkonComposite> >()) { colonizations.Add(ColonizationProject.Load(rawData, deindexer)); } var fleets = new FleetCollection(); foreach (var rawData in stateData[StatesDB.IdleFleetsKey].To <IEnumerable <IkonComposite> >()) { fleets.Add(Fleet.Load(rawData, deindexer)); } var colonies = new ColonyCollection(); foreach (var rawData in stateData[StatesDB.ColoniesKey].To <IEnumerable <IkonComposite> >()) { colonies.Add(Colony.Load(rawData, deindexer)); } var stellarises = new StellarisCollection(); foreach (var rawData in stateData[StatesDB.StellarisesKey].To <IEnumerable <IkonComposite> >()) { stellarises.Add(StellarisAdmin.Load(rawData, deindexer)); } for (int i = 0; i < players.Count; i++) { players[i].Orders = PlayerOrders.Load(ordersData[i].To <IkonComposite>(), deindexer); } organellePlayer.Orders = PlayerOrders.Load(saveData[MainGame.OrganelleOrdersKey].To <IkonComposite>(), deindexer); return(new Tuple <StatesDB, Player[], Player>( new StatesDB(stars, wormholes, planets, colonies, stellarises, developments, research, treaties, reports, designs, fleets, colonizations), players.ToArray(), organellePlayer )); }
public ScreenItemResearchProgress(Game game, ApplicationSkin skin, int x, int y, int width, ResearchProgress researchProgress) : base(game, skin, x, y, width) { this.ResearchProgress = researchProgress; }