Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void GenerateChallenges()
- {
- var playerClassDataManager = FindObjectOfType<PlayerClassDataManager>();
- foreach (var unlockable in unlockables)
- {
- var newChallenge = CreateInstance<Challenge>();
- var playerClass = playerClassDataManager.GetClassByUnlockable(unlockable.unlockable, out var index, out var array, out var type);
- //If index is -1 that means that unlockable wasn't found in any playerclass which should never happen
- if (index == -1) continue;
- newChallenge.rewards = new List<Reward>();
- foreach (var reward in challenge.rewards)
- {
- Reward rwrd = (reward is PlayerXpReward ? CreateInstance<PlayerXpReward>() : CreateInstance<ArchetypeXpReward>());
- newChallenge.rewards.Add(rwrd);
- }
- //If the unlockable should unlock next, create a new reward for that.
- if (unlockable.shouldUnlockNext && index < array.Length - 1)
- {
- var reward = CreateInstance<UnlockReward>();
- reward.playerClass = playerClass;
- reward.unlockable = array[index + 1];
- reward.name = "Reward_" + reward.unlockable.name;
- newChallenge.rewards.Add(reward);
- }
- newChallenge.prerequisites = new List<Prerequisite>();
- if (challenge.prerequisites != null)
- newChallenge.prerequisites.AddRange(challenge.prerequisites);
- //If the unlockable can't be used without the previous one being unlocked, create a new reward prerequisite.
- if (unlockable.shouldPreviousBeUnlocked && index > 0)
- {
- var prerequisite = CreateInstance<UnlockablePrerequisite>();
- prerequisite.data = playerClass;
- prerequisite.unlockable = array[index - 1];
- newChallenge.prerequisites.Add(prerequisite);
- }
- //"Shultze Primary I"
- newChallenge.ChallengeName = GenerateChallengeName(playerClass, index, type);
- newChallenge.data = playerClass;
- newChallenge.tasks = new List<Task>();
- foreach (var task in challenge.tasks)
- {
- var t = CreateInstance<Task>();
- t.conditions = new List<Condition>();
- foreach (var condition in task.conditions)
- {
- t.conditions.Add(condition);
- }
- newChallenge.tasks.Add(t);
- }
- //And finally create a condition for using the current weapon.
- if(unlockable.unlockable is PlayerUnlockableWeapon unlockableWeapon)
- foreach (var task in newChallenge.tasks)
- {
- var usingWeaponRestriction = CreateInstance<UsingWeaponRestriction>();
- usingWeaponRestriction.type = WeaponRestrictionType.UsingWeapon;
- usingWeaponRestriction.weapons = unlockableWeapon.Weapon.id;
- usingWeaponRestriction.name = "Using weapon " + usingWeaponRestriction.weapons;
- task.conditions.Add(usingWeaponRestriction);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement