public virtual void AIReset() { if (!stats) { stats = GetComponent <StatScript>(); } stats?.AIReset(); if (!rb) { rb = GetComponent <Rigidbody>(); } if (rb) { rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; } Vector3 pos = new Vector3( Random.Range(xRange.x, xRange.y), 0, Random.Range(yRange.x, yRange.y)); transform.localPosition = pos; transform.localRotation = Quaternion.Euler(0f, Random.Range(-180f, 180f), 0); state = StateEnum.Idle; ResetTarget(); }
public static string ConvertPathFileandWeb(StatScript statScript, string path) { string sConvertedPath = string.Empty; if (!string.IsNullOrEmpty(path)) { if (Path.IsPathRooted(path)) { sConvertedPath = path.Replace( statScript.DefaultRootFullFilePath, statScript.DefaultRootWebStoragePath); sConvertedPath = sConvertedPath.Replace( FILE_PATH_DELIMITER, WEBFILE_PATH_DELIMITER); } else { sConvertedPath = path.Replace( statScript.DefaultRootWebStoragePath, statScript.DefaultRootFullFilePath); sConvertedPath = sConvertedPath.Replace( WEBFILE_PATH_DELIMITER, FILE_PATH_DELIMITER); } } return(sConvertedPath); }
// Use this for initialization void Start() { display = GetComponent<Text>(); world = GameObject.Find("World"); stats = world.GetComponent<StatScript>(); }
// Use this for initialization void Awake() { Sstat = GetComponent <StatScript> (); player1_nma = GetComponent <NavMeshAgent> (); player1_anim = GetComponent <Animator> (); guiImage = GameObject.FindGameObjectWithTag("Gui").GetComponent <Image> (); }
//used for tests public static async Task <StatScript> ClientGetById(StatScript statScript) { StatScript deserializedScript = new StatScript(); HttpClient client = new HttpClient(); var json = JsonConvert.SerializeObject(statScript); Uri address = new Uri(string.Concat(statScript.DefaultWebDomain, "api/statscript", FileStorageIO.WEBFILE_PATH_DELIMITER, statScript.Key)); HttpResponseMessage response = await client.GetAsync(address); // Check that response was successful or throw exception response.EnsureSuccessStatusCode(); //the response body contains the json string result string statResult = JsonConvert.SerializeObject(response); if (!string.IsNullOrEmpty(statResult)) { string body = await response.Content.ReadAsStringAsync(); deserializedScript = JsonConvert.DeserializeObject <StatScript>(body); } return(deserializedScript); }
// Use this for initialization void Start() { PlayerStat = GameObject.FindGameObjectWithTag("Player").GetComponent <StatScript> (); Image[] tmp = GetComponentsInChildren <Image>(); rtLife = tmp [1].GetComponent <RectTransform> (); bkpHP = 0; }
private static string GetURLFromFilePath(StatScript statScript, string filePath) { string sTempURL = string.Empty; //standard convention in devtreks sTempURL = ConvertPathFileandWeb(statScript, filePath); return(sTempURL); }
public void Bite(GameObject enemy) { if (stats.AIEnabled) { StatScript eHS = enemy.GetComponent <StatScript>(); eHS.DamageHealth(damage); } }
public void SetCombatHUD(StatScript stats) { nameText.text = stats.entityName; hpSlider.maxValue = stats.hpMax; hpSlider.value = stats.hpCurrent; mpSlider.maxValue = stats.mpMax; mpSlider.maxValue = stats.mpCurrent; }
public void DisableGui() { guiTarget = null; myGui.color = new Color(255, 255, 255, 0); childGui.SetActive(false); isActive = false; isLock = false; TargetScript = null; }
// Start is called before the first frame update protected virtual void Start() { rb = gameObject.GetComponent <Rigidbody>(); stats = GetComponent <StatScript>(); stats.SubscribeToOnDeath(OnDeath); stats.SubscribeToOnResurrect(OnResurrect); stats.SubscribeToOnEnrage(OnEnrage); state = StateEnum.Idle; noiseSource = GetComponent <AudioSource>(); }
// Use this for initialization void Start() { Sstat = GetComponent <StatScript> (); current_nma = GetComponent <NavMeshAgent> (); current_col = GetComponent <CapsuleCollider> (); current_anim = GetComponent <Animator> (); current_rb = GetComponent <Rigidbody> (); Sspawner = gSpawner.GetComponent <EnemySpawners> (); player = GameObject.FindGameObjectWithTag("Player"); PlayerStat = player.GetComponent <StatScript> (); DetectZone = 10; }
public static async Task <bool> SaveContentInFile(StatScript statScript, string dataFilePath, string content) { bool bHasSaved = false; //datafilepath must always be a filesystem csv file, but output can be just text string sFilePath = dataFilePath.Replace(".csv", "out.txt"); bHasSaved = await SaveStringInFilePath(statScript, sFilePath, content); //convert the filepath to a url for auditing and retrieval statScript.OutputURL = GetURLFromFilePath(statScript, sFilePath); return(bHasSaved); }
public static async Task <StatScript> DeleteTest(IStatScriptRepository StatScriptRep, StatScript statScript) { StatScript testStat = new StatScript(statScript); if (!statScript.IsDevelopment) { return(testStat); } Uri uri = await ClientProgram.ClientDelete(testStat); return(testStat); }
public static async Task <string> SaveURLInTempFile(StatScript statScript, string url) { //statistical packages run using console process must be in filesystem //r can't handle urls to script files //async url to filesystem conversion string sURLContent = await ReadTextAsync(url); string sTempFilePath = GetTempFilePath(statScript, url); bool bIsSaved = await SaveStringInFilePath(statScript, sTempFilePath, sURLContent); return(sTempFilePath); }
public static async Task <StatScript> GetAllTest(IStatScriptRepository StatScriptRep, string statType) { //only runs when first stat.IsDevelopment = true; StatScript testStat = StatScript.FillInDebugStatScript(StatScriptRep, statType); //also runs the Create controller action to test running the stat scripts if (testStat.IsDevelopment && (!string.IsNullOrEmpty(testStat.Key))) { Uri uri = await ClientProgram.ClientCreate(testStat); } return(testStat); }
private static string GetTempFilePath(StatScript statScript, string urlPath) { string sURLPath = ChangeScriptExtension(statScript, urlPath); string sFileName = GetLastSubString(sURLPath, WEBFILE_PATH_DELIMITER); string sResourcesDir = string.Concat(statScript.DefaultRootFullFilePath, "resources"); if (!statScript.DefaultRootFullFilePath.Contains("wwwroot")) { string sWebRoot = string.Concat(statScript.DefaultRootFullFilePath, "wwwroot"); if (!Directory.Exists(sWebRoot)) { Directory.CreateDirectory(sWebRoot); } //the release build doesn't include wwwroot in path sResourcesDir = string.Concat(sWebRoot, FILE_PATH_DELIMITER, "resources"); } else { if (!Directory.Exists(statScript.DefaultRootFullFilePath)) { Directory.CreateDirectory(statScript.DefaultRootFullFilePath); } } if (!Directory.Exists(sResourcesDir)) { Directory.CreateDirectory(sResourcesDir); } string sTempDir = string.Concat(sResourcesDir, FILE_PATH_DELIMITER, "temp"); if (!Directory.Exists(sTempDir)) { Directory.CreateDirectory(sTempDir); } //key allows easier debug string sGuidDir = string.Concat(sTempDir, FILE_PATH_DELIMITER, statScript.Key); if (!Directory.Exists(sGuidDir)) { Directory.CreateDirectory(sGuidDir); } string sTempFilePath = string.Concat(sGuidDir, FILE_PATH_DELIMITER, sFileName); return(sTempFilePath); }
public void ChangeGuiTarget(GameObject gTarget, bool i) { if (i == true) { isLock = true; } isActive = true; myGui.color = Color.white; childGui.SetActive(true); guiTarget = gTarget; if (gTarget) { TargetScript = guiTarget.GetComponent <StatScript> (); } }
public static async Task <string> SaveURLInTempFile(StatScript statScript, string url, string existingFilePath) { //statistical packages run using console process must be in filesystem //r can't handle urls to script files //async url to filesystem conversion string sURLContent = await ReadTextAsync(url); string sWebFileName = GetLastSubString(url, WEBFILE_PATH_DELIMITER); string sFileName = GetLastSubString(existingFilePath, FILE_PATH_DELIMITER); string sTempFilePath = existingFilePath.Replace(sFileName, sWebFileName); bool bIsSaved = await SaveStringInFilePath(statScript, sTempFilePath, sURLContent); return(sTempFilePath); }
IEnumerator CombatSetup() { GameObject playerGameObject = Instantiate(playerPrefab, playerSpawn); playerStats = playerGameObject.GetComponent <StatScript>(); GameObject enemyGameObject = Instantiate(enemyPrefab, enemySpawn); enemyStats = enemyGameObject.GetComponent <StatScript>(); trackerText.text = playerStats.entityName + " vs " + enemyStats.entityName; playerHud.SetCombatHUD(playerStats); enemyHud.SetCombatHUD(enemyStats); yield return(new WaitForSeconds(2f)); combatState = CombatSystem.PlayerTurn; PlayerTurn(); }
public static async Task <Uri> ClientDelete(StatScript statScript) { // HTTP DELETE example Uri address = new Uri(string.Concat(statScript.DefaultWebDomain, "api/statscript", "/", statScript.Key)); HttpClient client = new HttpClient(); var json = JsonConvert.SerializeObject(statScript); HttpResponseMessage response = await client.DeleteAsync(address); Uri outputURL = response.Headers.Location; return(outputURL); }
private static async Task <bool> SaveStringInFilePath(StatScript statScript, string filePath, string content) { bool bIsSaved = false; using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None)) { using (StreamWriter sw = new StreamWriter(fileStream)) { await sw.WriteAsync(content); bIsSaved = true; } } return(bIsSaved); }
private void PickTarget(GameObject go) { //go = go.transform.root.gameObject; bool pickTarget = false; if (stats && stats.IsEnraged) { pickTarget = pickTarget || go.CompareTag("BadGuy"); } pickTarget = pickTarget || go.CompareTag("GoodGuy") || go.CompareTag("Player"); pickTarget = pickTarget && !go.GetComponent <StatScript>().IsDead; // Will short circuit if there is no stats script because I'm cool if (pickTarget) { target = go; targetStatScript = target.GetComponent <StatScript>(); targetStatScript.SubscribeToOnDeath(OnTargetDeath); } }
public static async Task <Uri> ClientUpdate(StatScript statScript) { // HTTP PUT example Uri address = new Uri(string.Concat(statScript.DefaultWebDomain, "api/statscript", "/", statScript.Key)); HttpClient client = new HttpClient(); var json = JsonConvert.SerializeObject(statScript); //update something statScript.DataURL = "url2"; HttpResponseMessage response = await client.PutAsync(address, new StringContent(json, Encoding.UTF8, "application/json")); Uri outputURL = response.Headers.Location; return(outputURL); }
private static string ChangeScriptExtension(StatScript statScript, string urlPath) { string sNewURLPath = urlPath; //script files from devtreks use "txt" extension //convert to either pyw or R extension if (statScript.ScriptURL == urlPath) { if (statScript.StatType == StatScript.STAT_TYPE.py.ToString()) { sNewURLPath = sNewURLPath.Replace(".txt", ".pyw"); } else if (statScript.StatType == StatScript.STAT_TYPE.julia.ToString()) { sNewURLPath = sNewURLPath.Replace(".txt", ".j"); } else { sNewURLPath = sNewURLPath.Replace(".txt", ".R"); } } return(sNewURLPath); }
public static async Task <Uri> ClientCreate(StatScript statScript) { // HTTP POST example HttpClient client = new HttpClient(); var json = JsonConvert.SerializeObject(statScript); // Post statscript Uri address = new Uri(string.Concat(statScript.DefaultWebDomain, "api/statscript")); Uri outputURL = new Uri(address.ToString()); try { //create controller actionresult says this only returns a url //to the created statscript referenced in Location Header HttpResponseMessage response = await client.PostAsync(address, new StringContent(json, Encoding.UTF8, "application/json")); //can also use .PostAsJson(address, statScript) but requires Microsoft.AspNet.WebApi.Client.5.2.3 package // Check that response was successful or throw exception response.EnsureSuccessStatusCode(); // the statistical result of running the statscript : the key to the statscript object created //{http://localhost:52958/api/statscript/2e100e5e-997f-4b84-ac69-91b8add6bad2} outputURL = response.Headers.Location; } catch (Exception ex) { statScript.ErrorMessage = ex.Message; } //expects {http://localhost:52958/api/statscript/2e100e5e-997f-4b84-ac69-91b8add6bad2} //the key is used to run GetById and returns the Json statscript in response body return(outputURL); }
public static async Task <bool> RunScript(IStatScriptRepository StatScriptRep, StatScript initStat) { //remember: even if the script can't run; still want the error message saved in json output file //item contains the scriptURL and the dataURL bool bHasStatResult = false; //new Stat needs the paths to R and P executable and webRoots that were added //to StatRepo during Startup.cs StatScript.FillInRepositoryStatScriptProperties(StatScriptRep, initStat); StringBuilder sb = new StringBuilder(); initStat.IsComplete = false; if (string.IsNullOrEmpty(initStat.DataURL) || (!initStat.DataURL.EndsWith(".csv"))) { initStat.ErrorMessage = "The dataset file URL has not been added to the Data URL. The file must be stored in a Resource and use a csv file extension."; } if (string.IsNullOrEmpty(initStat.ScriptURL) || (!initStat.ScriptURL.EndsWith(".txt"))) { initStat.ErrorMessage += "The script file URL has not been added to the Joint Data.The file must be stored in a Resource and use a txt file extension."; } if (string.IsNullOrEmpty(initStat.StatType)) { initStat.ErrorMessage += "The type of statistical package to run has not been filled in. Please specify r or py."; } string sScriptExecutable = string.Empty; if (initStat.StatType == StatScript.STAT_TYPE.py.ToString()) { sScriptExecutable = initStat.PyExecutablePath; } else if (initStat.StatType == StatScript.STAT_TYPE.julia.ToString()) { sScriptExecutable = initStat.JuliaExecutablePath; } else { //no harm in filling in again, but client should have sent this initStat.StatType = StatScript.STAT_TYPE.r.ToString(); //default is R because it runs faster than Py sScriptExecutable = initStat.RExecutablePath; } if (string.IsNullOrEmpty(sScriptExecutable) || (!File.Exists(sScriptExecutable))) { initStat.ErrorMessage += "The file path to the script executable could not be found."; } string sDataURLFilePath = string.Empty; string sScriptURLFilePath = string.Empty; try { ProcessStartInfo start = new ProcessStartInfo(); start.FileName = sScriptExecutable; start.RedirectStandardOutput = true; start.UseShellExecute = false; //task.when.all this sDataURLFilePath = await FileStorageIO.SaveURLInTempFile(initStat, initStat.DataURL); sScriptURLFilePath = await FileStorageIO.SaveURLInTempFile(initStat, initStat.ScriptURL, sDataURLFilePath); //init url where stat results held initStat.OutputURL = string.Empty; start.Arguments = string.Format("{0} {1}", sScriptURLFilePath, sDataURLFilePath); start.CreateNoWindow = true; //the scripts are run sync using (Process process = Process.Start(start)) { using (StreamReader reader = process.StandardOutput) { //configure added to ensure results appended to sb sb.Append(await reader.ReadToEndAsync().ConfigureAwait(false)); } process.WaitForExit(); } //client accesses results by deserializing Json response body //api only returns json statscript and can't access wwwroot except through api initStat.StatisticalResult = FileStorageIO.CleanScriptforResponseBody(sb); if (string.IsNullOrEmpty(initStat.StatisticalResult)) { initStat.ErrorMessage += "The script could not be run. Please double check both the script and the dataset"; } else { //fill in completed date -used to delete completed scripts on server initStat.DateCompleted = DateTime.Now.Date.ToString("d", CultureInfo.InvariantCulture); initStat.IsComplete = true; } //initStat is added to temp file storage and path is converted to url for auditing //the url can't be directly accessed but the file path can be found from outputURL var json = JsonConvert.SerializeObject(initStat); bool bHasSaved = await FileStorageIO.SaveContentInFile(initStat, sDataURLFilePath, json); if (bHasSaved) { bHasStatResult = initStat.IsComplete; } else { initStat.ErrorMessage += "The json results could not be saved in file system."; } } catch (Exception x) { initStat.ErrorMessage += x.Message; } return(bHasStatResult); }
// Start is called before the first frame update void Start() { // Init spells spellModifierAIScoreTracker = new SpellModifierAIScoreTracker(); spellModifierAIScoreTracker.agent = this; AIFirebolt = new SpellScript.Spell() { name = "Firebolt", shape = AllSpellsAndGlyphs.spellShapeBolt, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectFire, spellModifierAIScoreTracker } }; AIHealSelf = new SpellScript.Spell() { name = "Heal self", shape = AllSpellsAndGlyphs.spellShapeSelf, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectHeal, spellModifierAIScoreTracker } }; AIHealOther = new SpellScript.Spell() { name = "Heal other", shape = AllSpellsAndGlyphs.spellShapeBolt, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectHeal, spellModifierAIScoreTracker } }; AIFreeze = new SpellScript.Spell() { name = "Freeze", shape = AllSpellsAndGlyphs.spellShapeBolt, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectFreeze, spellModifierAIScoreTracker } }; AIStun = new SpellScript.Spell() { name = "Stun", shape = AllSpellsAndGlyphs.spellShapeBolt, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectStun, spellModifierAIScoreTracker } }; spells = new SpellScript.Spell[2] { AIFirebolt, AIFreeze }; startPos = transform.localPosition; stats = GetComponent <StatScript>(); rb = GetComponent <Rigidbody>(); //AgentReset(); startFrame = Time.frameCount; stats.SubscribeToOnDeath(OnDeath); stats.SubscribeToOnHealthChange(OnHealthChange); for (int i = 0; i < enemies.Length; ++i) { GameObject enemy = enemies[i]; StatScript enemyStat = enemy.GetComponent <StatScript>(); EnemyAI enemyAI = enemy.GetComponent <EnemyAI>(); enemyStats[i] = enemyStat; enemyAIs[i] = enemyAI; enemyStat.SubscribeToOnDeath(OnEnemyDeath); enemyStat.SubscribeToOnHealthChange(OnEnemyHealthChange); } enemyFields[0] = Enemy1Fields; enemyFields[1] = Enemy2Fields; enemyFields[2] = Enemy3Fields; enemyFields[3] = Enemy4Fields; }
protected virtual void OnTargetDeath(Object[] obj) { StatScript enemyStatScript = obj[0] as StatScript; ResetTarget(); }
public float ft_ChanceOfHit(StatScript target) { return(75 + Agility - target.Agility); }
void Awake() { if (instance != null && instance != this) { Destroy(this); } instance = this; DontDestroyOnLoad(this); }
public int ft_FinalDamage(StatScript target) { return(Mathf.RoundToInt((ft_BaseDamage() * (1 - target.Armor / 200)))); }
private void Start() { stats = GameObject.Find("World").GetComponent<StatScript>(); priceTag.text = "Cost per Upgrade: " + upgradeCost + " EXP"; }