private void OnTriggerStay(Collider other) { float qtty = 0f; if (other.gameObject.CompareTag("resource")) { gatherTarget = other.gameObject; currentMode = AgentMode.gathering; Resource res = gatherTarget.GetComponent <Resource>(); if (res != null) { qtty = res.Gather(gatheringRate); //myAcademy.totalWood += qtty; myArea.totalWood += qtty; wood += qtty; if (qtty > 0f) { // Reward the villager for gathering a resource AddReward(currentGatherReward); // Incentivize the villager to not interrupt the gathering process currentGatherReward += 0.01f; #if (UNITY_EDITOR) Debug.Log("Current Gather Reward: " + currentGatherReward.ToString()); #endif } else { currentMode = AgentMode.exploring; } } } }
/// <summary> /// 创建一个每天执行的代理作业 /// </summary> /// <param name="command">命令 包括文件名和参数</param> /// <param name="mode">代理作业模式</param> /// <param name="hour">开始执行时间 时</param> /// <param name="minute">开始执行时间 分</param> /// <param name="second">开始执行时间 秒</param> /// <exception cref="ArgumentOutOfRangeException">hour 或 minute 或 second 超出范围</exception> public Agent(string command, AgentMode mode, int hour, int minute, int second) { if (hour < 0 || hour > 23) { throw new ArgumentOutOfRangeException("hour"); } if (minute < 0 || minute > 59) { throw new ArgumentOutOfRangeException("minute"); } if (second < 0 || second > 59) { throw new ArgumentOutOfRangeException("second"); } DateTime now = DateTime.Now; DateTime startTime = new DateTime(now.Year, now.Month, now.Day, hour, minute, second); if (startTime < now) { startTime = startTime.AddDays(1); } this.Init(command, mode, TimeSpan.FromDays(1), startTime); }
/// <summary> /// initialisiert Kampagnenanmeldung /// </summary> public CampaignSession(string campaignCode, AgentMode agentMode, int agentPriority) { // Parameter initialisieren _campaignCode = campaignCode; _agentMode = agentMode; _agentPriority = agentPriority; }
private void Init(string command, AgentMode mode, TimeSpan interval, DateTime startTime) { if (command.IsNull()) { throw new ArgumentNullException("command", "command 不能为 null"); } this.Mode = mode; this.Interval = interval; this.StartTime = startTime; this.Last = DateTime.MaxValue; this.HasShutDown = false; ValueSet <int, int> result = command.IndexOfWhiteSpace(); this.Process = new Process(); if (result.IsNull()) { this.Process.StartInfo.FileName = command; } else { this.Process.StartInfo.FileName = command.Substring(0, result.Value1); this.Process.StartInfo.Arguments = command.Substring(result.Value1 + result.Value2); } }
public override void OnRequestAgentModeChange(ref Agent agent, AgentMode agentMode) { try { agent.AgentReqMode = agentMode; } catch (Exception exception) { Logger.Instance.LogMessage(Logger.LogAppender.DuoLogger2, "AgentAcw", exception, Logger.LogLevel.Error); } }
private void OnTriggerExit(Collider other) { currentMode = AgentMode.exploring; currentGatherReward = startGatherReward; #if (UNITY_EDITOR) Debug.Log("Exited trigger area."); #endif }
/// <summary> /// /// </summary> /// <param name="agent"></param> /// <param name="agentMode"></param> public override void OnRequestModeChange(Agent agent, AgentMode agentMode) { try { if (agent != null) { agent.AgentReqMode = agentMode; } } catch (Exception exception) { Logger.Instance.LogMessage(Logger.LogAppender.DuoLogger2, "AgentBusy", exception, Logger.LogLevel.Error); } }
private void Update() { if ((currentMode == AgentMode.gathering) && (gatherTarget == null)) { currentMode = AgentMode.exploring; currentGatherReward = startGatherReward; Debug.Log("Resource we were gathering was destroyed."); } }
private unsafe static IntPtr GetEnemySpawnDataPatch(IntPtr thisPtr, Vector3 *position, IntPtr courseNode, EnemyGroupType groupType, eEnemyGroupSpawnType spawnType, uint persistentGameDataID, float populationScore, IntPtr targetReplicator, IntPtr survivalWave, uint debugEnemyID, AgentMode debugEnemyMode) { var result = ourGetEnemySpawnData(thisPtr, position, courseNode, groupType, spawnType, persistentGameDataID, populationScore * SpawnTweakSettings.spawnPopMult, targetReplicator, survivalWave, debugEnemyID, debugEnemyMode); return(result); }
public override void InitializeAgent() { base.InitializeAgent(); currentMode = AgentMode.exploring; currentGatherReward = startGatherReward; agentRB = GetComponent <Rigidbody>(); rayPer = GetComponent <RayPerception>(); //myAcademy = myAcademyObj.GetComponent<CivAcademy>(); myArea = GetComponentInParent <LandSpawnArea>(); }
public override void AgentReset() { wood = 0; currentMode = AgentMode.exploring; currentGatherReward = startGatherReward; agentRB.velocity = Vector3.zero; // Agent position reset was managed by the Academy, now moved to LandSpawnArea //myAcademy.RespawnAgent(gameObject); myArea.RespawnNPC(gameObject); }
internal void Start() { if (PulseData.PatternData == null) { enabled = false; return; } _PatternLength = PulseData.PatternData.Length; if (_PatternLength <= 1) { enabled = false; return; } _Agent = GetComponentInParent <EnemyAgent>(); _DefaultColor = _Agent.MaterialHandler.m_defaultGlowColor; _TargetAgentMode = PulseData.Target switch { PulseEffectTarget.Hibernate => AgentMode.Hibernate, PulseEffectTarget.Combat => AgentMode.Agressive, PulseEffectTarget.Scout => AgentMode.Scout, PulseEffectTarget.None => AgentMode.Off, _ => AgentMode.Hibernate }; if (_TargetAgentMode == AgentMode.Off) { enabled = false; return; } var interval = Math.Max(0.0f, PulseData.Duration); _UpdateTimerDelay = interval / _PatternLength; _Timer = Clock.Time + StartDelay; }
/// <summary> /// 创建一个每天执行的代理作业 /// </summary> /// <param name="command">命令 包括文件名和参数</param> /// <param name="mode">代理作业模式</param> /// <param name="hour">开始执行时间 时</param> /// <exception cref="ArgumentOutOfRangeException">hour 超出范围</exception> public Agent(string command, AgentMode mode, int hour) : this(command, mode, hour, 0, 0) { // }
private void OnTriggerExit(Collider other) { currentMode = AgentMode.exploring; currentGatherReward = startGatherReward; Debug.Log("Exited trigger area."); }
public override void OnRequestAgentBreak(ref Agent agent, AgentMode agentMode, string callSessionId) { var result = ArdsHandler.SendStatusChangeRequestBreak(agent.UserAuth, callSessionId); agent.BreakRequsetHandle(result); }
/// <summary> /// aktualisiert Kampagnenanmeldungen /// </summary> private void RefreshCampaignSessions( itCampus.bb.Monitor.CampaignSessionList campaignSessions) { // Kampagnenanmeldungen abgleichen for (int i = 0; i < campaignSessions.Count; i++) { // Parameter für aktuelle Kampagnenanmeldung ermitteln string campaignCode = campaignSessions[i].CampaignCode; AgentMode agentMode = campaignSessions[i].AgentMode; int agentPriority = campaignSessions[i].AgentPriority; // Kampagnenanmeldung an aktueller Position ermitteln CampaignSession campaignSession = GetCampaignSession(i); // solange Kampagnenanmeldung an aktueller Position vorhanden und veraltet while ((campaignSession != null) && ((campaignSession.CampaignCode != campaignCode) || (campaignSession.AgentMode != agentMode) || (campaignSession.AgentPriority != agentPriority))) { // wenn Kampagne zugeordnet, freigeben if (campaignSession.Campaign != null) { UnassignCampaign(campaignSession.Campaign); } // Kampagnenanmeldung entfernen _campaignSessions.RemoveCampaignSession(campaignSession); // nächste Kampagnenanmeldung ermitteln campaignSession = GetCampaignSession(i); } // wenn keine Kampagnenanmeldung mit übereinstimmenden Parametern gefunden if (campaignSession == null) { // neue Kampagnenanmeldung initialisieren campaignSession = new CampaignSession(campaignCode, agentMode, agentPriority); // Kampagnenanmeldung zu Liste hinzufügen _campaignSessions.AddCampaignSession(campaignSession); // Kampagne suchen Campaign campaign = _frontendControl.MainControl.CampaignControl.GetCampaign( campaignCode); // wenn Kampagne gefunden, zuordnen if (campaign != null) { AssignCampaign(campaign); } } } // alle übrigen Kampagnenanmeldungen entfernen while (_campaignSessions.Count > campaignSessions.Count) { // nächste Kampagnenanmeldung ermitteln CampaignSession campaignSession = GetCampaignSession(campaignSessions.Count); // wenn Kampagne zugeordnet, freigeben if (campaignSession.Campaign != null) { UnassignCampaign(campaignSession.Campaign); } // Kampagnenanmeldung entfernen _campaignSessions.RemoveCampaignSession(campaignSession); } }
public async Async.Task <VMExtensionWrapper> AgentConfig(AzureLocation region, Os vmOs, AgentMode mode, List <Uri>?urls = null, bool withSas = false) { await UpdateManagedScripts(); var urlsUpdated = urls ?? new(); if (vmOs == Os.Windows) { var vmScripts = await ConfigUrl(new Container("vm-scripts"), "managed.ps1", withSas) ?? throw new Exception("failed to get VmScripts config url"); var toolsAzCopy = await ConfigUrl(new Container("tools"), "win64/azcopy.exe", withSas) ?? throw new Exception("failed to get toolsAzCopy config url"); var toolsSetup = await ConfigUrl(new Container("tools"), "win64/setup.ps1", withSas) ?? throw new Exception("failed to get toolsSetup config url"); var toolsOneFuzz = await ConfigUrl(new Container("tools"), "win64/onefuzz.ps1", withSas) ?? throw new Exception("failed to get toolsOneFuzz config url"); urlsUpdated.Add(vmScripts); urlsUpdated.Add(toolsAzCopy); urlsUpdated.Add(toolsSetup); urlsUpdated.Add(toolsOneFuzz); var toExecuteCmd = $"powershell -ExecutionPolicy Unrestricted -File win64/setup.ps1 -mode {mode.ToString().ToLowerInvariant()}"; var extension = new VMExtensionWrapper { Name = "CustomScriptExtension", TypePropertiesType = "CustomScriptExtension", Publisher = "Microsoft.Compute", Location = region, ForceUpdateTag = Guid.NewGuid().ToString(), TypeHandlerVersion = "1.9", AutoUpgradeMinorVersion = true, Settings = new BinaryData(JsonSerializer.Serialize(new { commandToExecute = toExecuteCmd, fileUris = urlsUpdated }, _extensionSerializerOptions)), ProtectedSettings = new BinaryData(JsonSerializer.Serialize(new { managedIdentity = new Dictionary <string, string>() }, _extensionSerializerOptions)) }; return(extension); } else if (vmOs == Os.Linux) { var vmScripts = await ConfigUrl(new Container("vm-scripts"), "managed.sh", withSas) ?? throw new Exception("failed to get VmScripts config url"); var toolsAzCopy = await ConfigUrl(new Container("tools"), "linux/azcopy", withSas) ?? throw new Exception("failed to get toolsAzCopy config url"); var toolsSetup = await ConfigUrl(new Container("tools"), "linux/setup.sh", withSas) ?? throw new Exception("failed to get toolsSetup config url"); urlsUpdated.Add(vmScripts); urlsUpdated.Add(toolsAzCopy); urlsUpdated.Add(toolsSetup); var toExecuteCmd = $"sh setup.sh {mode.ToString().ToLowerInvariant()}"; var extensionSettings = JsonSerializer.Serialize(new { CommandToExecute = toExecuteCmd, FileUris = urlsUpdated }, _extensionSerializerOptions); var protectedExtensionSettings = JsonSerializer.Serialize(new { ManagedIdentity = new Dictionary <string, string>() }, _extensionSerializerOptions); var extension = new VMExtensionWrapper { Name = "CustomScript", Publisher = "Microsoft.Azure.Extensions", TypePropertiesType = "CustomScript", TypeHandlerVersion = "2.1", Location = region, ForceUpdateTag = Guid.NewGuid().ToString(), AutoUpgradeMinorVersion = true, Settings = new BinaryData(extensionSettings), ProtectedSettings = new BinaryData(protectedExtensionSettings) }; return(extension); } throw new NotSupportedException($"unsupported OS: {vmOs}"); }
public override void OnRequestAgentModeChange(ref Agent agent, AgentMode agentMode) { try { throw new NotImplementedException("Invalid Agent Status."); } catch (Exception exception) { Logger.Instance.LogMessage(Logger.LogAppender.DuoLogger2, "AgentInitiate", exception, Logger.LogLevel.Error); } }
/// <summary> /// 获取客户端代理类的代码 /// </summary> /// <param name="p_clsName">类名</param> /// <returns></returns> public string GetAgentClass(string p_clsName) { List <string> keys = new List <string>(); IEnumerable <XElement> comments = null; AgentMode mode = AgentMode.Default; foreach (var item in Silo.Methods) { if (!item.Key.StartsWith(p_clsName + ".")) { continue; } keys.Add(item.Key); if (comments == null) { Type type = item.Value.Method.DeclaringType; var attr = type.GetCustomAttribute <ApiAttribute>(); if (attr != null) { mode = attr.AgentMode; } comments = LoadComments(type); } } if (keys.Count == 0) { return("未找到该类型!"); } // 不同模式的服务名 string serviceName; if (mode == AgentMode.Default) { serviceName = $"\"{Kit.SvcName}\""; } else if (mode == AgentMode.Generic) { serviceName = "typeof(TSvc).Name"; } else { serviceName = "p_serviceName"; } string retTypeName; int paramsLength; StringBuilder sb = new StringBuilder(); sb.Append("#region "); sb.Append(p_clsName); foreach (string key in keys) { ApiMethod sm = Silo.GetMethod(key); MethodInfo mi = sm.Method; // 添加注释 sb.AppendLine(); if (comments != null) { AppendComment(sm, sb, comments); } // 自定义Agent方法代码 var attr = mi.GetCustomAttribute <CustomAgentAttribute>(false); if (attr != null) { if (!string.IsNullOrEmpty(attr.Code)) { sb.Append(attr.Code.Replace("###", serviceName)); } continue; } // 方法定义 if (sm.CallMode == ApiCallMode.Unary) { retTypeName = GetRpcTypeName(mi.ReturnType); if (!string.IsNullOrEmpty(retTypeName)) { sb.AppendFormat("public static Task<{0}> {1}(", retTypeName, mi.Name); } else { sb.AppendFormat("public static Task {0}(", mi.Name); } } else { if (sm.CallMode == ApiCallMode.ServerStream) { retTypeName = "ResponseReader"; } else if (sm.CallMode == ApiCallMode.ClientStream) { retTypeName = "RequestWriter"; } else { retTypeName = "DuplexStream"; } sb.AppendFormat("public static Task<{0}> {1}(", retTypeName, mi.Name); } // 参数 ParameterInfo[] infos = mi.GetParameters(); if (infos.Length > 0) { // 最后的RequestReader, ResponseWriter不算数 if (sm.CallMode == ApiCallMode.Unary) { paramsLength = infos.Length; } else if (sm.CallMode == ApiCallMode.DuplexStream) { paramsLength = infos.Length - 2; } else { paramsLength = infos.Length - 1; } } else { paramsLength = 0; } // 自定义服务名模式 if (mode == AgentMode.Custom) { sb.Append("string p_serviceName"); if (paramsLength > 0) { sb.Append(", "); } } if (paramsLength > 0) { for (int i = 0; i < paramsLength; i++) { var item = infos[i]; // 实体类型,降型Row if (item.ParameterType.IsSubclassOf(typeof(Entity))) { sb.Append("Row "); sb.Append(item.Name); continue; } // Table<> -> Table if (item.ParameterType.IsGenericType && item.ParameterType.GetGenericTypeDefinition() == typeof(Table <>)) { sb.Append("Table "); sb.Append(item.Name); continue; } // 最后的List<object>转为params object[],方便客户端 if (i == paramsLength - 1 && item.ParameterType == typeof(List <object>)) { sb.Append("params object[] "); sb.Append(item.Name); continue; } sb.AppendFormat("{0} {1}", GetRpcTypeName(item.ParameterType), item.Name); if (!DBNull.Value.Equals(item.DefaultValue)) { if (item.DefaultValue == null) { if (item.ParameterType == typeof(List <object>)) { sb.Append(" = null"); } else { sb.Append(" = null"); } } else if (item.ParameterType == typeof(bool)) { sb.AppendFormat(" = {0}", item.DefaultValue.ToString().ToLower()); } else { sb.AppendFormat(" = {0}", item.DefaultValue); } } if (i < paramsLength - 1) { sb.Append(", "); } } } sb.AppendLine(")"); // 方法体 sb.AppendLine("{"); AppendTabSpace(sb, 1); if (sm.CallMode == ApiCallMode.Unary) { sb.AppendLine("return new UnaryRpc("); } else if (sm.CallMode == ApiCallMode.ServerStream) { sb.AppendLine("return new ServerStreamRpc("); } else if (sm.CallMode == ApiCallMode.ClientStream) { sb.AppendLine("return new ClientStreamRpc("); } else { sb.AppendLine("return new DuplexStreamRpc("); } // 服务名 AppendTabSpace(sb, 2); sb.Append(serviceName); sb.AppendLine(","); // 完整方法名 AppendTabSpace(sb, 2); sb.AppendFormat("\"{0}.{1}\"", p_clsName, mi.Name); if (paramsLength > 0) { for (int i = 0; i < paramsLength; i++) { var item = infos[i]; sb.AppendLine(","); AppendTabSpace(sb, 2); // params object[]转为List<object> if (i == paramsLength - 1 && item.ParameterType == typeof(List <object>)) { sb.AppendFormat("({0} == null || {0}.Length == 0) ? null : {0}.ToList()", item.Name); } else { sb.Append(item.Name); } } } sb.AppendLine(); // Rpc方法 AppendTabSpace(sb, 1); if (sm.CallMode == ApiCallMode.Unary) { if (!string.IsNullOrEmpty(retTypeName)) { sb.Append(").Call<"); sb.Append(retTypeName); sb.AppendLine(">();"); } else { sb.AppendLine(").Call<object>();"); } } else { sb.AppendLine(").Call();"); } sb.AppendLine("}"); } sb.Append("#endregion"); return(sb.ToString()); }
/// <summary> /// aktualisiert Parameter /// </summary> public void RefreshParameters(itCampus.bb.Monitor.Frontend frontend) { // Parameter aktualisieren _remoteAddress = frontend.RemoteAddress; _lastState = _state; _state = frontend.State; _lastStateChange = frontend.LastStateChange; _agentCode = frontend.AgentCode; _deviceCode = frontend.DeviceCode; _campaignCode = frontend.CampaignCode; _agentMode = frontend.AgentMode; _coachingPermission = frontend.CoachingPermission; _monitorCode = frontend.MonitorCode; _coachingMode = frontend.CoachingMode; foreach (AgentState agentState in Enum.GetValues(typeof(AgentState))) { _agentStateTimeAvgTtl[(int)agentState] = frontend.GetAgentStateTimeAvgTtl(agentState); } foreach (AgentState agentState in Enum.GetValues(typeof(AgentState))) { _agentStateTimeTtl[(int)agentState] = frontend.GetAgentStateTimeTtl(agentState); } // wenn Device zugeordnet if (_device != null) { // wenn Devicecode übereinstimmt if (_device.Code == _deviceCode) { // Device aktualisieren _device.RefreshFrontend(); } else { // sonst Device freigeben _device.UnassignFrontend(); _device = null; } } // wenn kein Device zugeordnet if (_device == null) { // wenn Devicecode angegeben if (_deviceCode != "") { // Deviceverwaltung referenzieren DeviceControl deviceControl = _frontendControl.MainControl.DeviceControl; // Device suchen _device = deviceControl[_deviceCode]; // wenn Device nicht gefunden, erzeugen if (_device == null) { _device = new Device(_deviceCode, deviceControl); } // Device zuordnen _device.AssignFrontend(this); } } // wenn Kampagne zugeordnet if (_campaign != null) { // wenn Kampagnencode nicht übereinstimmt, Kampagne freigeben if (_campaign.Code != _campaignCode) { UnassignCampaign(); } } // wenn keine Kampagne zugeordnet if (_campaign == null) { // wenn Kampagnencode angegeben if (_campaignCode != "") { // Kampagnenverwaltung referenzieren CampaignControl campaignControl = _frontendControl.MainControl.CampaignControl; // Kampagne suchen Campaign campaign = campaignControl.GetCampaign(_campaignCode); // wenn Kampagne gefunden, zuordnen if (campaign != null) { AssignCampaign(campaign); } } } // Frontendverwaltung aktualisieren _frontendControl.RefreshFrontend(this); }
/// <summary> /// gibt Agentenanzahl für angegebenen Modus zurück /// </summary> public int GetAgentModeCount(AgentMode agentMode) { return(_agentModeCount[(int)agentMode]); }
/// <summary> /// /// </summary> /// <param name="agent"></param> /// <param name="agentMode"></param> public abstract void OnRequestModeChange(Agent agent, AgentMode agentMode);
/// <summary> /// 创建一个启动即执行的代理作业 /// </summary> /// <param name="command">命令 包括文件名和参数</param> /// <param name="mode">代理作业模式</param> /// <param name="interval">执行间隔</param> public Agent(string command, AgentMode mode, TimeSpan interval) : this(command, mode, interval, DateTime.Now) { // }
/// <summary> /// /// </summary> /// <param name="agent"></param> /// <param name="agentMode"></param> public override void OnRequestModeChange(Agent agent, AgentMode agentMode) { //try { throw new NotImplementedException("Invalid Agent Status."); } //catch (Exception exception) { Logger.Instance.LogMessage(Logger.LogAppender.DuoLogger2, "AgentOffline", exception, Logger.LogLevel.Error); } Logger.Instance.LogMessage(Logger.LogAppender.DuoLogger2, "AgentOffline", new NotImplementedException("Invalid Agent Status."), Logger.LogLevel.Error); }
public abstract void OnRequestAgentBreak(ref Agent agent, AgentMode agentMode, string callSessionId);
/// <summary> /// 初始化 /// </summary> /// <param name="command">命令 包括文件名和参数</param> /// <param name="mode">代理作业模式</param> /// <param name="interval">执行间隔</param> /// <param name="startTime">开始时间</param> public Agent(string command, AgentMode mode, TimeSpan interval, DateTime startTime) { this.Init(command, mode, interval, startTime); }
/// <summary> /// 创建一个每天执行的代理作业 /// </summary> /// <param name="command">命令 包括文件名和参数</param> /// <param name="mode">代理作业模式</param> /// <param name="hour">开始执行时间 时</param> /// <param name="minute">开始执行时间 分</param> /// <exception cref="ArgumentOutOfRangeException">hour 或 minute 超出范围</exception> public Agent(string command, AgentMode mode, int hour, int minute) : this(command, mode, hour, minute, 0) { // }
public override void OnRequestAgentModeChange(ref Agent agent, AgentMode agentMode) { try { throw new NotImplementedException("Invalid Agent Status."); } catch (Exception exception) { Logger.Instance.LogMessage(Logger.LoggerFiles.DuoDefault, "", exception, Logger.LogLevel.Error); } }
public Agent() { AgentCurrentMode = new AgentMode(); AgentPreviousMode = new AgentMode(); _agentCurrentState = new AgentInitiate(); }