public void CmdRequestJoinAsPeer(string myName) { //A client has asked to become a new peer. hl.Peer peer = new hl.Peer(); hl.uIds++; peer.uId = hl.uIds; peer.myName = myName; peer.team = ServerSideLoop.DetermineBestTeam(peer.uId);//Only called on the server. Auto picks team 1 or 2 peer.teamPlayerNum = ServerSideLoop.DetermineTeamPlacement(peer.uId); Resources.InitResources(peer); hl.peers.Add(peer); RpcGrantJoinAsPeer(peer); //tell all the clients, including the one that just joined, all the peer info. hl.Peer[] list = new hl.Peer[hl.peers.Count]; for (int i = 0; i < list.Length; i++) { list[i] = hl.peers[i]; } RpcSendAllPeers(list); //Also update everyone's global info hl.globalInfo.currentPlayers++; RpcBroadcastGlobalInfo(hl.globalInfo); }
void Update() { UpdateNetworkDisplay(); popText.text = "Pop: " + displayPop + "/" + displayMaxPop; //"Pop: " + xa.pop + "/" + xa.maxPop; moneyText.text = "Gold: " + displayMoney + " (+" + displayMoneyIncrease + ")"; muntionsText.text = "Muntions: " + displayMunitions + " (+" + displayMunitionsIncrease + ")"; fuelText.text = "Fuel: " + displayFuel + " (+" + displayFuelIncrease + ")"; debugText.text = xa.debugStr; if (hl.globalInfo != null) { if (hl.globalInfo.currentLevel != null) { debugText3.text = "CurrentLevel: " + hl.globalInfo.currentLevel; } else { debugText3.text = "CurrentLevel is null"; } } else { debugText3.text = "GlobalInfo is null"; } debugText3.text += "\nLocal uId: " + hl.local_uId; string s = "Peer: "; if (hl.local_uId != -1) { s += "" + hl.local_uId + "\n"; hl.Peer peer = hl.GetPeerForUID(hl.local_uId); if (peer != null) { s += "Team: " + peer.team; } else { s += "Team: Peer not found"; } } else { s += " Peer is -1"; } teamText.text = s; debugText2.text = PrintPeers().ToString(); chatInput.text = ChatScript.inputStr; chatText.text = ChatScript.chatStr; svTimeText.text = "sv: " + hl.svTime + "\ncl: " + hl.clTime; }
public static void UpdateResources(hl.Peer peer) //Called only on the server, clients get this information via the tick { if (hl.svTime >= (peer.resourceUpdateTimeSet + peer.resourceUpdateDelay)) { peer.resourceUpdateTimeSet = hl.svTime; peer.money += peer.moneyIncrease; peer.munitions += peer.munitionsIncrease; peer.fuel += peer.fuelIncrease; } }
public static void SubtractCost(Type type, hl.Peer peer) //Subtracts the cost of this object from this peer { int[] cost = GetCostForType(type); if (cost == null) { return; } peer.pop += cost[0]; peer.money -= cost[1]; peer.munitions -= cost[2]; peer.fuel -= cost[3]; }
public void RpcGrantJoinAsPeer(hl.Peer peer) { if (isLocalPlayer) { if (hl.peers == null) { hl.peers = new List <hl.Peer>(); } hl.peers.Add(peer); hl.local_uId = peer.uId; } }
public void CmdRequestChangeTeam(int clId, int desiredTeam) //Happens on the server { //A client has asked to change team hl.Peer peer = hl.GetPeerForUID(clId); if (peer != null) { //Grant team change request peer.team = desiredTeam; } //Update everyone's peers (not added yet) //RpcUpdateTeam(clId, desiredTeam); }
public static void InitResources(hl.Peer peer) { peer.pop = 0; peer.maxPop = 10; peer.money = 300; peer.moneyIncrease = 1; peer.munitions = 0; peer.munitionsIncrease = 0; peer.fuel = 0; peer.fuelIncrease = 1; peer.resourceUpdateDelay = 1; peer.resourceUpdateTimeSet = 1; }
public void CmdRequestJoinAsPeer(string myName) { //A client has asked to become a new peer. hl.Peer peer = new hl.Peer(); hl.uIds++; peer.uId = hl.uIds; peer.myName = myName; RpcGrantJoinAsPeer(peer); //Also update everyone's global info hl.globalInfo.currentPlayers++; RpcBroadcastGlobalInfo(hl.globalInfo); }
public static void ApplyPeerFuel(int uId, int fuel, int fuelIncrease) { hl.Peer p = hl.GetPeerForUID(uId); if (p == null) { return; } p.fuel = fuel; p.fuelIncrease = fuelIncrease; UIController.displayFuel = fuel; UIController.displayFuelIncrease = fuelIncrease; }
public static void ApplyPeerMuntions(int uId, int muntions, int muntionsIncrease) { hl.Peer p = hl.GetPeerForUID(uId); if (p == null) { return; } p.munitions = muntions; p.munitionsIncrease = muntionsIncrease; UIController.displayMunitions = muntions; UIController.displayMunitionsIncrease = muntionsIncrease; }
public static void ApplyPeerMoney(int uId, int money, int moneyIncrease) { hl.Peer p = hl.GetPeerForUID(uId); if (p == null) { return; } p.money = money; p.moneyIncrease = moneyIncrease; UIController.displayMoney = money; UIController.displayMoneyIncrease = moneyIncrease; }
public static void ApplyPeerPop(int uId, int pop, int maxPop) { hl.Peer p = hl.GetPeerForUID(uId); if (p == null) { return; } p.pop = pop; p.maxPop = maxPop; UIController.displayPop = pop; UIController.displayMaxPop = maxPop; }
public static bool CheckCost(Type type, hl.Peer peer) //Returns false if this peer can't afford it { int[] cost = GetCostForType(type); if (cost == null) { return(false); } if (peer.pop + cost[0] <= peer.maxPop && peer.money >= cost[1] && peer.munitions >= cost[2] && peer.fuel >= cost[3]) { return(true); } return(false); }
public void RpcGrantJoinAsPeer(hl.Peer peer) { if (isLocalPlayer) { if (hl.peers == null) { hl.peers = new List <hl.Peer>(); } //check that this peer doesn't already exist int result = hl.GetIndexForUID(peer.uId); if (result == -1) //Doesn't exist here yet { hl.peers.Add(peer); Debug.Log("Just added Peer" + peer.uId + " to hl.peers, count: " + hl.peers.Count); } //At this point, it either exists here already, or was just added. Since this is //the local player, set hl.local_uId hl.local_uId = peer.uId; } }
public static void CreateObj(Type type, Vector3 pos, Vector3 ang, int clId, int uId) { //Create the go hl.Peer peer = hl.GetPeerForUID(clId); Obj obj = new Obj(); obj.type = type; obj.go = Instantiate(PrefabLibrary.GetPrefabForType(type)); obj.go.transform.position = pos; obj.go.transform.localEulerAngles = ang; obj.ownedByClId = clId; obj.uId = uId; obj.goal = pos; switch (type) { case Type.Marine: obj.isUnit = true; //This obj is a unit, and can be selected. //create selectionCircle obj.selectionCircle = (GameObject)Instantiate(xa.de.selectionCirclePrefab, pos, new Quaternion(0, 0, 0, 0)); obj.selectionCircle.transform.parent = obj.go.transform; obj.selectionCircle.transform.localPosition = Vector3.zero; obj.selectionCircle.SetActive(false); obj.textMesh = obj.go.GetComponentInChildren <TextMesh>(); obj.textMesh.text = ""; //uId: " + obj.uId + "\nClId: " + obj.ownedByClId; obj.go.GetComponent <Info>().uId = obj.uId; obj.animator = obj.go.GetComponent <Info>().animator; int[] cost = GetCostForType(type); obj.popCost = cost[0]; obj.moneyCost = cost[1]; obj.muntionsCost = cost[2]; obj.fuelCost = cost[3]; obj.priorityValue = 1; obj.health = 100; break; } objs.Add(obj); }
public void CmdCreateObj(int clId, Vector3 pos, int objType) //Sends an order from the client to the server { Debug.Log("Trying to buy " + (ObjFuncs.Type)objType); //Can the player afford this object? hl.Peer p = hl.GetPeerForUID(clId); if (p == null) { Debug.Log("Peer (" + clId + ") was null, failed to buy " + (ObjFuncs.Type)objType); return; } //Make sure the peer still exists if (!ObjFuncs.CheckCost((ObjFuncs.Type)objType, p)) { Debug.Log("Couldnt afford " + (ObjFuncs.Type)objType); return; } //Make sure they can afford this obj ObjFuncs.SubtractCost((ObjFuncs.Type)objType, p); //Spend the money to buy this object hl.uIds++; //Only ever do this on the server int uId = hl.uIds; ChatScript.ChatLocally("CreateObj on Sv. uId: " + uId); RpcCreateObj(clId, pos, objType, uId); }