public ResearchTechControlVM(FactionTechDB factionTech, Guid techID) { _factionTech = factionTech; _techSD = factionTech.GetResarchableTech(techID).tech; }
/// <summary> /// adds research points to a scientists project. /// </summary> /// <param name="entity"></param> /// <param name="factionAbilities"></param> /// <param name="factionTechs"></param> internal void DoResearch(Entity entity) { Entity faction; entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction); FactionAbilitiesDB factionAbilities = faction.GetDataBlob <FactionAbilitiesDB>(); FactionTechDB factionTechs = faction.GetDataBlob <FactionTechDB>(); EntityResearchDB entityResearch = entity.GetDataBlob <EntityResearchDB>(); //Dictionary<ComponentInstance, int> labs = entityResearch.Labs; List <(ComponentInstance lab, int pnts)> allLabs = new List <(ComponentInstance lab, int pnts)>(); if (entity.GetDataBlob <ComponentInstancesDB>().TryGetComponentsByAttribute <ResearchPointsAtbDB>(out var labs)) { foreach (var labInstance in labs) { var points = labInstance.Design.GetAttribute <ResearchPointsAtbDB>().PointsPerEconTick; allLabs.Add((labInstance, points)); } } int labIndex = 0; int maxLabs = allLabs.Count; foreach (Scientist scientist in entity.GetDataBlob <TeamsHousedDB>().TeamsByType[TeamTypes.Science]) { if (scientist.ProjectQueue.Count == 0) { continue; } Guid projectGuid = scientist.ProjectQueue[0].techID; bool cycleProject = scientist.ProjectQueue[0].cycle; if (!factionTechs.IsResearchable(projectGuid)) { scientist.ProjectQueue.RemoveAt(0); continue; } int assignedLabs = scientist.AssignedLabs; //(TechSD)scientist.GetDataBlob<TeamsDB>().TeamTask; TechSD project = factionTechs.GetResarchableTech(projectGuid).tech;//_staticData.Techs[projectGuid]; //int numProjectLabs = scientist.TeamSize; float bonus = 1; if (scientist.Bonuses.ContainsKey(project.Category)) { bonus += scientist.Bonuses[project.Category]; } //bonus *= BonusesForType(factionEntity, colonyEntity, InstallationAbilityType.Research); int researchPoints = 0; var maxIndex = Math.Max(labIndex + assignedLabs, maxLabs); //shouldn't happen unless assigned labs is more than the labs availible. for (int i = labIndex; i < maxIndex; i++) { researchPoints += allLabs[i].pnts; } researchPoints = (int)(researchPoints * bonus); if (factionTechs.IsResearchable(project.ID)) { int currentLvl = factionTechs.GetLevelforTech(project); factionTechs.AddPoints(project.ID, researchPoints); if (factionTechs.GetLevelforTech(project) > currentLvl) { scientist.ProjectQueue.RemoveAt(0); if (cycleProject) { scientist.ProjectQueue.Add((project.ID, true)); } } } } }