You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

116 lines
2.8 KiB

using ExitGames.Client.Photon;
using Photon.Pun;
using Photon.Realtime;
using System.Collections.Generic;
using UnityEngine;
public class Selection : MonoBehaviour {
public static Selection Instance {
get; set;
}
public float selectionTime;
[Header("Costs")]
public int maxPoints;
public List<CircuitCost> circuitCosts;
public bool HasStarted;
private List<CircuitAmount> circuitAmounts;
public int CurrentPoints {
get {
int currentSummedCost = 0;
foreach (CircuitAmount circuitAmount in circuitAmounts) {
int individualCost = circuitCosts.Find(x => x.type.Equals(circuitAmount.type)).cost;
int circuitAmountCost = individualCost * circuitAmount.amount;
currentSummedCost += circuitAmountCost;
}
return maxPoints - currentSummedCost;
}
}
void Awake() {
Instance = this;
circuitAmounts = new List<CircuitAmount>() {
new CircuitAmount(CircuitType.Basic, 0),
new CircuitAmount(CircuitType.Capacitor, 0),
new CircuitAmount(CircuitType.Generator, 0),
new CircuitAmount(CircuitType.Speeder, 0)
};
if (!PhotonNetwork.IsConnected) {
PhotonNetwork.OfflineMode = true;
PhotonNetwork.CreateRoom("development");
PhotonNetwork.LocalPlayer.SetCustomProperties(new Hashtable() {
["IsReady"] = true,
["ColorIndex"] = Random.Range(1, 9)
});
StartSelection();
}
}
void Update() {
if (HasStarted) {
selectionTime -= Time.deltaTime;
if (selectionTime <= 0)
SelectionDone();
}
}
public bool CanAdd(CircuitType type) {
return CurrentPoints >= circuitCosts.Find(c => c.type.Equals(type)).cost;
}
public bool AddCircuitToSelection(CircuitType type, out int newCount) {
int cost = circuitCosts.Find(x => x.type.Equals(type)).cost;
newCount = 0;
if (CurrentPoints - cost < 0) {
//No
return false;
} else {
//Yes
CircuitAmount circuitAmount = circuitAmounts.Find(x => x.type.Equals(type));
circuitAmount.amount++;
newCount = circuitAmount.amount;
Debug.Log("Added circuit to selection. Current Points: " + CurrentPoints);
return true;
}
}
public bool RemoveCircuitFromSelection(CircuitType type, out int newCount) {
CircuitAmount circuitAmount = circuitAmounts.Find(x => x.type.Equals(type));
newCount = 0;
if (circuitAmount.amount == 0) {
//No
return false;
} else {
//Yes
circuitAmount.amount--;
newCount = circuitAmount.amount;
Debug.Log("Removed circuit from selection. Current Points: " + CurrentPoints);
return true;
}
}
//Entry point
public void StartSelection() {
Debug.Log("Selection countdown has started!");
HasStarted = true;
}
public void SelectionDone() {
HasStarted = false;
GameManager manager = GameManager.Instance;
manager.circuitAmounts = circuitAmounts;
manager.restPoints = CurrentPoints;
PhotonNetwork.LoadLevel(2);
}
}