Example #1
0
    public void load(int file)
    {
        CityHelp.helpMode = -3;
        Debug.Log("LOADING : " + file);
        SavePackage package;

        try {
            FileStream fs;
            if (file == 1)
            {
                fs = new FileStream(saveGameFile1, FileMode.Open);
            }
            else if (file == 2)
            {
                fs = new FileStream(saveGameFile2, FileMode.Open);
            }
            else if (file == 4)
            {
                fs = new FileStream(tmpSaveGameFile, FileMode.Open);
            }
            else
            {
                fs = new FileStream(saveGameFile3, FileMode.Open);
            }
            package = SavePackage.ParseFrom(fs);
            fs.Flush();
            fs.Close();
        } catch (IOException excep) {
            IOException dummy = excep;
            log("IO ERROR: COULD NOT LOAD GAME DATA");
            return;
        }

        //WORLD GENERATION
        currentMap = new Map(package.Seed);

        //QUESTS
        List <QuestSave> questSaves = new List <QuestSave> ();

        questSaves.AddRange(package.QuestDataList);
        questListener = new QuestListener(questSaves);

        //CONVERSATIONS
        List <ConversationSave> conversationSaves = new List <ConversationSave> ();

        conversationSaves.AddRange(package.ConversationDataList);
        LoadResources.Instance.setConversationData(conversationSaves);

        //PLAYER STATUS
        player.transform.position = new Vector3(0.0f, player.transform.position.y, 0.0f);         //global shift
        currentArea = currentMap.getArea(package.Player.PlayerPosition.AreaX, package.Player.PlayerPosition.AreaY);
        player.GetComponentInChildren <Player> ().setPlayerStatus(package.Player);
        currentArea.getGroup().generateAreas();

        Transform camera = getCamera();

        camera.position = new Vector3(package.Player.PlayerPosition.LocalX, camera.position.y, package.Player.PlayerPosition.LocalY);
        Quaternion rotation = camera.rotation;

        rotation.eulerAngles = new Vector3(0.0f, package.Player.Rotation, 0.0f);
        camera.rotation      = rotation;

        //SPAWNED OBJECTS
        List <SpawnedObject> spawnedObjects = new List <SpawnedObject> ();

        spawnedObjects.AddRange(package.SpawnedObjectsList);
        foreach (SpawnedObject o in spawnedObjects)
        {
            GlobalPosition pos  = o.ObjectPosition;
            Area           area = currentMap.getArea(pos.AreaX, pos.AreaY);
            GameObject     obj;

            WorldMap.AddStarAt(pos.AreaX, pos.AreaY, o.Description);

            if (o.HasEnemyAttributes)
            {
                obj = (GameObject)getEnemyFromProtobuf(o.ObjectData);
                obj = (GameObject)GameObject.Instantiate(obj);
                obj.GetComponent <Enemy>().name = o.ObjectData.Name;
                //TODO set enemy health
            }
            else
            {
                obj = (GameObject)getItemFromProtobuf(o.ObjectData);
                ItemDropObject drop      = LoadResources.Instance.CommonItemDrop.GetComponent <ItemDropObject>();
                GameObject     newDrop   = (GameObject)GameObject.Instantiate(drop.gameObject);
                GameObject     newObject = (GameObject)GameObject.Instantiate(obj);
                newObject.SetActive(false);
                newObject.GetComponent <Item>().name = o.ObjectData.Type;

                if (o.ObjectData.HasItemInformation && o.ObjectData.ItemInformation.HasSaveVersion && newObject.GetComponent <Weapon>() != null)
                {
                    newObject.GetComponent <Weapon>().version = o.ObjectData.ItemInformation.SaveVersion;
                }

                newDrop.GetComponent <ItemDropObject>().item = newObject;
                obj = newDrop;
            }

            obj.transform.position = new Vector3(pos.LocalX, obj.transform.position.y, pos.LocalY);

            if (area.basicRoom != null)
            {
                area.basicRoom.addSpawnedObject(obj);
            }

            if (area != currentArea)
            {
                obj.SetActive(false);
            }
        }
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        if (bossLevel)
        {
            return;
        }

        if (generateBuilderDataOnLaunch)
        {
            generateBuilderData();
        }

        bool atCity = false;

        if (loadGame && PersistentInfo.saveFile != 0)
        {
            load(PersistentInfo.saveFile);
            loadGame = false;
        }
        else
        {
            questListener = new QuestListener();

            currentMap  = new Map();
            currentArea = currentMap.getArea(4, 4);
            try
            {
                currentArea.getGroup().generateAreas();
                Point spawnPoint = currentArea.defaultSpawn;

                player.transform.position = new Vector3(spawnPoint.x, player.transform.position.y, spawnPoint.y);
            }
            catch (System.Exception e)
            {
                //nah...
                atCity = true;
            }
            currentMap.debugDisplayMap();
            questListener.initializeQuests();
        }
        FollowPlayer.Travel();
        currentArea.showArea();

        if (atCity)
        {
            int  i = 0;
            Tile currentPortal;
            do
            {
                currentPortal = currentArea.portals[i];
                i++;
            } while (currentPortal.gameObject.GetComponent <Portal>().dir != Direction.DOWN);
            player.transform.GetChild(0).transform.localPosition = Vector3.zero;
            player.transform.GetChild(1).transform.localPosition = Vector3.zero;
            player.transform.position = new Vector3(currentPortal.transform.position.x, player.transform.position.y, currentPortal.transform.position.z - 8);
            Player.inCity             = true;
        }

        clearer = new QuestStarClearer();
        new BossStarter();

//        Debug.Log("Startup time: " + Time.realtimeSinceStartup);
    }