/// <summary> /// Attempts to look up a name in the BodyCatalog, then find the SkillFamily instance used for one of its slots (by slot enum type). Returns null on failure. /// </summary> /// <param name="bodyName">The body name to search for. Case sensitive.</param> /// <param name="slot">The skillslot name to search for.</param> /// <returns>The resultant SkillFamily if lookup was successful, null otherwise.</returns> public static SkillFamily FindSkillFamilyFromBody(string bodyName, SkillSlot slot) { var targetBodyIndex = BodyCatalog.FindBodyIndex(bodyName); if (targetBodyIndex == BodyIndex.None) { AncientScepterMain._logger.LogError($"FindSkillFamilyFromBody: Couldn't find body with name {bodyName}"); return(null); } var allSlots = BodyCatalog.GetBodyPrefabSkillSlots(targetBodyIndex); var skLoc = BodyCatalog.GetBodyPrefab(targetBodyIndex).GetComponentInChildren <SkillLocator>(); if (!skLoc) { AncientScepterMain._logger.LogError($"FindSkillFamilyFromBody: Body with name {bodyName} has no SkillLocator"); return(null); } foreach (var skillInstance in BodyCatalog.GetBodyPrefabSkillSlots(targetBodyIndex)) { var targetSlot = skLoc.FindSkillSlot(skillInstance); if (targetSlot == slot) { return(skillInstance.skillFamily); } } AncientScepterMain._logger.LogError($"FindSkillFamilyFromBody: Body with name {bodyName} has no skill in slot {slot}"); return(null); }
public void RandomizeLoadout() { if (!PreGameController.instance || !characterSelectController) { return; } var bodyIndex = SurvivorCatalog.GetBodyIndexFromSurvivorIndex(characterSelectController.selectedSurvivorIndex); var bodySkills = BodyCatalog.GetBodyPrefabSkillSlots(bodyIndex); var bodySkins = BodyCatalog.GetBodySkins(bodyIndex); var localUser = ((MPEventSystem)EventSystem.current).localUser; var loadout = new Loadout(); localUser.userProfile.CopyLoadout(loadout); for (var i = 0; i < bodySkills.Length; i++) { var skill = bodySkills[i]; var unlockedVariants = new List <uint>(); for (uint j = 0; j < skill.skillFamily.variants.Length; j++) { if (localUser.userProfile.HasUnlockable(skill.skillFamily.variants[j].unlockableDef)) { unlockedVariants.Add(j); } } loadout.bodyLoadoutManager.SetSkillVariant(bodyIndex, i, unlockedVariants[UnityEngine.Random.Range(0, unlockedVariants.Count)]); } var unlockedSkins = new List <uint>(); for (uint j = 0; j < bodySkins.Length; j++) { if (localUser.userProfile.HasUnlockable(bodySkins[j].unlockableDef)) { unlockedSkins.Add(j); } } loadout.bodyLoadoutManager.SetSkinIndex(bodyIndex, unlockedSkins[UnityEngine.Random.Range(0, unlockedSkins.Count)]); localUser.userProfile.SetLoadout(loadout); }
/// <summary> /// Attempts to look up a name in the BodyCatalog, then find the SkillFamily instance used for one of its slots (by index). Returns null on failure. /// </summary> /// <param name="bodyName">The body name to search for. Case sensitive.</param> /// <param name="slotIndex">The skillslot index to search for. Must be positive and within range of the target body's skillslot count.</param> /// <returns>The resultant SkillFamily if lookup was successful, null otherwise.</returns> public static SkillFamily FindSkillFamilyFromBody(string bodyName, int slotIndex) { var targetBodyIndex = BodyCatalog.FindBodyIndex(bodyName); if (targetBodyIndex == BodyIndex.None) { AncientScepterMain._logger.LogError($"FindSkillFamilyFromBody: Couldn't find body with name {bodyName}"); return(null); } var allSlots = BodyCatalog.GetBodyPrefabSkillSlots(targetBodyIndex); if (slotIndex < 0 || slotIndex > allSlots.Length) { AncientScepterMain._logger.LogError($"FindSkillFamilyFromBody: Skill slot index {slotIndex} is invalid for body with name {bodyName}"); return(null); } return(BodyCatalog.GetBodyPrefabSkillSlots(targetBodyIndex)[slotIndex].skillFamily); }
private void CharacterSelectController_OnNetworkUserLoadoutChanged(ILContext il) { void emittedAction(CharacterModel model, Loadout loadout, Int32 body) { GenericSkill[] skills = BodyCatalog.GetBodyPrefabSkillSlots(body); for (Int32 i = 0; i < skills.Length; i++) { UInt32 selectedSkillIndex = loadout.bodyLoadoutManager.GetSkillVariant(body, i); GenericSkill slot = skills[i]; for (Int32 j = 0; j < slot.skillFamily.variants.Length; j++) { SkillDef skillDef = slot.skillFamily.variants[j].skillDef; if (skillDef != null && skillDef is PassiveSkillDef) { var passiveSkillDef = skillDef as PassiveSkillDef; if (j == selectedSkillIndex) { passiveSkillDef.OnAssignDisplay(model); } else { passiveSkillDef.OnUnassignDisplay(model); } } } } } var c = new ILCursor(il); _ = c.GotoNext(MoveType.After, x => x.MatchCallOrCallvirt <RoR2.SkinDef>("Apply")); _ = c.Emit(OpCodes.Ldloc, 6); _ = c.Emit(OpCodes.Ldloc, 2); _ = c.Emit(OpCodes.Ldloc, 3); _ = c.EmitDelegate <Action <CharacterModel, Loadout, Int32> >(emittedAction); }