public static NPCCrewConfig LoadConfigFile() { if (MyAPIGateway.Utilities.FileExistsInLocalStorage("NPCCrewConfig.xml", typeof(NPCCrewConfig)) == true) { try { NPCCrewConfig config = null; var reader = MyAPIGateway.Utilities.ReadFileInLocalStorage("NPCCrewConfig.xml", typeof(NPCCrewConfig)); string configcontents = reader.ReadToEnd(); config = MyAPIGateway.Utilities.SerializeFromXML <NPCCrewConfig>(configcontents); //LogEntry("Found Config File"); return(config); } catch (Exception exc) { Logging.Instance.WriteLine(string.Format("Logging.WriteLine Error: {0}", exc.ToString())); } } NPCCrewConfig defaultconfig = new NPCCrewConfig(); //LogEntry("Config File Not Found. Using Default Values"); using (var writer = MyAPIGateway.Utilities.WriteFileInLocalStorage("NPCCrewConfig.xml", typeof(NPCCrewConfig))) { writer.Write(MyAPIGateway.Utilities.SerializeToXML <NPCCrewConfig>(defaultconfig)); } return(defaultconfig); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { try { npcCrewBlock = Entity as IMyUpgradeModule; //MyAPIGateway.Utilities.ShowMessage("DEBUG", "Init Ran"); NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME; npcCrewBlock.CubeGrid.ColorBlocks(npcCrewBlock.SlimBlock.Position, npcCrewBlock.SlimBlock.Position, Color.Red.ColorToHSV()); NPCCrewConfig loadconfig = NPCCrewConfig.LoadConfigFile(); forceColor = loadconfig.forceColor; if (Sink == null) { Sink = new MyResourceSinkComponent(); } ResourceInfo = new MyResourceSinkInfo() { ResourceTypeId = GId, MaxRequiredInput = 0.02f, RequiredInputFunc = () => Power }; Sink.Init(MyStringHash.GetOrCompute("Utility"), ResourceInfo); Sink.AddType(ref ResourceInfo); Entity.Components.Add(Sink); Sink.Update(); } catch (Exception e) { MyVisualScriptLogicProvider.ShowNotificationToAll("Init Error" + e, 10000, "Red"); } }
public void Init() { NPCCrewConfig loadconfig = NPCCrewConfig.LoadConfigFile(); disableAIModeEnabled = loadconfig.disableAIModeEnabled; if (disableAIModeEnabled) { EntityList.Clear(); PlayerList.Clear(); MyAPIGateway.Entities.GetEntities(EntityList); MyAPIGateway.Players.GetPlayers(PlayerList); foreach (var player in PlayerList) { PlayerListLong.Add(player.IdentityId); } MyAPIGateway.Entities.OnEntityAdd += OnEntityAdded; MyAPIGateway.Entities.OnEntityRemove += OnEntityRemoved; //MyAPIGateway.Utilities.ShowMessage("DEBUG", "DisableAI Mode Running"); DisableAIFunction(); } }
public void Initalize() { NPCCrewConfig loadconfig = NPCCrewConfig.LoadConfigFile(); thrustOutputMulitplierControl = loadconfig.thrustOutputMulitplierControl; gyroOutputMulitplierControl = loadconfig.gyroOutputMulitplierControl; powerOutputMulitplierControl = loadconfig.powerOutputMulitplierControl; powerConsumptionDivisionControl = loadconfig.powerConsumptionDivisionControl; gasGeneratorOutputMulitplierControl = loadconfig.gasGeneratorOutputMulitplierControl; drillOutputMulitplierControl = loadconfig.drillOutputMulitplierControl; entityList.Clear(); gridsList.Clear(); npcCombatList.Clear(); npcCombatListWorking.Clear(); npcCombatListNotWorking.Clear(); npcProductionList.Clear(); npcProductionListWorking.Clear(); npcProductionListNotWorking.Clear(); npcEngineerList.Clear(); npcEngineerListWorking.Clear(); npcEngineerListNotWorking.Clear(); MyAPIGateway.Entities.GetEntities(entityList); foreach (var entity in entityList) { if (entity as IMyCubeGrid != null) { gridsList.Add(entity as IMyCubeGrid); } } foreach (var grid in gridsList) { List <IMySlimBlock> gridBlocks = new List <IMySlimBlock>(); gridBlocks.Clear(); grid.GetBlocks(gridBlocks); foreach (var block in gridBlocks) { if (block.BlockDefinition.Id.SubtypeName == combatNpcSubtypeName) { var blockAsRemoteControl = block.FatBlock as IMyRemoteControl; npcCombatList.Add(blockAsRemoteControl); blockAsRemoteControl.IsWorkingChanged += WorkingChanged; blockAsRemoteControl.AppendingCustomInfo += AppendingCustomInfo; combatNpcUpgradeDetails = "\nValues Upgraded\n=============\n Thrust Ouput: " + (thrustOutputMulitplierControl * 100).ToString() + "%\n Gyro Outout: " + (gyroOutputMulitplierControl * 100).ToString() + "%"; blockAsRemoteControl.RefreshCustomInfo(); TriggerTerminalRefresh(blockAsRemoteControl as MyCubeBlock); /* * if (npcCombatList.Count > 0) * { * ProcessCombatMobilityUpgradeList(blockAsRemoteControl.CubeGrid as MyCubeGrid); * } */ } if (block.BlockDefinition.Id.SubtypeName == engineeringNpcSubtypeName) { var engineerNPC = block.FatBlock as IMyUpgradeModule; if (engineerNPC != null) { npcEngineerList.Add(engineerNPC); engineerNPC.IsWorkingChanged += WorkingChanged; engineerNPC.AppendingCustomInfo += AppendingCustomInfo; engineerNpcUpgradeDetails = "\nValues Upgraded\n=============\n Power Ouput: " + (powerOutputMulitplierControl * 100).ToString() + "%\n Power Consumption: " + (100 / powerConsumptionDivisionControl).ToString() + "%"; engineerNPC.RefreshCustomInfo(); TriggerTerminalRefresh(engineerNPC as MyCubeBlock); /* * if (npcEngineerList.Count > 0) * { * ProcessEngineeringUpgradeList(engineerNPC.CubeGrid as MyCubeGrid); * } */ } } if (block.BlockDefinition.Id.SubtypeName == productionNpcSubtypeName) { var productionNPC = block.FatBlock as IMyUpgradeModule; if (productionNPC != null) { npcProductionList.Add(productionNPC); productionNPC.IsWorkingChanged += WorkingChanged; productionNPC.AppendingCustomInfo += AppendingCustomInfo; productionNpcUpgradeDetails = "\nValues Upgraded\n=============\n Gas Ouput: " + (gasGeneratorOutputMulitplierControl * 100).ToString() + "%\n Drill Outout: " + (drillOutputMulitplierControl * 100).ToString() + "%"; productionNPC.RefreshCustomInfo(); TriggerTerminalRefresh(productionNPC as MyCubeBlock); /* * if (npcProductionList.Count == 1) * { * ProcessProductionUpgradeList(productionNPC.CubeGrid as MyCubeGrid); * } */ } } } grid.OnBlockAdded += BlockAddedToGrid; grid.OnBlockRemoved += BlockRemovedFromGrid; //MyVisualScriptLogicProvider.ShowNotificationToAll(npcCombatList.Count.ToString(), 1000, "Red"); } MyAPIGateway.Entities.OnEntityAdd += EntityAdded; MyAPIGateway.Entities.OnEntityRemove += EntityRemoved; //MyAPIGateway.Utilities.ShowMessage("DEBUG", "Init Ran"); }