2022-11-28 22:54:08 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2022-12-03 23:40:23 +00:00
|
|
|
using System.Xml.Serialization;
|
2022-11-28 22:54:08 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using Random = UnityEngine.Random;
|
|
|
|
|
|
|
|
public class TargetController : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject EnvironmentObj;
|
|
|
|
public GameObject AgentObj;
|
2022-12-09 09:53:53 +00:00
|
|
|
public GameObject HUDObj;
|
2022-11-28 22:54:08 +00:00
|
|
|
public GameObject SceneBlockContainerObj;
|
|
|
|
public GameObject EnemyContainerObj;
|
|
|
|
public GameObject ParameterContainerObj;
|
|
|
|
public GameObject EnvironmentUIObj;
|
|
|
|
public GameObject WorldUIObj;
|
|
|
|
// area
|
|
|
|
public GameObject edgeUp;
|
|
|
|
public GameObject edgeDown;
|
|
|
|
public GameObject edgeLeft;
|
|
|
|
public GameObject edgeRight;
|
|
|
|
public GameObject edgeAgent_Enemy;
|
|
|
|
|
|
|
|
//group
|
|
|
|
public string group1Tag = "Player";
|
|
|
|
public string group2Tag = "Enemy";
|
|
|
|
|
|
|
|
public float minEnemyAreaX;
|
|
|
|
[System.NonSerialized] public float maxEnemyAreaX;
|
|
|
|
[System.NonSerialized] public float minEnemyAreaZ;
|
|
|
|
[System.NonSerialized] public float maxEnemyAreaZ;
|
|
|
|
[System.NonSerialized] public float minAgentAreaX;
|
|
|
|
[System.NonSerialized] public float maxAgentAreaX;
|
|
|
|
[System.NonSerialized] public float minAgentAreaZ;
|
|
|
|
[System.NonSerialized] public float maxAgentAreaZ;
|
|
|
|
[System.NonSerialized] public float startTime = 0f;
|
|
|
|
[System.NonSerialized] public float leftTime = 0f;
|
|
|
|
|
|
|
|
[SerializeField, Range(0f, 1f)] public float attackProb = 0.2f;
|
|
|
|
[SerializeField, Range(0f, 1f)] public float gotoProb = 0.2f;
|
|
|
|
[SerializeField, Range(0f, 1f)] public float defenceProb = 0.2f;
|
|
|
|
|
|
|
|
[System.NonSerialized] public int targetTypeInt;
|
2022-12-03 08:42:51 +00:00
|
|
|
public float[] targetState = new float[6];
|
2022-11-28 22:54:08 +00:00
|
|
|
public enum Targets { Free, Go, Attack, Defence, Num };// Num is use for get total target bumber
|
|
|
|
public enum EndType { Win, Lose, Running, Num };
|
|
|
|
[System.NonSerialized] public int targetNum = 0;
|
|
|
|
private Dictionary<int, float[]> oneHotRarget = new Dictionary<int, float[]>();
|
|
|
|
|
2022-12-03 23:40:23 +00:00
|
|
|
private int inArea = 0;
|
2022-11-28 22:54:08 +00:00
|
|
|
private float freeProb;
|
|
|
|
private float sceneSize;
|
|
|
|
private float lastDistance;
|
2022-12-05 05:56:18 +00:00
|
|
|
public Vector3 targetPosition;
|
2022-11-28 22:54:08 +00:00
|
|
|
private Vector3 targetLocalPosition;
|
|
|
|
private bool firstRewardFlag = true;
|
2022-12-01 10:52:52 +00:00
|
|
|
private bool targetEnemySpawnFinish = false;
|
2022-11-28 22:54:08 +00:00
|
|
|
private SceneBlockContainer blockCont;
|
|
|
|
private EnemyContainer enemyCont;
|
|
|
|
private EnvironmentUIControl envUICon;
|
|
|
|
private ParameterContainer paramCon;
|
|
|
|
private CharacterController agentCharaCon;
|
|
|
|
private WorldUIController worldUICon;
|
2022-12-09 09:53:53 +00:00
|
|
|
private HUDController hudCon;
|
2022-12-18 11:17:08 +00:00
|
|
|
private RaySensors raySensors;
|
2022-11-28 22:54:08 +00:00
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
minEnemyAreaX = edgeLeft.transform.localPosition.x + 1.0f;
|
|
|
|
maxEnemyAreaX = edgeRight.transform.localPosition.x - 1.0f;
|
|
|
|
minEnemyAreaZ = edgeAgent_Enemy.transform.localPosition.z + 1.0f;
|
|
|
|
maxEnemyAreaZ = edgeUp.transform.localPosition.z - 1.0f;
|
|
|
|
|
|
|
|
minAgentAreaX = edgeLeft.transform.localPosition.x + 1.0f;
|
|
|
|
maxAgentAreaX = edgeRight.transform.localPosition.x - 1.0f;
|
|
|
|
minAgentAreaZ = edgeDown.transform.localPosition.z + 1.0f;
|
|
|
|
maxAgentAreaZ = edgeAgent_Enemy.transform.localPosition.z - 1.0f;
|
|
|
|
|
|
|
|
blockCont = SceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
|
|
|
envUICon = EnvironmentUIObj.GetComponent<EnvironmentUIControl>();
|
|
|
|
enemyCont = EnemyContainerObj.GetComponent<EnemyContainer>();
|
|
|
|
agentCharaCon = AgentObj.GetComponent<CharacterController>();
|
|
|
|
paramCon = ParameterContainerObj.GetComponent<ParameterContainer>();
|
|
|
|
worldUICon = WorldUIObj.GetComponent<WorldUIController>();
|
2022-12-09 09:53:53 +00:00
|
|
|
hudCon = HUDObj.GetComponent<HUDController>();
|
2022-12-18 11:17:08 +00:00
|
|
|
raySensors = AgentObj.GetComponent<RaySensors>();
|
2022-11-28 22:54:08 +00:00
|
|
|
freeProb = 1 - attackProb - gotoProb - defenceProb;
|
|
|
|
targetNum = (int)Targets.Num;
|
|
|
|
if (freeProb < 0)
|
|
|
|
{
|
|
|
|
Debug.LogError("target percentage wrong");
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize a simple fake onehot encoder.
|
|
|
|
for (int i = 0; i < targetNum; i++)
|
|
|
|
{
|
|
|
|
float[] onehotList = new float[targetNum];
|
|
|
|
for (int j = 0; j < targetNum; j++)
|
|
|
|
{
|
|
|
|
onehotList[j] = 0;
|
|
|
|
}
|
|
|
|
onehotList[i] = 1;
|
|
|
|
oneHotRarget.Add(i, onehotList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
leftTime = paramCon.timeLimit - Time.time + startTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void rollNewScene()
|
|
|
|
{
|
|
|
|
startTime = Time.time;// Reset StartTime as now time
|
2022-11-29 21:39:56 +00:00
|
|
|
leftTime = paramCon.timeLimit - Time.time + startTime;
|
2022-11-28 22:54:08 +00:00
|
|
|
float randTargetType = UnityEngine.Random.Range(0f, 1f);
|
|
|
|
if (randTargetType <= gotoProb)
|
|
|
|
{
|
|
|
|
// goto target spawn
|
|
|
|
Debug.Log("GOTO THIS TARGET!");
|
|
|
|
targetTypeInt = (int)Targets.Go;
|
|
|
|
int randBlockType = Random.Range(0, blockCont.goBlockPrefabs.Length);
|
|
|
|
// get choosed scene size
|
|
|
|
sceneSize = blockCont.goBlockPrefabs[randBlockType].GetComponent<SceneBlock>().blockSize;
|
2022-12-03 08:42:51 +00:00
|
|
|
float randX = UnityEngine.Random.Range(minEnemyAreaX + sceneSize/2 + 1f, maxEnemyAreaX - sceneSize/2 - 1f);
|
|
|
|
float randZ = UnityEngine.Random.Range(minEnemyAreaZ + sceneSize/2 + 1f, maxEnemyAreaZ - sceneSize/2 - 1f);
|
2022-11-28 22:54:08 +00:00
|
|
|
targetPosition = new Vector3(randX, 0f, randZ);
|
|
|
|
// Init Agent position
|
|
|
|
moveAgentToSpwanArea();
|
|
|
|
// init scene block
|
|
|
|
blockCont.destroyBlock();
|
|
|
|
blockCont.createNewBlock(targetTypeInt, randBlockType, targetPosition, group1Tag, group2Tag);
|
|
|
|
enemyCont.destroyAllEnemys();
|
2022-12-09 09:53:53 +00:00
|
|
|
enemyCont.randomInitEnemysExcept(hudCon.enemyNum, targetPosition, sceneSize);
|
2022-11-28 22:54:08 +00:00
|
|
|
blockCont.thisBlock.initBlock(EnvironmentObj);
|
|
|
|
// set startDistance
|
|
|
|
firstRewardFlag = true;
|
|
|
|
}
|
|
|
|
else if (randTargetType > gotoProb && randTargetType <= gotoProb + attackProb)
|
|
|
|
{
|
|
|
|
// attack target spawn
|
|
|
|
Debug.Log("ATTACK!");
|
|
|
|
targetTypeInt = (int)Targets.Attack;
|
|
|
|
int randBlockType = Random.Range(0, blockCont.attackBlockPrefabs.Length);
|
|
|
|
// get choosed scene size
|
|
|
|
sceneSize = blockCont.attackBlockPrefabs[randBlockType].GetComponent<SceneBlock>().blockSize;
|
2022-12-03 08:42:51 +00:00
|
|
|
float randX = UnityEngine.Random.Range(minEnemyAreaX + sceneSize/2 + 1f, maxEnemyAreaX - sceneSize/2 - 1f);
|
|
|
|
float randZ = UnityEngine.Random.Range(minEnemyAreaZ + sceneSize/2 + 1f, maxEnemyAreaZ - sceneSize/2 - 1f);
|
2022-11-28 22:54:08 +00:00
|
|
|
targetPosition = new Vector3(randX, 0f, randZ);
|
|
|
|
// Init Agent position
|
|
|
|
moveAgentToSpwanArea();
|
|
|
|
// init scene block
|
|
|
|
blockCont.destroyBlock();
|
|
|
|
blockCont.createNewBlock(targetTypeInt, randBlockType, targetPosition, group1Tag, group2Tag);
|
|
|
|
enemyCont.destroyAllEnemys();
|
2022-12-09 09:53:53 +00:00
|
|
|
enemyCont.randomInitEnemysExcept(hudCon.enemyNum, targetPosition, sceneSize);
|
2022-11-28 22:54:08 +00:00
|
|
|
blockCont.thisBlock.initBlock(EnvironmentObj);
|
|
|
|
// set startDistance
|
|
|
|
firstRewardFlag = true;
|
2022-12-01 10:52:52 +00:00
|
|
|
targetEnemySpawnFinish = false;
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
else if (randTargetType > gotoProb + attackProb && randTargetType <= gotoProb + attackProb + defenceProb)
|
|
|
|
{
|
|
|
|
// defence target spawn
|
|
|
|
Debug.Log("DEFENCE!");
|
|
|
|
targetTypeInt = (int)Targets.Defence;
|
|
|
|
int randBlockType = Random.Range(0, blockCont.attackBlockPrefabs.Length);
|
|
|
|
// get choosed scene size
|
|
|
|
sceneSize = blockCont.defencePrefabs[randBlockType].GetComponent<SceneBlock>().blockSize;
|
2022-12-03 08:42:51 +00:00
|
|
|
float randX = UnityEngine.Random.Range(minEnemyAreaX + sceneSize/2 + 1f, maxEnemyAreaX - sceneSize/2 - 1f);
|
|
|
|
float randZ = UnityEngine.Random.Range(minEnemyAreaZ + sceneSize/2 + 1f, maxEnemyAreaZ - sceneSize/2 - 1f);
|
2022-11-28 22:54:08 +00:00
|
|
|
targetPosition = new Vector3(randX, 0f, randZ);
|
|
|
|
// Init Agent position
|
|
|
|
moveAgentTo(targetPosition);
|
|
|
|
// init scene block
|
|
|
|
blockCont.destroyBlock();
|
|
|
|
blockCont.createNewBlock(targetTypeInt, randBlockType, targetPosition, group1Tag, group2Tag);
|
|
|
|
enemyCont.destroyAllEnemys();
|
2022-12-09 09:53:53 +00:00
|
|
|
enemyCont.randomInitEnemysExcept(hudCon.enemyNum, targetPosition, sceneSize);
|
2022-11-28 22:54:08 +00:00
|
|
|
blockCont.thisBlock.initBlock(EnvironmentObj);
|
|
|
|
// set startDistance
|
|
|
|
firstRewardFlag = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-18 11:17:08 +00:00
|
|
|
//Debug.Log("Free");
|
2022-11-28 22:54:08 +00:00
|
|
|
targetTypeInt = (int)Targets.Free;
|
|
|
|
enemyCont.destroyAllEnemys();
|
2022-12-09 09:53:53 +00:00
|
|
|
enemyCont.randomInitEnemys(hudCon.enemyNum);
|
2022-11-28 22:54:08 +00:00
|
|
|
moveAgentToSpwanArea();
|
|
|
|
blockCont.destroyBlock();
|
|
|
|
}
|
2022-12-03 08:42:51 +00:00
|
|
|
updateTargetStates();
|
2022-11-29 21:39:56 +00:00
|
|
|
envUICon.updateTargetType(targetTypeInt);
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get target observation states
|
2022-12-03 08:42:51 +00:00
|
|
|
public void updateTargetStates()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
// targettype, x,y,z, firebasesAreaDiameter
|
|
|
|
if (targetTypeInt == (int)Targets.Free)
|
|
|
|
{
|
2022-12-03 08:42:51 +00:00
|
|
|
targetState[0] = targetTypeInt;
|
|
|
|
for(int i = 1; i < targetState.Length; i++)
|
|
|
|
targetState[i] = 0f;
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-03 08:42:51 +00:00
|
|
|
targetState[0] = targetTypeInt;
|
2023-03-07 08:29:47 +00:00
|
|
|
/* targetState[1] = targetPosition.x / raySensors.viewDistance; // normalization
|
2022-12-18 11:17:08 +00:00
|
|
|
targetState[2] = targetPosition.y / raySensors.viewDistance;
|
2023-03-07 08:29:47 +00:00
|
|
|
targetState[3] = targetPosition.z / raySensors.viewDistance;*/
|
|
|
|
targetState[1] = targetPosition.x; // normalization
|
|
|
|
targetState[2] = targetPosition.y;
|
|
|
|
targetState[3] = targetPosition.z;
|
2022-12-18 11:17:08 +00:00
|
|
|
targetState[4] = blockCont.thisBlock.firebasesAreaDiameter / raySensors.viewDistance;
|
2022-12-03 08:42:51 +00:00
|
|
|
targetState[5] = blockCont.thisBlock.belongRatio;
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// move Agent into Agent Spawn Area
|
|
|
|
public void moveAgentToSpwanArea()
|
|
|
|
{
|
2022-12-07 21:24:51 +00:00
|
|
|
float randX = UnityEngine.Random.Range(minAgentAreaX, maxAgentAreaX); ;
|
|
|
|
float randZ = 0f;
|
|
|
|
if (paramCon.spawnAgentInAllMap)
|
|
|
|
{
|
|
|
|
// spawn agent in all around map
|
|
|
|
randZ = UnityEngine.Random.Range(minAgentAreaZ, maxEnemyAreaZ);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// spawn agent in only agent spawn area
|
|
|
|
randZ = UnityEngine.Random.Range(minAgentAreaZ, maxAgentAreaZ);
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
int Y = 1;
|
|
|
|
Vector3 initAgentLoc = new Vector3(randX, Y, randZ);
|
|
|
|
moveAgentTo(initAgentLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// move Agent to this position
|
|
|
|
public void moveAgentTo(Vector3 thisPosition)
|
|
|
|
{
|
|
|
|
// while using transform.localPosition to move character
|
|
|
|
// u should turn off character Controller or it won't work
|
|
|
|
agentCharaCon.enabled = false;
|
|
|
|
AgentObj.transform.localPosition = thisPosition;
|
|
|
|
agentCharaCon.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// check over and get rewards
|
|
|
|
// 1 = success,2 = overtime,0 = notover
|
2022-12-03 08:42:51 +00:00
|
|
|
public (int, float,float) checkOverAndRewards()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
int endTypeInt = 0;
|
|
|
|
float thisReward = 0;
|
2022-12-03 08:42:51 +00:00
|
|
|
float endReward = 0;
|
2022-11-28 22:54:08 +00:00
|
|
|
float nowDistance = 0f;
|
|
|
|
switch (targetTypeInt)
|
|
|
|
{
|
|
|
|
case (int)Targets.Go:
|
|
|
|
// goto
|
|
|
|
(nowDistance, inArea) = blockCont.getAgentTargetDistanceAndInside(AgentObj.transform.position);
|
|
|
|
envUICon.updateTargetGauge(blockCont.thisBlock.firebasesBelong, blockCont.thisBlock.belongMaxPoint);
|
2022-12-03 23:40:23 +00:00
|
|
|
float areaTargetReward = getDistanceReward(nowDistance, inArea);
|
2023-02-15 12:06:57 +00:00
|
|
|
//if(inArea != 0)
|
|
|
|
if (blockCont.thisBlock.firebasesBelong >= blockCont.thisBlock.belongMaxPoint)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
// win
|
|
|
|
// let the area belongs to me
|
2022-12-03 08:42:51 +00:00
|
|
|
thisReward = areaTargetReward;
|
|
|
|
endReward = paramCon.goWinReward;
|
|
|
|
//thisReward = (paramCon.inAreaReward * inArea) + getDistanceReward(nowDistance);
|
2022-11-28 22:54:08 +00:00
|
|
|
endTypeInt = (int)EndType.Win;
|
|
|
|
}
|
|
|
|
else if (leftTime <= 0)
|
|
|
|
{
|
|
|
|
// time out lose
|
2022-12-03 08:42:51 +00:00
|
|
|
thisReward = areaTargetReward;
|
|
|
|
endReward = paramCon.loseReward;
|
2022-11-28 22:54:08 +00:00
|
|
|
endTypeInt = (int)EndType.Lose;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// keep on keeping on!
|
2022-12-03 08:42:51 +00:00
|
|
|
thisReward = areaTargetReward;
|
|
|
|
endReward = 0;
|
2022-11-28 22:54:08 +00:00
|
|
|
endTypeInt = (int)EndType.Running;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (int)Targets.Attack:
|
|
|
|
// attack
|
|
|
|
(nowDistance, inArea) = blockCont.getAgentTargetDistanceAndInside(AgentObj.transform.position);
|
|
|
|
envUICon.updateTargetGauge(blockCont.thisBlock.firebasesBelong, blockCont.thisBlock.belongMaxPoint);
|
2022-12-01 10:52:52 +00:00
|
|
|
if (blockCont.thisBlock.getInAreaNumber(group2Tag) <= 0 && targetEnemySpawnFinish)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
// win
|
|
|
|
// let the area belongs to me and kill every enmy in this area.
|
2022-12-03 08:42:51 +00:00
|
|
|
thisReward = 0;
|
|
|
|
endReward = paramCon.attackWinReward;
|
2022-11-28 22:54:08 +00:00
|
|
|
//thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
|
|
|
endTypeInt = (int)EndType.Win;
|
|
|
|
}
|
2022-12-01 10:52:52 +00:00
|
|
|
else if (leftTime <= 0 && targetEnemySpawnFinish)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
// time out lose
|
2022-12-03 08:42:51 +00:00
|
|
|
thisReward = 0;
|
|
|
|
endReward = paramCon.loseReward;
|
2022-11-28 22:54:08 +00:00
|
|
|
//thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
|
|
|
endTypeInt = (int)EndType.Lose;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// keep on keeping on!
|
2022-12-01 10:52:52 +00:00
|
|
|
// thisReward = (paramCon.inAreaReward * inArea) + getDistanceReward(nowDistance);
|
2022-12-03 08:42:51 +00:00
|
|
|
thisReward = 0;
|
|
|
|
endReward = 0;
|
2022-12-01 10:52:52 +00:00
|
|
|
targetEnemySpawnFinish = true;
|
2022-11-28 22:54:08 +00:00
|
|
|
endTypeInt = (int)EndType.Running;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (int)Targets.Defence:
|
|
|
|
//defence
|
2022-12-03 08:42:51 +00:00
|
|
|
// !!! DIDN't FINISH!!!
|
2022-11-28 22:54:08 +00:00
|
|
|
(nowDistance, inArea) = blockCont.getAgentTargetDistanceAndInside(AgentObj.transform.position);
|
|
|
|
envUICon.updateTargetGauge(blockCont.thisBlock.firebasesBelong, blockCont.thisBlock.belongMaxPoint);
|
|
|
|
if (leftTime <= 0 && blockCont.thisBlock.firebasesBelong >= 0f)
|
|
|
|
{
|
|
|
|
// win
|
|
|
|
// time over and the area still mine
|
2022-11-29 21:39:56 +00:00
|
|
|
thisReward = paramCon.defenceWinReward;
|
2022-11-28 22:54:08 +00:00
|
|
|
//thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
|
|
|
endTypeInt = (int)EndType.Win;
|
|
|
|
}
|
|
|
|
else if (blockCont.thisBlock.firebasesBelong <= blockCont.thisBlock.belongMaxPoint)
|
|
|
|
{
|
|
|
|
// lost area lose
|
|
|
|
thisReward = paramCon.loseReward;
|
|
|
|
//thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
|
|
|
endTypeInt = (int)EndType.Lose;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// keep on keeping on!
|
2022-12-01 10:52:52 +00:00
|
|
|
// thisReward = (paramCon.inAreaReward * inArea) + getDistanceReward(nowDistance);
|
2022-11-28 22:54:08 +00:00
|
|
|
endTypeInt = (int)EndType.Running;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//free kill
|
|
|
|
if (EnemyContainerObj.transform.childCount <= 0)
|
|
|
|
{
|
|
|
|
// win
|
|
|
|
//thisReward = paramCon.winReward + (paramCon.timeBonusPerSecReward * leftTime);
|
2022-12-03 08:42:51 +00:00
|
|
|
thisReward = 0;
|
|
|
|
endReward = paramCon.freeWinReward;
|
2022-11-28 22:54:08 +00:00
|
|
|
endTypeInt = (int)EndType.Win;
|
|
|
|
}
|
|
|
|
else if (Time.time - startTime >= paramCon.timeLimit)
|
|
|
|
{
|
|
|
|
// lose
|
|
|
|
//thisReward = paramCon.loseReward;
|
2022-12-03 08:42:51 +00:00
|
|
|
thisReward = 0;
|
|
|
|
endReward = paramCon.loseReward;
|
2022-11-28 22:54:08 +00:00
|
|
|
endTypeInt = (int)EndType.Lose;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// keep on keeping on!
|
2022-12-03 08:42:51 +00:00
|
|
|
thisReward = 0;
|
|
|
|
endReward = 0;
|
2022-11-28 22:54:08 +00:00
|
|
|
endTypeInt = (int)EndType.Running;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
envUICon.showResult(endTypeInt);
|
|
|
|
worldUICon.updateChart(targetTypeInt, endTypeInt);
|
2022-12-03 08:42:51 +00:00
|
|
|
return (endTypeInt, thisReward,endReward);
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 10:52:52 +00:00
|
|
|
// caulculate sceneReward if close to target then get great reward
|
2022-12-03 23:40:23 +00:00
|
|
|
public float getDistanceReward(float nowDistance,int inarea)
|
2022-12-01 10:52:52 +00:00
|
|
|
{
|
|
|
|
if (firstRewardFlag)
|
|
|
|
{
|
2022-12-07 21:24:51 +00:00
|
|
|
// first distance record
|
2022-12-01 10:52:52 +00:00
|
|
|
(lastDistance, _) = blockCont.getAgentTargetDistanceAndInside(AgentObj.transform.position);
|
|
|
|
firstRewardFlag = false;
|
|
|
|
}
|
|
|
|
float thisSceneReward = 0f;
|
2022-12-03 23:40:23 +00:00
|
|
|
if (inarea != 0)
|
|
|
|
{
|
2023-02-15 12:06:57 +00:00
|
|
|
// in area
|
2022-12-03 23:40:23 +00:00
|
|
|
thisSceneReward = paramCon.inAreaReward;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-07 08:29:47 +00:00
|
|
|
// out of area
|
|
|
|
// thisSceneReward = paramCon.distanceReward * Math.Clamp(lastDistance - nowDistance, 0, 100);
|
2022-12-03 23:40:23 +00:00
|
|
|
thisSceneReward = paramCon.distanceReward * (lastDistance - nowDistance);
|
|
|
|
}
|
2022-12-01 10:52:52 +00:00
|
|
|
lastDistance = nowDistance;
|
|
|
|
return thisSceneReward;
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
// calculate kill reward base on killed enemy's position
|
|
|
|
public float killReward(Vector3 enemyPosition)
|
|
|
|
{
|
|
|
|
float thisKillReward = 0f;
|
|
|
|
if (targetTypeInt == (int)Targets.Attack)
|
|
|
|
{
|
2022-11-29 21:39:56 +00:00
|
|
|
// attack mode
|
2022-11-28 22:54:08 +00:00
|
|
|
(_, int isInArea) = blockCont.thisBlock.getDist_inArea(enemyPosition);
|
|
|
|
if (isInArea == 1)
|
|
|
|
{
|
2022-11-29 21:39:56 +00:00
|
|
|
// kill in area enemy
|
|
|
|
thisKillReward = paramCon.killTargetEnemyReward;
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
thisKillReward = paramCon.killReward;
|
|
|
|
}
|
|
|
|
}
|
2022-12-01 10:52:52 +00:00
|
|
|
else if (targetTypeInt == (int)Targets.Free)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
2022-12-01 10:52:52 +00:00
|
|
|
// free mode hit
|
2022-11-29 21:39:56 +00:00
|
|
|
thisKillReward = paramCon.killTargetEnemyReward;
|
2022-12-01 10:52:52 +00:00
|
|
|
}
|
|
|
|
else
|
2022-11-29 21:39:56 +00:00
|
|
|
{
|
|
|
|
// goto & defence
|
2022-11-28 22:54:08 +00:00
|
|
|
thisKillReward = paramCon.killReward;
|
|
|
|
}
|
|
|
|
return thisKillReward;
|
|
|
|
}
|
2022-11-29 21:39:56 +00:00
|
|
|
|
|
|
|
// calculate hit reward base on killed enemy's position and now mode
|
2022-12-01 10:52:52 +00:00
|
|
|
public float hitEnemyReward(Vector3 enemyPosition)
|
2022-11-29 21:39:56 +00:00
|
|
|
{
|
|
|
|
float thisHitReward = 0f;
|
|
|
|
if (targetTypeInt == (int)Targets.Attack)
|
|
|
|
{
|
|
|
|
// attack mode
|
|
|
|
(_, int isInArea) = blockCont.thisBlock.getDist_inArea(enemyPosition);
|
|
|
|
if (isInArea == 1)
|
|
|
|
{
|
|
|
|
// hit in area enemy
|
|
|
|
thisHitReward = paramCon.hitTargetReward;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// hit not in area enemy
|
|
|
|
thisHitReward = paramCon.hitReward;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (targetTypeInt == (int)Targets.Free)
|
|
|
|
{
|
|
|
|
// free mode hit
|
|
|
|
thisHitReward = paramCon.hitTargetReward;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// goto & defence
|
|
|
|
thisHitReward = paramCon.hitReward;
|
|
|
|
}
|
|
|
|
return thisHitReward;
|
|
|
|
}
|
2022-12-03 23:40:23 +00:00
|
|
|
|
|
|
|
// get in area state
|
|
|
|
public int getInAreaState()
|
|
|
|
{
|
|
|
|
if(targetTypeInt == (int)Targets.Go)
|
|
|
|
{
|
|
|
|
return inArea;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|