149 lines
3.5 KiB
C#
149 lines
3.5 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class TournamentPlayer : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public TournamentManager tournamentManager;
|
|
|
|
public bool isAi = true;
|
|
|
|
public int playerId = 1;
|
|
|
|
public string playerName = "Tournament Player";
|
|
|
|
public int aiLevel = 5;
|
|
|
|
public bool isLocalPlayer;
|
|
|
|
public float catchTime = 10f;
|
|
|
|
public float catchTimeDiff = 0.25f;
|
|
|
|
private float nextCatchTime;
|
|
|
|
public float currentMultiScore;
|
|
|
|
public int sortedPosition;
|
|
|
|
public List<TournamentManager.TournamentFish> fishList = new List<TournamentManager.TournamentFish>();
|
|
|
|
public float[] aiLevels = new float[10];
|
|
|
|
public void Initialize()
|
|
{
|
|
tournamentManager = GameController.Instance.tournamentManager;
|
|
catchTime = aiLevels[aiLevel];
|
|
if (isAi)
|
|
{
|
|
SetNextCatchTime();
|
|
}
|
|
}
|
|
|
|
public void MakeUpdate()
|
|
{
|
|
if (isAi)
|
|
{
|
|
nextCatchTime -= Time.deltaTime;
|
|
if (nextCatchTime <= 0f)
|
|
{
|
|
CatchRandomFish();
|
|
SetNextCatchTime();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetNextCatchTime()
|
|
{
|
|
nextCatchTime = Random.Range(catchTime - catchTime * catchTimeDiff, catchTime + catchTime * catchTimeDiff);
|
|
}
|
|
|
|
public void CatchRandomFish()
|
|
{
|
|
if (tournamentManager.tournamentActive && !tournamentManager.tournamentStarted)
|
|
{
|
|
TournamentManager.TournamentFish tournamentFish = tournamentManager.tournamentSpecies[Random.Range(0, tournamentManager.tournamentSpecies.Count)];
|
|
TournamentManager.TournamentFish tournamentFish2 = new TournamentManager.TournamentFish();
|
|
tournamentFish2.species = tournamentFish.species;
|
|
tournamentFish2.weight = Random.Range(tournamentFish.weightMinMax.x, tournamentFish.weightMinMax.y);
|
|
tournamentFish2.weight += (float)(aiLevel - 5) * tournamentFish.weight * 0.01f;
|
|
fishList.Add(tournamentFish2);
|
|
tournamentManager.PlayerCatchFish(playerId, tournamentFish2);
|
|
}
|
|
}
|
|
|
|
public void CatchFish(Fish fish)
|
|
{
|
|
if (tournamentManager.tournamentActive && tournamentManager.tournamentStarted)
|
|
{
|
|
TournamentManager.TournamentFish tournamentFish = TournamentManager.FishToTournamentFish(fish);
|
|
fishList.Add(tournamentFish);
|
|
tournamentManager.PlayerCatchFish(playerId, tournamentFish);
|
|
}
|
|
}
|
|
|
|
public float GetScore()
|
|
{
|
|
if (!tournamentManager.gameController.isMultiplayer || this == tournamentManager.gameController.fishingPlayer.tournamentPlayer)
|
|
{
|
|
TournamentManager.TournamentDefinition.GoalType goalType = tournamentManager.tournamentDefinition.goalType;
|
|
float result = 0f;
|
|
switch (goalType)
|
|
{
|
|
case TournamentManager.TournamentDefinition.GoalType.AMOUNT:
|
|
result = GetFishAmount();
|
|
break;
|
|
case TournamentManager.TournamentDefinition.GoalType.WEIGHT_SUM:
|
|
result = GetFishWeight();
|
|
break;
|
|
case TournamentManager.TournamentDefinition.GoalType.WEIGHT_MAX:
|
|
result = GetMaxFishWeight();
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
return currentMultiScore;
|
|
}
|
|
|
|
public void SetScore(TournamentManager.TournamentDefinition.GoalType goalType, float newScore)
|
|
{
|
|
currentMultiScore = newScore;
|
|
}
|
|
|
|
public int GetFishAmount()
|
|
{
|
|
return fishList.Count;
|
|
}
|
|
|
|
public float GetFishWeight()
|
|
{
|
|
float num = 0f;
|
|
for (int i = 0; i < fishList.Count; i++)
|
|
{
|
|
num += fishList[i].weight;
|
|
}
|
|
return num;
|
|
}
|
|
|
|
public float GetMaxFishWeight()
|
|
{
|
|
TournamentManager.TournamentFish tournamentFish = null;
|
|
for (int i = 0; i < fishList.Count; i++)
|
|
{
|
|
if (tournamentFish == null)
|
|
{
|
|
tournamentFish = fishList[i];
|
|
}
|
|
else if (fishList[i].weight > tournamentFish.weight)
|
|
{
|
|
tournamentFish = fishList[i];
|
|
}
|
|
}
|
|
if (tournamentFish != null)
|
|
{
|
|
return tournamentFish.weight;
|
|
}
|
|
return 0f;
|
|
}
|
|
}
|