void EndEpisode() { GameObject[] Remained = inspector.getCurrentUnits(); foreach (GameObject unit in Remained) { if (inspector.setScriptsFrom(unit)) { if (inspector.getScriptType() == "Unit") { inspector.removeFrom(unit); Destroy(unit); } else if (inspector.getScriptType() == "AgentScript") { Debug.LogWarning("Agent Remained after episode ends"); } } } sys.battleStarted = false; System.Array.Resize(ref sys.knightUnits, 0); System.Array.Resize(ref sys.enemyUnits, 0); foreach (GameObject unit in inspector.getInstantiatedUnits()) { Destroy(unit); } foreach (GameObject corpe in GameObject.FindGameObjectsWithTag("Ragdoll")) { corpe.GetComponent <DeleteParticles>().DestroyMe(); } }
public void onStart() { if (Dict != null) { foreach (Healthbar pair in Dict.Values) { Destroy(pair.gameObject); } } Dict = new Dictionary <GameObject, Healthbar>(); if (characterPlacer.showhp) { GameObject[] units = inspector.getCurrentUnits(); for (int i = 1; i <= units.Length; i++) { if (inspector.setScriptsFrom(units[i - 1])) { GameObject obj = Instantiate(HpBar); Healthbar bar = obj.GetComponent <Healthbar>(); bar.SetDesc(inspector.getScriptType()); bar.SetColorTag(units[i - 1].tag); bar.maximumHealth = inspector.getInitialLives(); obj.transform.SetParent(HpBarParent); obj.transform.localPosition = new Vector3(87, i * (-34) - 38, 30); obj.transform.localScale = new Vector3(1f, 0.2f, 0.2f); Dict.Add(units[i - 1], bar); } } } }
public void Academy_EnemySpawn() { foreach (GameObject enemy in levelData.levels[0].units) { if (inspector.setScriptsFrom(enemy)) { placeEnemy(enemy); } } }
/// <summary>set Debuginfo from given unit</summary> /// <param name="unit">lolsbarry</param> public void setFromUnit(GameObject unit) { if (i.setScriptsFrom(unit)) { initialLives = i.getInitialLives(); currentLives = i.getLives(); defaultDammage = i.getDamage(); attackTag = i.getAttackTag(); range = i.getRange(); unitType = i.getScriptType(); //needAction=i.getNeedAction(); } }
public override void RewardAtEpisodeEnds(UnitInspect inspector, GameSystem sys) { float AllDamaged = (inspector.getCurrentEnemys().Length <= 0)?0:inspector.AvgLives(inspector.getCurrentEnemys()); //Rewarding globally foreach (GameObject knight in inspector.getInstantiatedKnights()) { inspector.setScriptsFrom(knight); if (inspector.isScriptValid() && inspector.getScriptType() == "AgentScript") { BagReset(); AddReward((1 - ((AllDamaged) / sys.AllInitLives)) * 2f); Apply(inspector.AgentScript); } } /* * //Rewarding reamined units * foreach(GameObject knight in inspector.getCurrentKnights()) { * inspector.AgentAddRewardDircetly(1f); * } */ }
public override void CollectObservations() { if (sys != null) { if (!sys.battleStarted) { Debug.LogWarning("Observation triggered before battle started. sending zero observation"); for (int i = 0; i < PlannedObs; i++) { AddVectorObs(0); AddVectorObs(0); } } else { GameObject[] Knight = inspector.getCurrentKnights(); GameObject[] Enemy = inspector.getCurrentEnemys(); for (int i = 0; i < sys.initKnightNumber; i++) { if (i >= Knight.Length || Knight?[i] == null) { AddVectorObs(0); AddVectorObs(0); continue; } if (inspector.setScriptsFrom(Knight[i])) //returns true when it's valid { if (!inspector.isDead()) { // When alive AddVectorObs(Knight[i].transform.localPosition.x); AddVectorObs(Knight[i].transform.localPosition.z); } else { // When dead AddVectorObs(0); AddVectorObs(0); } continue; } //When script is not valid but it existed as game object Debug.LogWarning("Unknown game object tagged as knight and it observated."); AddVectorObs(0); AddVectorObs(0); continue; } for (int i = 0; i < sys.initEnemyNumber; i++) { if (i >= Enemy.Length || Enemy?[i] == null) { AddVectorObs(0); AddVectorObs(0); continue; } if (inspector.setScriptsFrom(Enemy[i])) //returns true when it's valid { if (!inspector.isDead()) { AddVectorObs(Enemy[i].transform.localPosition.x); AddVectorObs(Enemy[i].transform.localPosition.z); } else { AddVectorObs(0); AddVectorObs(0); } continue; } Debug.LogError("Unknown game object tagged as enemy and it observated."); AddVectorObs(0); AddVectorObs(0); continue; } } } else { Debug.LogError("Observation triggered before even game system instantiate"); for (int i = 0; i < PlannedObs; i++) //placeholder { AddVectorObs(0); AddVectorObs(0); } } SetTextObs($"{inspector.AvgLives(inspector.getCurrentKnights())}"); }
void FixedUpdate() { if (lives != lastLives && Academy.showeffects) { if (!DamagedParticle.isPlaying) { DamagedParticle.Play(); //DamagedParticle.Simulate(Time.unscaledDeltaTime, true, false); } lastLives = lives; } //find closest enemy //ML:relating to moves if (currentTarget != null) { inspector.setScriptsFrom(currentTarget.gameObject); if (!inspector.isScriptValid() || inspector.isDead()) { currentTarget = findCurrentTarget(); } } else { currentTarget = findCurrentTarget(); } //if character ran out of lives, it should die if (lives < 0 && !dead) { die(); } else { if (Vector3.Distance(agent.destination, transform.position) <= agent.stoppingDistance && currentTarget != null) { int sign = rnd.Next(0, 2) * 2 - 1; int sign2 = rnd.Next(0, 2) * 2 - 1; agent.destination = new Vector3(currentTarget.position.x + (float)gausianRand() * RandomRange * sign, currentTarget.position.y, currentTarget.position.z + (float)gausianRand() * RandomRange * sign2); agent.isStopped = false; } else if (currentTarget == null) { agent.destination = getRandomPosition(area); } if (isPassedCooltime) //&& (rnd.Next(0, 2) * 2 - 1)>0) { { foreach (GameObject unit in HitboxComponent.GetCollideObjects()) { if (unit == null && !ReferenceEquals(unit, null)) { HitboxComponent.RemoveObject(unit); continue; } if (unit.CompareTag("Knight")) { if (inspector.setScriptsFrom(unit) && !inspector.isDead()) { inspector.setLives(inspector.getLives() - (damage)); if (inspector.getLives() < 0) { HitboxComponent.RemoveObject(unit); } } else { Debug.LogWarning("Invalid Target Triggered."); } } } isPassedCooltime = false; StartCoroutine("Cooltime"); } } //ML:relating to moves }