void OnArrivedAtPlanet(Planet planet) { if (planet.GetOwnerIdAt(VTEUtil.GetTime()) == NetworkInstanceId.Invalid) { planet.Conquer(netId, 0); } }
void OnMouseUpAsButton() { Moveable player = VTEUtil.GetLocalPlayerComponent <Moveable> (); if (player.selected) { player.UserSaysSetTargetPlanet(this); } else { GameObject origin = selection.GetSelected(); if (origin == null) { SelectOrigin(); } else if (origin == gameObject) { Deselect(); } else { SelectTarget(origin); } } }
public void UserSaysSetTargetPlanet(Planet newPlanet) { print("SetTargetPlanet at " + VTEUtil.GetTime()); SetSelected(false); CmdSetTargetPlanet(newPlanet.netId); // todo: feedback that click was registered }
public MovementEvent(Vector3 _startPos, Vector3 _tgtPos, Planet _tgtPlanet) { startPos = _startPos; tgtPos = _tgtPos; time = VTEUtil.GetTime(); tgtPlanet = _tgtPlanet; done = _startPos == _tgtPos; }
void GameOver(NetworkInstanceId winnerId) { UnityEngine.Assertions.Assert.IsTrue(isClient); bool youWin = winnerId == VTEUtil.GetLocalPlayerComponent <NetworkBehaviour> ().netId; gameOverText.text = youWin ? "You win!" : "You lose!"; gameOverText.color = youWin ? ownColor : enemyColor; }
public void GoTo(Vector3 _startPos, Vector3 _tgt) { tgtPos = _tgt; startPos = _startPos; startTime = VTEUtil.GetTime(); initialized = true; print("Send Decree from " + startPos + " to " + tgtPos); }
void EndMovement(int i) { MovementEvent movementEvent = movementEvents [i]; print("Arrive at " + VTEUtil.GetTime() + " after " + (VTEUtil.GetTime() - movementEvent.time)); print("Completing movement " + i.ToString() + " : " + movementEvent.ToString()); movementEvent.done = true; gameObject.SendMessage("OnArrivedAtPlanet", movementEvent.tgtPlanet); RpcEndMovement(i); }
IEnumerator UpdateDisplay() { while (true) { yield return(new WaitForSeconds(secsPerDisplayUpdate)); float distToPlayer = VTEUtil.GetDistToLocalPlayer(transform.position); float apparentTime = VTEUtil.GetApparentTime(distToPlayer); UpdateColor(apparentTime, distToPlayer); UpdateDroneDisplay(apparentTime); } }
void ConquerInitialPlanet() { foreach (GameObject planet in GameObject.FindGameObjectsWithTag("Planet")) { if (planet.transform.position == transform.position) { Planet closestPlanet = planet.GetComponent <Planet>(); Assert.IsTrue(closestPlanet.GetOwnerIdAt(VTEUtil.GetTime()) == NetworkInstanceId.Invalid); GetComponent <Moveable>().UserSaysSetTargetPlanet(closestPlanet); break; } } }
IEnumerator ExecuteDelayed(NetworkBehaviour commander, Planet planet) { Vector3 startPos = commander.transform.position; Vector3 tgtPos = planet.transform.position; float travelTime = Vector2.Distance(startPos, tgtPos) / DecreeCapsule.unitsPerSec; yield return(new WaitForSeconds(travelTime)); if (planet.GetOwnerIdAt(VTEUtil.GetTime()) == commander.netId) { Execute(); } Destroy(gameObject); }
void UpdateColor(float time, float distToPlayer) { Color baseColor = enemyColor; NetworkInstanceId ownerId = GetOwnerIdAt(time); if (ownerId == NetworkInstanceId.Invalid) { baseColor = neutralColor; } else if (ownerId == VTEUtil.GetLocalPlayerComponent <NetworkBehaviour> ().netId) { baseColor = playerColor; } material.color = baseColor * (1f - distToPlayer / maxDist); }
public float GetApparentTime() { float time = 0; for (int i = GetCurrentMovementEventIdx(); i >= 0; --i) { MovementEvent movementEvent = movementEvents [i]; time = VTEUtil.GetApparentTime(movementEvent.startPos, movementEvent.tgtPos, movementEvent.time, unitsPerSec, VTEUtil.GetLocalPlayerComponent <Moveable> ().GetActualPosition()); if (time >= 0) { break; } // else { // print ("Going back " + (1 + GetCurrentMovementEventIdx () - i).ToString ()); // } } return(time); }
void OnArrivedAtPlanet(Planet planet) { DroneEvent lastDroneChange = droneEvents [droneEvents.Count - 1]; print("OnArrivedAtPlanet fleet of size " + lastDroneChange.numDrones); if (planet.GetOwnerIdAt(VTEUtil.GetTime()) == lastDroneChange.ownerId) { planet.RpcAddDrones(lastDroneChange.numDrones); } else if (planet.GetNumDrones() < lastDroneChange.numDrones) { planet.Conquer(lastDroneChange.ownerId, lastDroneChange.numDrones - planet.GetNumDrones()); } else { planet.RpcAddDrones(-lastDroneChange.numDrones); } AddDroneEvent(lastDroneChange.ownerId, 0); }
public Vector3 GetActualPosition() { return(GetPositionAt(VTEUtil.GetTime()).Value); }
bool IsControlledByLocalPlayer() { return(VTEUtil.GetLocalPlayerComponent <NetworkBehaviour> ().netId == commanderId); }
public DroneEvent(NetworkInstanceId _ownerId, int newNumDrones) { ownerId = _ownerId; numDrones = newNumDrones; time = VTEUtil.GetTime(); }
NetworkInstanceId GetOwnerId(GameObject oPlanet) { return(oPlanet.GetComponent <Planet> ().GetOwnerIdAt(VTEUtil.GetTime())); }
[ClientRpc] public void RpcAddDrones(int numDronestoAdd) { droneEvents.Add(new DroneEvent(GetOwnerIdAt(VTEUtil.GetTime()), GetNumDrones() + numDronestoAdd)); }
public int GetNumDrones() { return(GetDronesAt(VTEUtil.GetTime())); }
void UpdateApparentPosition() { float time = VTEUtil.GetApparentTime(startPos, tgtPos, startTime, unitsPerSec, VTEUtil.GetLocalPlayerComponent <Moveable>().GetActualPosition()); transform.position = GetPositionAt(time); }
void SelectTarget(GameObject origin) { VTEUtil.GetLocalPlayerComponent <Player> ().SendDrones(origin.GetComponent <Planet> (), this); Deselect(); }