////////////////////////////////////////// /// TrainPerk() ////////////////////////////////////////// public void TrainPerk(string i_strKey) { // get the perk's data PerkData dataPerk = IDL_Perks.GetData(i_strKey); if (dataPerk != null) { // make sure the player can train the perk and the perk has another level to train int nLevel = GetPerkLevel(i_strKey); int nCost = dataPerk.GetCostToTrain(nLevel); int nXP = GetCurrentXP(); if (nCost > 0 && nXP >= nCost) { // update player's xp int nNewXP = nXP - nCost; SetProperty("XP", nNewXP); // update the perk's level Dictionary <string, int> dictPerks = GetPropertyValue <Dictionary <string, int> >("Perks"); dictPerks[i_strKey] = nLevel + 1; SetProperty("Perks", dictPerks); Save(); } } }
////////////////////////////////////////// /// CanTrainPerk() /// Returns whether or not the player /// can train the incoming perk. ////////////////////////////////////////// public bool CanTrainPerk(string i_strKey) { // get the player's perks Dictionary <string, int> dictPerks = GetPropertyValue <Dictionary <string, int> >("Perks"); // get the perk data PerkData dataPerk = IDL_Perks.GetData(i_strKey); if (dataPerk != null) { // go through all the requirements and make sure the player has the perks at that level foreach (KeyValuePair <string, int> req in dataPerk.PerkRequirements) { // the player doesn't even have required perk? fail if (dictPerks.ContainsKey(req.Key) == false) { return(false); } // the player has the required perk but not at the required level? fail if (dictPerks[req.Key] < req.Value) { return(false); } } } return(true); }