Exemple #1
0
 void OnArrivedAtPlanet(Planet planet)
 {
     if (planet.GetOwnerIdAt(VTEUtil.GetTime()) == NetworkInstanceId.Invalid)
     {
         planet.Conquer(netId, 0);
     }
 }
Exemple #2
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);
            }
        }
    }
Exemple #3
0
 public void UserSaysSetTargetPlanet(Planet newPlanet)
 {
     print("SetTargetPlanet at " + VTEUtil.GetTime());
     SetSelected(false);
     CmdSetTargetPlanet(newPlanet.netId);
     // todo: feedback that click was registered
 }
Exemple #4
0
 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);
 }
Exemple #7
0
    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);
    }
Exemple #8
0
    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);
        }
    }
Exemple #9
0
 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;
         }
     }
 }
Exemple #10
0
    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);
    }
Exemple #11
0
    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);
    }
Exemple #12
0
    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);
    }
Exemple #14
0
 public Vector3 GetActualPosition()
 {
     return(GetPositionAt(VTEUtil.GetTime()).Value);
 }
Exemple #15
0
 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()));
 }
Exemple #18
0
 [ClientRpc] public void RpcAddDrones(int numDronestoAdd)
 {
     droneEvents.Add(new DroneEvent(GetOwnerIdAt(VTEUtil.GetTime()), GetNumDrones() + numDronestoAdd));
 }
Exemple #19
0
 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);
    }
Exemple #21
0
 void SelectTarget(GameObject origin)
 {
     VTEUtil.GetLocalPlayerComponent <Player> ().SendDrones(origin.GetComponent <Planet> (), this);
     Deselect();
 }