示例#1
0
    public void saveCurrentSettlement()
    {
        Debug.Log ("Saving");
        PlayerData newData = new PlayerData ();

        newData.scrap = scrap;
        newData.food = food;
        newData.power = power;
        newData.water = water;
        newData.popLimit = popLimit;
        newData.morale = morale;

        //newData.population = population;
        List<serialAgent> serialPopulation = new List<serialAgent>();

        foreach (GameObject agent in population) {
            serialAgent tempAgent = new serialAgent();

            tempAgent.agentId = agent.name;
            tempAgent.gender = agent.GetComponent<AgentLogic_07>().gender;
            tempAgent.myModelIndex = agent.GetComponent<AgentLogic_07>().modelIndex;
            tempAgent.photo = agent.GetComponent<AgentLogic_07>().portraitIndex;
            tempAgent.agentName = agent.GetComponent<AgentLogic_07>().firstLastName;
            tempAgent.xPos = agent.transform.position.x;
            tempAgent.yPos = agent.transform.position.y;
            tempAgent.zPos = agent.transform.position.z;
            tempAgent.health = agent.GetComponent<AgentLogic_07>().health;
            tempAgent.hunger = agent.GetComponent<AgentLogic_07>().hungerValue;
            tempAgent.agility = (int) agent.GetComponent<AgentAttributes>().agentAgility;
            tempAgent.perception = (int) agent.GetComponent<AgentAttributes>().agentPerception;
            tempAgent.strength = (int) agent.GetComponent<AgentAttributes>().agentStrength;

            tempAgent.state = agent.GetComponent<AgentLogic_07>().aState;
            tempAgent.job = agent.GetComponent<AgentLogic_07>().jobState;

            serialPopulation.Add (tempAgent);
        }

        List<serialBuilding> serialBuildingDatabase = new List<serialBuilding>();

        foreach (GameObject building in buildingDatabase) {
            serialBuilding tempBuilding = new serialBuilding();

            tempBuilding.bType = building.GetComponent<BuildingScript>().myType;
            Debug.Log (building.name);
            tempBuilding.xPos = building.transform.position.x;
            tempBuilding.yPos = building.transform.position.y;
            tempBuilding.zPos = building.transform.position.z;

            serialBuildingDatabase.Add(tempBuilding);
        }

        newData.settlementWeapons = weaponStash;
        newData.population = serialPopulation;
        newData.buildingDatabase = serialBuildingDatabase;

        PlayerDataManager.playerDataManager.writePlayerData (newData);
        Debug.Log ("SAVED");
    }
示例#2
0
    void results()
    {
        PlayerData myData = PlayerDataManager.playerDataManager.loadSaveData ();
        //updatescrap
        if (win && !rewardTriggered) {
            Debug.Log ("win was called");

            winUI.sprite = winSprite;

            myData.scrap += scrapRate;
            GameObject newSObj = (GameObject) Instantiate ( scrapObj, Vector3.zero, Quaternion.identity );
            newSObj.transform.SetParent ( rewardBucket.transform );
            newSObj.transform.localScale = new Vector3( 1, 1, 1);
            newSObj.GetComponent<Reward_Scrap>().scrapVal.text = ""+scrapRate;

            for (int i = 0; i < recruitRate; i++) {
                serialAgent newAgent = new serialAgent ();
                //Gender
                string[] genderArray = new string[2] {
                    "Male",
                    "Female"
                };
                int randomGender = Random.Range (0, (genderArray.Length));
                newAgent.agentId = "NEWAGENT";
                newAgent.gender = genderArray [randomGender];
                newAgent.agentName = generateNewAgentName (newAgent.gender);
                newAgent.xPos = 0;
                newAgent.yPos = 0;
                newAgent.zPos = 0;

                newAgent.health = 60;
                newAgent.hunger = 80;

                newAgent.strength = randomStat ();
                newAgent.perception = randomStat ();
                newAgent.agility = randomStat ();

                newAgent.state = AgentLogic_07.agentState.Wandering;
                newAgent.job = AgentLogic_07.jobSubState.Default;
                if( newAgent.gender == "Male" ){
                    newAgent.photo = (int) Random.Range (0,settlerObj.GetComponent<Reward_Person>().maleSprites.Count-1);
                    newAgent.myModelIndex = (int) Random.Range (0,6);
                } else {
                    newAgent.photo = (int) Random.Range (0,settlerObj.GetComponent<Reward_Person>().femaleSprites.Count-1);
                    newAgent.myModelIndex = (int) Random.Range (0,11);
                }

                GameObject newWObj = (GameObject) Instantiate ( settlerObj, Vector3.zero, Quaternion.identity );
                newWObj.transform.SetParent ( rewardBucket.transform );
                newWObj.transform.localScale = new Vector3( 1, 1, 1);
                newWObj.GetComponent<Reward_Person>().agentName.text = newAgent.agentName;
                newWObj.GetComponent<Reward_Person>().strVal.text = ""+newAgent.strength;
                newWObj.GetComponent<Reward_Person>().perVal.text = ""+ newAgent.perception;
                newWObj.GetComponent<Reward_Person>().aglVal.text = ""+newAgent.agility;
                if( newAgent.gender == "Male"){
                    newWObj.GetComponent<Reward_Person>().agentImg.sprite = newWObj.GetComponent<Reward_Person>().maleSprites[newAgent.photo];
                } else {
                    newWObj.GetComponent<Reward_Person>().agentImg.sprite = newWObj.GetComponent<Reward_Person>().femaleSprites[newAgent.photo];
                }

                myData.population.Add (newAgent);
                myData.populationCount++;
                Debug.Log ("newAgent: " + newAgent.agentName + " was added");
            }

            for (int i = 0; i < weaponRate; i++) {
                serialWeapon newWeapon = new serialWeapon ();

                string gunName = _nameGenerator.GetAdjective () + " " + _nameGenerator.GetVerbs ();
                gunName = gunName.ToUpper ();

                newWeapon.weaponName = gunName;
                newWeapon.weaponId = "" + ((int)Random.Range (1000, 9999));
                int dice = (int)rollDice (1, 7);

                if (dice <= 3) {
                    newWeapon.weaponType = "Handgun";
                    newWeapon.range = 8 + (int)rollDice (-2, 2);
                    newWeapon.accuracy = 0.95f + rollDice (-0.3f, 0.3f);
                    newWeapon.damageModifier = 6 + (int)rollDice (-3, 3);
                    newWeapon.rangeModifier = 0.1f;
                    newWeapon.soundRange = newWeapon.range - 3 + (newWeapon.damageModifier / 2);
                } else if (dice <= 5) {
                    newWeapon.weaponType = "Shotgun";
                    newWeapon.range = 6 + (int)rollDice (-2, 2);
                    newWeapon.accuracy = 0.95f + rollDice (-0.2f, 0.2f);
                    newWeapon.damageModifier = 6 + (int)rollDice (-3, 6);
                    newWeapon.rangeModifier = 0.2f;
                    newWeapon.soundRange = newWeapon.range - 3 + (newWeapon.damageModifier / 2);
                } else {
                    newWeapon.weaponType = "Rifle";
                    newWeapon.range = 13 + (int)rollDice (-3, 3);
                    newWeapon.accuracy = 0.75f + rollDice (-0.2f, 0.2f);
                    newWeapon.damageModifier = 6 + (int)rollDice (-2, 4);
                    newWeapon.rangeModifier = 0.05f;
                    newWeapon.soundRange = newWeapon.range - 3 + (newWeapon.damageModifier / 2);
                }

                GameObject newWObj = (GameObject) Instantiate ( weaponObj, Vector3.zero, Quaternion.identity );
                newWObj.transform.SetParent ( rewardBucket.transform );
                newWObj.transform.localScale = new Vector3( 1, 1, 1);
                newWObj.GetComponent<Reward_Weapon>().weaponName.text = newWeapon.weaponName;
                newWObj.GetComponent<Reward_Weapon>().weaponType.text = "["+newWeapon.weaponType+"]";
                newWObj.GetComponent<Reward_Weapon>().dmgMod.text = "+"+newWeapon.damageModifier;
                newWObj.GetComponent<Reward_Weapon>().rngMod.text = ""+ newWeapon.range;
                newWObj.GetComponent<Reward_Weapon>().accMod.text = newWeapon.accuracy*10 + "%";
                myData.settlementWeapons.Add (newWeapon);

                rewardTriggered = true;

            }
        } else if(!rewardTriggered) {
            winUI.sprite = loseSprite;
            if( winUI.gameObject.GetComponentInChildren<ScrollRect>().gameObject.activeSelf )
                winUI.gameObject.GetComponentInChildren<ScrollRect>().gameObject.SetActive(false);
        }

        foreach (serialAgent sA in myData.currentParty) {
            for( int i = myData.population.Count - 1; i >=0; i--){
                if( sA.agentId == myData.population[i].agentId ){
                    Debug.Log ( myData.population.Count );
                    myData.population.Remove ( myData.population[i] );
                    Debug.Log ( sA.agentName + " was removed " + myData.population[i].agentName  );
                    Debug.Log ( myData.population.Count );
                }
            }
        }
        foreach (Unit fU in _gameController.folk) {
            foreach( serialAgent sA in myData.currentParty ){
                if( sA.agentId == fU.agentId ){
                    sA.health = fU.health * 10;
                }
            }
        }
        foreach (serialAgent sA in myData.currentParty) {
            if( sA.health > 0 ){
                Debug.Log (sA.agentName + "readded to population");
                myData.population.Add ( sA );
            }
        }
        myData.currentParty.Clear ();

        PlayerDataManager.playerDataManager.writePlayerData (myData);
        //loadBuild ();
    }