/// <summary> /// 验证模块 /// </summary> /// <param name=""></param> /// <returns></returns> public Result CheckModule(PowerModule model) { if (string.IsNullOrWhiteSpace(model.Name)) { return(Result.Fail("模块名称不能为空")); } if (model.Id <= 0) { if (_moduleBusiness.Exist(p => p.Pid == model.Pid && p.Name == model.Name && p.Status == NomalStatus.Valid)) { return(Result.Fail("模块名称已存在")); } if (_moduleBusiness.Exist(p => p.Code == model.Code && p.Status == NomalStatus.Valid)) { return(Result.Fail("模块Code已存在")); } } else { if (_moduleBusiness.Exist(p => p.Pid == model.Pid && p.Name == model.Name && p.Status == NomalStatus.Valid && p.Id != model.Id)) { return(Result.Fail("模块名称已存在")); } if (_moduleBusiness.Exist(p => p.Code == model.Code && p.Status == NomalStatus.Valid && p.Id != model.Id)) { return(Result.Fail("模块Code已存在")); } } return(Result.Success()); }
public static Module sample(ModuleType type) { switch (type) { case ModuleType.Core: return(CoreModule.sample()); case ModuleType.Energy: return(EnergyModule.sample()); case ModuleType.Armor: return(ArmorModule.sample()); case ModuleType.Computation: return(ComputationModule.sample()); case ModuleType.Power: return(PowerModule.sample()); case ModuleType.Weapon: return(WeaponModule.sample()); case ModuleType.Repair: return(RepairModule.sample()); case ModuleType.Battery: return(BatteryModule.sample()); default: return(new Module(ModuleType.None, 0, 0, 0)); } }
public BaseWeapon(Handle handle, PowerModule powerModule, Propulsor[] propulsors) { this.fireMode = 0; this.handle = handle; this.powerModule = powerModule; this.propulsors = propulsors; this.isTriggerDown = false; this.CombineProperties(); }
void Awake() { if (_connectViaSelf) { _ownPowerModule = GetComponent <PowerModule>(); if (!_ownPowerModule) { Debug.LogError("Connectors using 'Connect Via Self' requires a PowerModule component!"); } } }
private void Tool_AppendingCustomInfo(IMyTerminalBlock trash, StringBuilder Info) { Info.Clear(); //Info.AppendLine($"Current Input: {Math.Round(Tool.ResourceSink.RequiredInputByType(Electricity), 2)} MW"); Info.AppendLine($"Max Required Input: {Math.Round(PowerModule.PowerConsumptionFunc(true), 2)} MW"); //Info.AppendLine($"Performance impact: {(RunTimesAvailable ? Math.Round(AvgRunTime, 4).ToString() : "--")}/{(RunTimesAvailable ? Math.Round(MaxRunTime, 4).ToString() : "--")} ms (avg/max)"); if (Tool is IMyShipWelder) { Info.AppendLine($"Support inventories: {OnboardInventoryOwners.Count}"); } }
void Main(int ticks = 0) { try { if (ticks == 0) { ticks = SessionCore.WorkSkipTicks; } System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); if (Tool.IsToolWorking()) { watch.Start(); } try { if (IsWelder && LocalPlayerIsOwner && HUDModule.MessageExpired) { MissingHUD.Hide(); } PowerModule.SetPowerUsage(); if (Tool.IsToolWorking() && PowerModule.HasEnoughPower) { Work(ticks); BeamCtlModule.DrawBeam(); } else if (!PowerModule.HasEnoughPower) { DebugNote.Text = $"{Tool.CustomName}: not enough power"; } else { DebugNote.Text = $"{Tool.CustomName}: idle"; //UnbuiltBlocks.Clear(); } Tool.RefreshCustomInfo(); //if (SessionCore.Debug) DebugNote.Text = $"{Tool.CustomName} perf. impact: {(RunTimesAvailable ? Math.Round(AvgRunTime, 5).ToString() : "--")}/{(RunTimesAvailable ? Math.Round(MaxRunTime, 5).ToString() : "--")} ms (avg/max)"; } catch (Exception Scrap) { SessionCore.LogError($"{Tool.CustomName}.Main().Work()", Scrap); } if (Tool.IsToolWorking()) { watch.Stop(); watch.Report(Tool.CustomName, "Main()"); } } catch (Exception Scrap) { SessionCore.LogError($"{Tool.CustomName}.Main()", Scrap); } }
public void Disconnect(PowerModule inLostConnection) { if (!_connectedModules.Contains(inLostConnection)) { return; } _connectedModules.Remove(inLostConnection); inLostConnection.Disconnect(this); UpdateConnection(); }
public void Connect(PowerModule inNewConnection) { if (_connectedModules.Contains(inNewConnection)) { return; } _connectedModules.Add(inNewConnection); inNewConnection.Connect(this); UpdateConnection(); }
public static float CalculateTotalPowerGenerationSpeed() { GameObject[] modules = GameObject.FindGameObjectsWithTag("Module"); float power = 0f; foreach (GameObject m in modules) { PowerModule pm = m.GetComponent <PowerModule>(); if (pm) { power += pm.powerGenerationSpeed; } } return(power + 5f); }
void OnTriggerExit(Collider inCollider) { PowerModule inPowerModule = inCollider.GetComponent <PowerModule>(); if (inPowerModule) { foreach (PowerModule powerModule in _connectedModules) { if (_connectViaSelf) { powerModule.Disconnect(_ownPowerModule); } else { powerModule.Disconnect(inPowerModule); } } } }
public override void UpdateBeforeSimulation100() { PowerModule.UpdateAvailablePower(); }
public Result AddOrEditModule(PowerModule model) { var result = CheckModule(model); if (!result.Succeed) { return(result); } model.Status = NomalStatus.Valid; try { using (TransactionScope ts = new TransactionScope()) { //新增 if (model.Id <= 0) { model.Level = 1; model.LevelMap = "0"; _moduleBusiness.Add(model); } if (model.Pid <= 0) { model.LevelMap = ",0," + model.Id + ","; model.Level = 1; } else { var modelParent = _moduleBusiness.GetSingle(p => p.Id == model.Pid && p.Status == NomalStatus.Valid); if (modelParent == null) { return(Result.Fail("未查询到父级模块")); } model.LevelMap = modelParent.LevelMap + model.Id + ","; model.Level = modelParent.Level + 1; //删除父节点 模块元素中的 显示 _elementBusiness.Delete(p => p.ModuleId == modelParent.Id); } var showElemCount = _elementBusiness.Count(p => p.ModuleId == model.Id && p.DomId == "btnShow"); if (showElemCount <= 0 && model.Pid > 0) { var modelElement = new PowerElement() { Id = 0, ModuleId = model.Id, Name = "显示", DomId = "btnShow", Status = NomalStatus.Valid, IsSystem = IsSystem.Yes, Position = PowerElementPosition.Up, DisplayOrder = -9999 }; _elementBusiness.Add(modelElement); } _moduleBusiness.Update(model); ts.Complete(); return(Result.Success()); } } catch (Exception ex) { return(Result.Fail("操作失败:" + ex.Message)); } }
public ActionResult SetPower(string param) { try { string path = AppDomain.CurrentDomain.BaseDirectory; string dir = Path.Combine(path, "bin"); string filePath = dir + Path.DirectorySeparatorChar + param; byte[] filedata = System.IO.File.ReadAllBytes(filePath); Assembly assembly = Assembly.Load(filedata); Type[] t_arr = assembly.GetExportedTypes(); Type _typePower = typeof(PowerAttribute); Type _typeGroup = typeof(GroupAttribute); string _p = _typePower.FullName; string _g = _typeGroup.FullName; string areStr = "/Admin"; // PowerAdmin _powerConf = new PowerAdmin(); if (_powerConf.list == null) { _powerConf.list = new List <PowerGroup>(); } foreach (Type t in t_arr)//针对每个类型获取详细信息 { string className = t.Name; if (className.EndsWith("Controller"))//是否控制器 { //获取class的Attribute object[] att_class = t.GetCustomAttributes(false); PowerGroup _group = null; //string _controller = className.Replace("Controller", ""); string _controller = className.Remove(className.IndexOf("Controller"), ("Controller").Length); foreach (object obj in att_class) { Type _t = obj.GetType(); string t_name = _t.ToString(); if (t_name == _g) { _group = new PowerGroup(); _group.Name = _controller; PropertyInfo p_Title = _t.GetProperty("Title"); object _ss = p_Title.GetValue(obj, null); if (_ss != null) { _group.Title = _ss.ToString(); } PropertyInfo p_Des = _t.GetProperty("Des"); object _dd = p_Des.GetValue(obj, null); if (_dd != null) { _group.Des = _dd.ToString(); } PropertyInfo p_IsShow = _t.GetProperty("IsShow"); object _cc = p_IsShow.GetValue(obj, null); if (_cc != null) { _group.IsShow = Convert.ToBoolean(_cc.ToString()); } PropertyInfo p_Icon = _t.GetProperty("Icon"); object _oo = p_Icon.GetValue(obj, null); if (_oo != null) { _group.Icon = _oo.ToString(); } break; } } if (_group != null && _group.module == null) { _group.module = new List <PowerModule>(); List <PowerModule> modules = new List <PowerModule>(); //获取方法信息 MethodInfo[] MethodInfo_arr = t.GetMethods(); foreach (MethodInfo m in MethodInfo_arr) { string methodName = m.Name; object[] att_obj = m.GetCustomAttributes(false); foreach (object obj in att_obj) { Type _t = obj.GetType(); string t_name = _t.ToString(); if (t_name == _p) { PowerModule _power = new PowerModule(); PropertyInfo p_Name = _t.GetProperty("ModuleName"); object _pp = p_Name.GetValue(obj, null); if (_pp != null) { _power.Name = _pp.ToString(); } PropertyInfo p_actionEnum = _t.GetProperty("actionEnum"); object _aa = p_actionEnum.GetValue(obj, null); if (_aa != null) { _power.Action_Type = _aa.ToString(); } PropertyInfo p_IsShow = _t.GetProperty("IsShow"); object _cc = p_IsShow.GetValue(obj, null); if (_cc != null) { _power.IsShow = Convert.ToBoolean(_cc.ToString()); } PropertyInfo p_Title = _t.GetProperty("Title"); object _ss = p_Title.GetValue(obj, null); if (_ss != null) { _power.Title = _ss.ToString(); } PropertyInfo p_Icon = _t.GetProperty("Icon"); object _oo = p_Icon.GetValue(obj, null); if (_oo != null) { _power.Icon = _oo.ToString(); } _power.ParamStr = areStr + "/" + _controller + "/" + methodName; modules.Add(_power); } } } //去重后的模块 Dictionary <string, PowerModule> module_dic_temp = new Dictionary <string, PowerModule>(); //去重后的模块Action Dictionary <string, Dictionary <string, string> > moduleaction_dic = new Dictionary <string, Dictionary <string, string> >(); //过滤重复模块名 foreach (var module in modules) { if (module.IsShow) { if (!module_dic_temp.ContainsKey(module.Name)) { module_dic_temp.Add(module.Name, module); } else { module_dic_temp[module.Name] = module; } } else { if (!module_dic_temp.ContainsKey(module.Name)) { module_dic_temp.Add(module.Name, module); } } if (!moduleaction_dic.ContainsKey(module.Name)) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add(module.Action_Type, module.Action_Type); moduleaction_dic.Add(module.Name, dic); } else { Dictionary <string, string> dic = moduleaction_dic[module.Name]; if (!dic.ContainsKey(module.Action_Type)) { dic.Add(module.Action_Type, module.Action_Type); } moduleaction_dic[module.Name] = dic; } } Dictionary <string, PowerModule> module_dic = new Dictionary <string, PowerModule>(); //合并操作标示 foreach (var dic in module_dic_temp) { if (moduleaction_dic.ContainsKey(dic.Key)) { string Action_Type = ""; foreach (var m_dic in moduleaction_dic[dic.Key]) { if (string.IsNullOrEmpty(Action_Type)) { Action_Type += m_dic.Value; } else { Action_Type += "," + m_dic.Value; } } dic.Value.Action_Type = Action_Type; module_dic.Add(dic.Key, dic.Value); } } // _group.module = module_dic.Values.ToList(); _powerConf.list.Add(_group); } } } SerializeHelper.Serialize(_powerConf, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configuration", "PowerConfig.config")); if (Constant.CacheKey.List[Cactus.Model.Sys.Enums.Constant.CacheKey.PowerConfigCacheKey].Count() > 0) { base.cacheService.Remove(Cactus.Model.Sys.Enums.Constant.CacheKey.PowerConfigCacheKey); } return(Json(new ResultModel { pass = true, msg = "初始化成功", append = _powerConf }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new ResultModel { pass = false, msg = e.Message })); } }
public void AddWeaponPart(PowerModule powerModule) { this.powerModules.Add(powerModule); }
public OneHandedWeapon(Handle handle, PowerModule powerModule, Propulsor[] propulsors) : base(handle, powerModule, propulsors) { }
public Result EditModule([FromForm] PowerModule model) { return(_wrappers.AddOrEditModule(model)); }
public void Init(PowerModule module) { PowerModule = module; }