Advertisement
kanagara

Untitled

Nov 8th, 2019
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.27 KB | None | 0 0
  1.   private void GenerateChallenges()
  2.     {
  3.         var playerClassDataManager = FindObjectOfType<PlayerClassDataManager>();
  4.         foreach (var unlockable in unlockables)
  5.         {
  6.             var newChallenge = CreateInstance<Challenge>();
  7.             var playerClass = playerClassDataManager.GetClassByUnlockable(unlockable.unlockable, out var index, out var array, out var type);
  8.             //If index is -1 that means that unlockable wasn't found in any playerclass which should never happen
  9.             if (index == -1) continue;
  10.  
  11.             newChallenge.rewards = new List<Reward>();
  12.             foreach (var reward in challenge.rewards)
  13.             {
  14.                 Reward rwrd = (reward is PlayerXpReward ? CreateInstance<PlayerXpReward>() :  CreateInstance<ArchetypeXpReward>());
  15.                 newChallenge.rewards.Add(rwrd);
  16.             }
  17.            
  18.             //If the unlockable should unlock next, create a new reward for that.
  19.             if (unlockable.shouldUnlockNext && index < array.Length - 1)
  20.             {
  21.                 var reward = CreateInstance<UnlockReward>();
  22.                 reward.playerClass = playerClass;
  23.                 reward.unlockable = array[index + 1];
  24.                 reward.name = "Reward_" + reward.unlockable.name;
  25.                 newChallenge.rewards.Add(reward);
  26.             }
  27.            
  28.             newChallenge.prerequisites = new List<Prerequisite>();
  29.            
  30.             if (challenge.prerequisites != null)
  31.                 newChallenge.prerequisites.AddRange(challenge.prerequisites);
  32.                
  33.             //If the unlockable can't be used without the previous one being unlocked, create a new reward prerequisite.
  34.             if (unlockable.shouldPreviousBeUnlocked && index > 0)
  35.             {
  36.                 var prerequisite = CreateInstance<UnlockablePrerequisite>();
  37.                 prerequisite.data = playerClass;
  38.                 prerequisite.unlockable = array[index - 1];
  39.                 newChallenge.prerequisites.Add(prerequisite);
  40.             }
  41.             //"Shultze Primary I"
  42.             newChallenge.ChallengeName = GenerateChallengeName(playerClass, index, type);
  43.             newChallenge.data = playerClass;
  44.             newChallenge.tasks = new List<Task>();
  45.             foreach (var task in challenge.tasks)
  46.             {
  47.                 var t = CreateInstance<Task>();
  48.                 t.conditions = new List<Condition>();
  49.                 foreach (var condition in task.conditions)
  50.                 {
  51.                     t.conditions.Add(condition);
  52.                 }
  53.                 newChallenge.tasks.Add(t);
  54.             }
  55.             //And finally create a condition for using the current weapon.
  56.             if(unlockable.unlockable is PlayerUnlockableWeapon unlockableWeapon)
  57.                 foreach (var task in newChallenge.tasks)
  58.                 {
  59.                     var usingWeaponRestriction = CreateInstance<UsingWeaponRestriction>();
  60.                     usingWeaponRestriction.type = WeaponRestrictionType.UsingWeapon;
  61.                     usingWeaponRestriction.weapons = unlockableWeapon.Weapon.id;
  62.                     usingWeaponRestriction.name = "Using weapon " + usingWeaponRestriction.weapons;
  63.                     task.conditions.Add(usingWeaponRestriction);
  64.                 }
  65.            
  66.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement