RewardRanking(ArenaNode ParentNode, ArenaNode ChildNode) { // compute reward based on ranking float StepReward_ = 0f; if (ParentNode.RankingWinType == RankingWinTypes.Survive) { // Survive: dead ranking at 1 means reward 0, the higher the dead ranking, the better StepReward_ += (float)ChildNode.GetKilledRanking() * globalManager.RewardRankingCoefficient; } else if (ParentNode.RankingWinType == RankingWinTypes.Depart) { // Depart: dead last (ranking getNumTeams()) means reward 0, the lower the dead ranking, the better StepReward_ += ((float)ParentNode.GetNumChildNodes() - (float)ChildNode.GetKilledRanking() - 1f) * globalManager.RewardRankingCoefficient; } else { Debug.LogError("RankingWinType is invalid."); } // add the computed reward ChildNode.AddReward(StepReward_ * ParentNode.RewardSchemeScale); }
GetParentNode() { if (ParentNode == null) { ParentNode = Utils.GetBottomLevelArenaNodeInGameObject(gameObject); } return(ParentNode); }
GetTopLevelArenaNodesInChildren(GameObject GameObject_) { List <ArenaNode> ArenaNodes = new List <ArenaNode>(); for (int ID = 0; ID < GameObject_.transform.childCount; ID++) { ArenaNode ArenaNode_ = GameObject_.transform.GetChild(ID).gameObject.GetComponent <ArenaNode>(); if (ArenaNode_ != null) { ArenaNodes.Add(ArenaNode_); } } return(ArenaNodes); }
TrigEvent(GameObject other) { // if collid with body, according to https://www.youtube.com/watch?v=35lpSHgvibU if (other.CompareTag("Body")) { ArenaNode OtherNode = Utils.GetBottomLevelArenaNodeInGameObject(other); ArenaNode ThisNode = Utils.GetBottomLevelArenaNodeInGameObject(gameObject); List <int> ThisNodeCoordinate = ThisNode.GetCoordinate(); List <int> OtherNodeCoordinate = OtherNode.GetCoordinate(); if (!Utils.IsListEqual(ThisNodeCoordinate, OtherNodeCoordinate, Mathf.Min(ThisNodeCoordinate.Count, OtherNodeCoordinate.Count))) { ThisNode.Kill(); } } } // TrigEvent
GetBottomLevelArenaNodeInGameObject(GameObject GameObject_) { Transform parent_ = GameObject_.transform.parent; if (parent_ != null) { ArenaNode ArenaNode_ = parent_.gameObject.GetComponent <ArenaNode>(); if (ArenaNode_ != null) { return(ArenaNode_); } else { return(GetBottomLevelArenaNodeInGameObject(parent_.gameObject)); } } else { return(null); } }
DiscreteStep(int Action_) { if (GetActionSpaceType() != SpaceType.discrete) { Debug.LogError("ActionSpaceType is not Discrete, DiscreteStep() should not be called."); } if (AllowGunAttack) { if (IsShowAimLine) { IsHit = Physics.Raycast(RaycastEmitter.transform.position, RaycastEmitter.transform.up, out AimRaycast); if (IsHit) { AimLine.DrawLineInGameView(RaycastEmitter.transform.position, RaycastEmitter.transform.position + RaycastEmitter.transform.up * AimRaycast.distance, ((Action_ == Attack) && (NumBullet > 0) && (!Reloading) && (CoolingSteps == 0)) ? AimLineColorWhenAttack : AimLineColor); } } else { AimLine.DrawLineInGameView(RaycastEmitter.transform.position, RaycastEmitter.transform.position + RaycastEmitter.transform.up * 0f, AimLineColor); } switch (Action_) { case Attack: if ((NumBullet > 0) && (!Reloading) && (CoolingSteps == 0)) { CoolingSteps = NumCoolingSteps + 1; if (ShootType == ShootTypes.Raycast) { if (!IsShowAimLine) { // not showing aim line, so raycast need to be done here IsHit = Physics.Raycast(RaycastEmitter.transform.position, RaycastEmitter.transform.up, out AimRaycast); if (IsHit) { AimLine.DrawLineInGameView(RaycastEmitter.transform.position, RaycastEmitter.transform.position + RaycastEmitter.transform.up * AimRaycast.distance, AimLineColorWhenAttack); } } if (IsHit) { if (TrigTags.Contains(AimRaycast.collider.gameObject.tag)) { ArenaNode SubjectNode = Utils.GetBottomLevelArenaNodeInGameObject( AimRaycast.collider.gameObject); if (IsKill) { SubjectNode.Kill(); } if (KillHealth != 0f) { SubjectNode.IncrementAttribute("Health", -KillHealth); } } if (AimRaycast.collider.gameObject.tag == "ObstacleDestroyable") { AimRaycast.collider.gameObject.GetComponent <Destroyable>().Hitted(); } } } else if (ShootType == ShootTypes.Bullet) { GameObject Temp_Bullet_Handeler; Temp_Bullet_Handeler = Instantiate(Bullet, BulletEmitter.transform.position, BulletEmitter.transform.rotation) as GameObject; Temp_Bullet_Handeler.GetComponent <Rigidbody>().AddForce( BulletEmitter.transform.up * BulletFarwardForce); } NumBullet -= 1.0f; foreach (Dictionary <string, UIPercentageBar> UIPercentageBars in AllAgentCamerasUIPercentageBars) { UIPercentageBars["Ammo"].UpdatePercentage(GetBulletPercentage()); } if (NumBullet < 1.0f) { Reloading = true; } } break; default: break; } if (CoolingSteps > 0) { CoolingSteps--; } if (Reloading) { NumBullet += NumBulletPerLoad; foreach (Dictionary <string, UIPercentageBar> UIPercentageBars in AllAgentCamerasUIPercentageBars) { UIPercentageBars["Ammo"].UpdatePercentage(GetBulletPercentage()); } if (NumBullet >= FullNumBullet) { Reloading = false; } } } } // DiscreteStep
TrigEvent(GameObject other) { if (TrigTags.Contains(other.tag)) { OtherNode = Utils.GetBottomLevelArenaNodeInGameObject(other); ThisNode = Utils.GetBottomLevelArenaNodeInGameObject(gameObject); ArenaNode SubjectNode; if (SubjectType == SubjectTypes.This) { SubjectNode = ThisNode; } else { SubjectNode = OtherNode; } if (SubjectNode == null) { return; } if (IsMatchNodeCoordinate) { if ((ThisNode == null) || (OtherNode == null)) { return; } else { List <int> ThisNodeCoordinate = ThisNode.GetCoordinate_ParentToChild(); List <int> OtherNodeCoordinate = OtherNode.GetCoordinate_ParentToChild(); if (!Utils.IsListEqual(ThisNodeCoordinate, OtherNodeCoordinate, Mathf.Min(ThisNodeCoordinate.Count, OtherNodeCoordinate.Count))) { return; } } } if (IsKill) { BeforeTrigKill(); SubjectNode.Kill(); } foreach (string Attribute_ in IncrementAttributes.Keys) { if (float.Parse(IncrementAttributes[Attribute_]) != 0f) { float Scale_ = 1f; if (CompareTag("Eatable")) { Scale_ = transform.localScale.y; } SubjectNode.IncrementAttribute(Attribute_, float.Parse(IncrementAttributes[Attribute_]) * Scale_); } } if (IsCarried) { ToFollow = other; RelativePosition = transform.position - ToFollow.transform.position; } } } // TrigEvent