Exemple #1
0
        public void executeCommands(AreaGroup group)
        {
            foreach (SpawnCommand s in commands)
            {
                Point spawnedAt = null;
                if (s.getSpawnSpecification().Equals(SpawnAreaTypeSpecification.LOCAL))
                {
                    spawnedAt = MasterDriver.Instance.CurrentArea.position;
                    MasterDriver.Instance.CurrentArea.executeSpawnCommand(s);
                }
                else
                {
                    spawnedAt = group.executeSpawnCommand(s);
                }

                WorldMap.AddStarAt(spawnedAt.x, spawnedAt.y, this.description);
                spawnLocations.Add(spawnedAt);
            }
        }
Exemple #2
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);
            }
        }
    }