Exemple #1
0
 // adds a building to the appropriate dictionary
 public void addBuilding(Tuple t, Building b)
 {
     if (b.GetType() == typeof(HeadQuarterBuilding))
     {
         HeadQuarterBuilding head = (HeadQuarterBuilding)b;
         hq           = head;
         hqLocation.x = t.x;
         hqLocation.y = t.y;
     }
     else if (b.GetType() == typeof(DecorativeBuilding))
     {
         DecorativeBuilding decBuilding = (DecorativeBuilding)b;
         decorativeBuildings.Add(t, decBuilding);
     }
     else if (b.GetType() == typeof(ResourceBuilding))
     {
         ResourceBuilding resBuilding = (ResourceBuilding)b;
         resourceBuildings.Add(t, resBuilding);
     }
     else if (b.GetType() == typeof(ResidenceBuilding))
     {
         ResidenceBuilding resBuilding = (ResidenceBuilding)b;
         residenceBuildings.Add(t, resBuilding);
     }
 }
Exemple #2
0
    // This method populates the save data with data from a json string
    public void loadJSON(String json)
    {
        Debug.Log(json);

        JSONArray loadedResourceBuildings;
        JSONArray loadedDecorativeBuildings;

        JSONNode data = JSON.Parse(json);

        userID         = data ["user_id"].AsInt;
        userLevel      = data ["level"].AsInt;
        userExperience = data ["experience"].AsInt;
        userPassword   = data ["password"];
        username       = data ["username"];
        hqLevel        = data ["headquarters_level"].AsInt;
        //change this back
        fire      = data ["fire"].AsInt;
        water     = data ["water"].AsInt;
        earth     = data ["earth"].AsInt;
        air       = data ["air"].AsInt;
        maxFire   = data ["max_fire"].AsInt;
        maxWater  = data ["max_water"].AsInt;
        maxEarth  = data ["max_earth"].AsInt;
        maxAir    = data ["max_air"].AsInt;
        fireEle   = data ["fire_ele"].AsInt;
        waterEle  = data ["water_ele"].AsInt;
        earthEle  = data ["earth_ele"].AsInt;
        airEle    = data ["air_ele"].AsInt;
        poofCount = data ["poof_count"].AsInt;

        // load the buildings
        loadedResourceBuildings   = data ["resource_buildings"].AsArray;
        loadedDecorativeBuildings = data ["decorative_buildings"].AsArray;

        hqLocation = new Tuple(data["hq_pos_x"].AsInt, data["hq_pos_y"].AsInt);
        //since array start at 0, lv 1-> index 0, lv 2 -> index 1
        hq = PrefabManager.prefabManager.headQuarterBuildings[hqLevel - 1];

        foreach (JSONNode building in loadedResourceBuildings)
        {
            int x = building["position_x"].AsInt;
            int y = building["position_y"].AsInt;

            // Retrieves a building from the resource buildings list
            if (PrefabManager.prefabManager == null)
            {
                Debug.LogError("[SaveState] Prefab manager is null");
            }

            ResourceBuilding newBuilding = PrefabManager.prefabManager.getResourceBuilding(building["building_info_id"].AsInt);

            newBuilding.created        = false;
            newBuilding.ID             = building["id"].AsInt;
            newBuilding.buildingInfoID = building["building_info_id"].AsInt;

            resourceBuildings.Add(new Tuple(x, y), newBuilding);
        }

        foreach (JSONNode building in loadedDecorativeBuildings)
        {
            int x = building["position_x"].AsInt;
            int y = building["position_y"].AsInt;

            // Retrieves a building from the resource buildings list
            Debug.Log("index: " + building["building_info_id"].AsInt);
            if (PrefabManager.prefabManager == null)
            {
                Debug.Log("prefab manager");
            }

            DecorativeBuilding newBuilding = PrefabManager.prefabManager.getDecorativeBuilding(building["building_info_id"].AsInt);

            Debug.Log(newBuilding.name + " has info id of: " + building["building_info_id"].AsInt);

            newBuilding.created        = false;
            newBuilding.ID             = building["id"].AsInt;
            newBuilding.buildingInfoID = building["building_info_id"].AsInt;

            decorativeBuildings.Add(new Tuple(x, y), newBuilding);
        }
    }