示例#1
0
    IEnumerator restartAddTroopsActions()
    {
        WWWForm wwwform = new WWWForm();

        wwwform.AddField("username", Globals.username);
        WWW request = new WWW("localhost:8080/myapp/world/troops/restartAdd", wwwform);

        yield return(request);

        AddTroopsCommand[] atcs = JsonMapper.ToObject <AddTroopsCommand[]>(request.text);
        foreach (AddTroopsCommand atc in atcs)
        {
            AddTroopsAction a = new AddTroopsAction(atc.bId);
            // Update values based on Time.DeltaTime
            a.overflowTroopsAdded += ((CurrentTime.currentTimeMillis() - atc.b.lastUpdated) / 1000) * Globals.timeCostPerTroop;
            int wholeUnitsAdded = (int)Mathf.Floor(a.overflowTroopsAdded);;
            if (wholeUnitsAdded > Mathf.Abs(a.b.unitsToAdd))
            {
                wholeUnitsAdded = Mathf.Abs(a.b.unitsToAdd);
            }
            if (wholeUnitsAdded > 0)
            {
                // Update base text wrappers
                a.b.units             += wholeUnitsAdded;
                a.overflowTroopsAdded -= Mathf.Abs(wholeUnitsAdded);
                a.b.unitsToAdd        -= wholeUnitsAdded;
            }

            addTroopsActions.Add(a);
        }
    }
示例#2
0
    IEnumerator finishAddTroops(AddTroopsAction a)
    {
        WWWForm wwwform = new WWWForm();

        wwwform.AddField("username", Globals.username);
        wwwform.AddField("baseId", a.b.baseId);
        WWW request = new WWW("localhost:8080/myapp/world/troops/finishBuy", wwwform);

        yield return(request);
    }