|
@ -6,68 +6,74 @@ using Networking.Server; |
|
|
public class blockSpawn : MonoBehaviour |
|
|
public class blockSpawn : MonoBehaviour |
|
|
{ |
|
|
{ |
|
|
[SerializeField] |
|
|
[SerializeField] |
|
|
public Inventory.Data[] spawnLogicList; |
|
|
|
|
|
|
|
|
public Inventory.Data[] StrongLogicList; |
|
|
|
|
|
public Inventory.Data[] NormalLogicList; |
|
|
|
|
|
public Inventory.Data[] WeakLogicList; |
|
|
|
|
|
Inventory.Data[] listtoUse; |
|
|
|
|
|
|
|
|
List<ClientData> ConnectedClients; |
|
|
List<ClientData> ConnectedClients; |
|
|
public ClientList clientDataList; |
|
|
public ClientList clientDataList; |
|
|
public Block[] SpawnBlocks; |
|
|
public Block[] SpawnBlocks; |
|
|
List<Vector3> spawnedLocations; |
|
|
List<Vector3> spawnedLocations; |
|
|
int min_z = -2, max_z = 2; |
|
|
|
|
|
Vector3 spawnposition = new Vector3(0, 0, 0); |
|
|
|
|
|
|
|
|
List<Block> possibleSpawnLocations; |
|
|
|
|
|
int spawnNumber = 2; |
|
|
|
|
|
|
|
|
void Awake() |
|
|
void Awake() |
|
|
{ |
|
|
{ |
|
|
ConnectedClients = clientDataList.ConnectedClients; |
|
|
ConnectedClients = clientDataList.ConnectedClients; |
|
|
spawnedLocations = new List<Vector3>(); |
|
|
spawnedLocations = new List<Vector3>(); |
|
|
|
|
|
possibleSpawnLocations = new List<Block>(); |
|
|
} |
|
|
} |
|
|
public void wakeup() |
|
|
public void wakeup() |
|
|
{ |
|
|
{ |
|
|
SpawnBlocks = FindObjectsOfType<Block>().Where(p => p.is_Walkable).ToArray(); |
|
|
|
|
|
|
|
|
SpawnBlocks = FindObjectsOfType<Block>().Where(p => p.isCollectableSpawnable).ToArray(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Spawn() |
|
|
public void Spawn() |
|
|
{ |
|
|
{ |
|
|
/* |
|
|
|
|
|
Get all player locations, get leader(biggest x position value) and min value |
|
|
|
|
|
+2 to each value, set as min and man in random.range() |
|
|
|
|
|
add locations to a list to ensure no duplicates |
|
|
|
|
|
check not over pit or hole |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Sort play locations so leader is first
|
|
|
ConnectedClients.Sort((b, a) => a.playerCharacter.transform.position.x.CompareTo(b.playerCharacter.transform.position.x)); |
|
|
ConnectedClients.Sort((b, a) => a.playerCharacter.transform.position.x.CompareTo(b.playerCharacter.transform.position.x)); |
|
|
int min_x = (int)ConnectedClients[ConnectedClients.Count - 1].playerCharacter.transform.position.x + 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//add two to each to set bounds
|
|
|
|
|
|
int min_x = (int)ConnectedClients[ConnectedClients.Count - 1].playerCharacter.transform.position.x + 3; |
|
|
int max_x = (int)ConnectedClients[0].playerCharacter.transform.position.x + 2; |
|
|
int max_x = (int)ConnectedClients[0].playerCharacter.transform.position.x + 2; |
|
|
|
|
|
|
|
|
for(int i = 0; i < 2; i++) |
|
|
|
|
|
|
|
|
//Check points within the bounds of players
|
|
|
|
|
|
foreach(Block point in SpawnBlocks) |
|
|
{ |
|
|
{ |
|
|
spawnposition = new Vector3(Random.Range(min_x, max_x), -0.5f, Random.Range(min_z, max_z)); |
|
|
|
|
|
checkLocation(spawnposition); |
|
|
|
|
|
|
|
|
if(point.transform.position.x > min_x && point.transform.position.x < max_x) |
|
|
|
|
|
{ |
|
|
|
|
|
possibleSpawnLocations.Add(point); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//pick a random value from those available, checks the location
|
|
|
|
|
|
//then removes it to remove the possibility of duplicates
|
|
|
|
|
|
while(spawnNumber > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
int choice = Random.Range(0, possibleSpawnLocations.Count - 1); |
|
|
|
|
|
bool spawned = checkLocation(possibleSpawnLocations[choice].transform.position); |
|
|
|
|
|
if (spawned == true) |
|
|
|
|
|
{ |
|
|
|
|
|
possibleSpawnLocations.RemoveAt(choice); |
|
|
|
|
|
spawnNumber--; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
spawnNumber = 2; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void checkLocation(Vector3 spawnposition) |
|
|
|
|
|
|
|
|
private bool checkLocation(Vector3 spawnposition) |
|
|
{ |
|
|
{ |
|
|
bool duplicate = checkDuplicatePosition(spawnposition); |
|
|
bool duplicate = checkDuplicatePosition(spawnposition); |
|
|
if (duplicate == false) |
|
|
if (duplicate == false) |
|
|
{ |
|
|
{ |
|
|
bool valid = checkValid(spawnposition); |
|
|
|
|
|
if (valid == true) |
|
|
|
|
|
{ |
|
|
|
|
|
spawnBlock(spawnposition); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
//Block clostest = Utility.minBy(SpawnBlocks, p => Vector3.Distance(p.transform.position, spawnposition));
|
|
|
|
|
|
//checkLocation(new Vector3(spawnposition.x, spawnposition.y + 1.5f, spawnposition.z));
|
|
|
|
|
|
Debug.Log("Fail one"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
spawnBlock(spawnposition); |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
//this needs to be changed
|
|
|
|
|
|
//Block clostest = Utility.minBy(SpawnBlocks, p => Vector3.Distance(p.transform.position, spawnposition));
|
|
|
|
|
|
//checkLocation(new Vector3(spawnposition.x, spawnposition.y + 1.5f, spawnposition.z));
|
|
|
|
|
|
Debug.Log("Fail two"); |
|
|
|
|
|
|
|
|
Debug.Log("Fail to spawn - duplicate positioning"); |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -86,30 +92,32 @@ public class blockSpawn : MonoBehaviour |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private bool checkValid(Vector3 spawnposition) |
|
|
|
|
|
{ |
|
|
|
|
|
//is over a walkable block
|
|
|
|
|
|
for (int i = 0; i < SpawnBlocks.Length; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if (SpawnBlocks[i].position.x == spawnposition.x && SpawnBlocks[i].position.z == spawnposition.z) |
|
|
|
|
|
{ |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void spawnBlock(Vector3 spawnposition) |
|
|
private void spawnBlock(Vector3 spawnposition) |
|
|
{ |
|
|
{ |
|
|
GameObject prefab = Resources.Load("Logic Block") as GameObject; |
|
|
GameObject prefab = Resources.Load("Logic Block") as GameObject; |
|
|
GameObject block = Instantiate(prefab); |
|
|
GameObject block = Instantiate(prefab); |
|
|
spawnposition.y += 1.5f; |
|
|
spawnposition.y += 1.5f; |
|
|
|
|
|
|
|
|
int number = (int)Random.Range(1.0f, spawnLogicList.Length); |
|
|
|
|
|
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.element = spawnLogicList[number].element; |
|
|
|
|
|
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.Count = spawnLogicList[number].Count; |
|
|
|
|
|
block.transform.position = spawnposition; |
|
|
block.transform.position = spawnposition; |
|
|
//Debug.Log("Instantiated new logic block: " + spawnLogicList[number].element + " at position: " + block.transform.position);
|
|
|
|
|
|
spawnedLocations.Add(spawnposition); |
|
|
spawnedLocations.Add(spawnposition); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void assignLogicBlock(GameObject block, float value) |
|
|
|
|
|
{ |
|
|
|
|
|
if(value > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
listtoUse = WeakLogicList; |
|
|
|
|
|
} |
|
|
|
|
|
else if (value < 0 && value > (-10)) |
|
|
|
|
|
{ |
|
|
|
|
|
listtoUse = NormalLogicList; |
|
|
|
|
|
} |
|
|
|
|
|
else if (value <= (-10)) |
|
|
|
|
|
{ |
|
|
|
|
|
listtoUse = StrongLogicList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int number = (int)Random.Range(0, listtoUse.Length-1); |
|
|
|
|
|
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.element = listtoUse[number].element; |
|
|
|
|
|
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.Count = listtoUse[number].Count; |
|
|
|
|
|
} |
|
|
} |
|
|
} |