void SetupConfigs() { IUnitConfigDataProvider database; //todo guard if (LSDatabaseManager.TryGetDatabase(out database)) { ConfigElementData = database.UnitConfigElementData; ConfigElementMap = new Dictionary <string, UnitConfigElementDataItem> (); for (int i = 0; i < ConfigElementData.Length; i++) { var item = ConfigElementData [i]; ConfigElementMap.Add(item.Name, item); } ConfigData = database.UnitConfigData; for (int i = 0; i < ConfigData.Length; i++) { IUnitConfigDataItem item = ConfigData [i]; RTSAgent agent = GameResourceManager.GetAgentTemplate(item.Target); for (int j = 0; j < item.Stats.Length; j++) { Stat stat = item.Stats [j]; //todo guard var element = ConfigElementMap [stat.ConfigElement]; Component component = agent.GetComponent(element.ComponentType); SetField(component, element.Field, stat.Value); } } } }
public override void DecideWhatToDo() { base.DecideWhatToDo(); if (Agent.Tag == AgentTag.Harvester && cachedHarvest.IsFocused) { //convert to fast list... List <RTSAgent> resources = new List <RTSAgent>(); foreach (RTSAgent nearbyObject in nearbyObjects) { ResourceDeposit resource = nearbyObject.GetAbility <ResourceDeposit>(); if (resource && !resource.IsEmpty()) { resources.Add(nearbyObject); } } RTSAgent nearestObject = WorkManager.FindNearestWorldObjectInListToPosition(resources, transform.position); if (nearestObject) { ResourceDeposit closestResource = nearestObject.GetAbility <ResourceDeposit>(); // only harvest resources the worker is assigned to if (closestResource && closestResource.ResourceType == cachedHarvest.HarvestType) { // send harvest command Command harvestCom = new Command(AbilityDataItem.FindInterfacer("Harvest").ListenInputID); harvestCom.Add <DefaultData>(new DefaultData(DataType.UShort, nearestObject.GlobalID)); UserInputHelper.SendCommand(harvestCom); } } } if (Agent.Tag == AgentTag.Builder && cachedBuild.IsFocused) { //convert to fast array List <RTSAgent> buildings = new List <RTSAgent>(); foreach (RTSAgent nearbyObject in nearbyObjects) { if (nearbyObject.GetCommander() != Agent.Controller.Commander) { continue; } RTSAgent nearbyBuilding = nearbyObject.GetComponent <RTSAgent>(); if (nearbyBuilding && nearbyBuilding.GetAbility <Structure>().UnderConstruction()) { buildings.Add(nearbyObject); } } RTSAgent nearestObject = WorkManager.FindNearestWorldObjectInListToPosition(buildings, transform.position); if (nearestObject) { RTSAgent closestBuilding = nearestObject.GetComponent <RTSAgent>(); if (closestBuilding) { // send build command Command buildCom = new Command(AbilityDataItem.FindInterfacer("Construct").ListenInputID); buildCom.Add <DefaultData>(new DefaultData(DataType.UShort, closestBuilding.GlobalID)); UserInputHelper.SendCommand(buildCom); } } else { cachedBuild.SetCurrentProject(null); } } }