/// <summary> /// Gives the specified upgrades to a FirstPersonMover /// </summary> /// <param name="Target"></param> /// <param name="Upgrades"></param> public static void Give(FirstPersonMover Target, UpgradeDescription[] Upgrades) { for (int i = 0; i < Upgrades.Length; i++) { Give(Target, Upgrades[i]); } }
public static void OnFPMDie(FirstPersonMover __instance) { ModdingZoneHooks.ModZoneLogger.Debug($"{__instance} died."); //TODO Future - see if we can transpile FPM#dropWeaponsOrKillPlayerFromDamagedBodyPart EventBus.Instance.Post(new CharacterDeathEvent(__instance)); }
void FindPlayer() { if (_player != null) { return; } float lastTime = Time.time + 5f; WaitForThenCall.Schedule(delegate { if (Time.time >= lastTime) { return; } FirstPersonMover player = CharacterTracker.Instance.GetPlayer(); if (player.gameObject.GetComponent <PhysicalVRPlayer>() != null) { throw new Exception("There was already a PhysicalVrPlayer on the player"); } _player = player.gameObject.AddComponent <PhysicalVRPlayer>(); }, delegate { if (Time.time >= lastTime) { return(true); } FirstPersonMover player = CharacterTracker.Instance.GetPlayer(); return(player != null && player.IsAttachedAndAlive()); }); }
static void validateHasRestrictionsForCharacter(FirstPersonMover firstPersonMover) { if (!_characterInputRestrictions.ContainsKey(firstPersonMover)) { throw new KeyNotFoundException("The given FirstPersonMover does not exist in the input restrictions dictionary, check if a character is defined with the HasAnyRestrictions(FirstPersonMover) method"); } }
void Update() { Camera main = Camera.main; if (main == null) { FirstPersonMover player = CharacterTracker.Instance.GetPlayerRobot(); if (player == null) { return; } main = player.GetPlayerCamera(); if (main == null) { return; } } if (main.GetComponent <DebugLineDrawer>() == null) { main.gameObject.AddComponent <DebugLineDrawer>(); } StartCoroutine(runAtEndOfFrame()); }
/// <summary> /// Sets the <see cref="InputRestrictions.AttackKeyDown"/> on the given <see cref="FirstPersonMover"/> /// </summary> /// <param name="firstPersonMover">The <see cref="FirstPersonMover"/> to set the input restrictions of</param> /// <param name="inputRestrictions">The <see cref="InputRestrictions"/> to set</param> public static void SetInputRestrictions(FirstPersonMover firstPersonMover, InputRestrictions inputRestrictions) { validateInputRestrictions(inputRestrictions); _characterInputRestrictions[firstPersonMover] = inputRestrictions; filterDictionary(); }
/// <summary> /// Calls this method on all mods /// </summary> /// <param name="owner"></param> /// <param name="upgrades"></param> public override void AfterUpgradesRefreshed(FirstPersonMover owner, UpgradeCollection upgrades) { List <Mod> mods = ModsManager.Instance.GetAllLoadedMods(); for (int i = 0; i < mods.Count; i++) { mods[i].AfterUpgradesRefreshed(owner, upgrades); } }
/// <summary> /// Calls this method on all mods /// </summary> /// <param name="me"></param> public override void OnFirstPersonMoverUpdate(FirstPersonMover me) { List <Mod> mods = ModsManager.Instance.GetAllLoadedMods(); for (int i = 0; i < mods.Count; i++) { mods[i].OnFirstPersonMoverUpdate(me); } }
/// <summary> /// Removes all input restrictions defined in the given bitfield from a <see cref="FirstPersonMover"/>, if no input restrictions remain, the <see cref="FirstPersonMover"/> will be removed from the input restrictions dictionary /// </summary> /// <param name="firstPersonMover">The <see cref="FirstPersonMover"/> to remove the restrictions from</param> /// <param name="inputRestriction">A bitfield of input restrictions to remove</param> public static void RemoveRestriction(FirstPersonMover firstPersonMover, InputRestrictions inputRestriction) { validateHasRestrictionsForCharacter(firstPersonMover); validateInputRestrictions(inputRestriction); _characterInputRestrictions[firstPersonMover] &= ~inputRestriction; // Remove the restriction(s) from the bitfield filterDictionary(); }
/// <summary> /// Moved from <see cref="CalledFromInjections"/>, checks for <see langword="null"/> and calls <see cref="AfterUpgradesRefreshed(FirstPersonMover, UpgradeCollection)"/> /// </summary> /// <param name="firstPersonMover"></param> public static void AfterUpgradesRefreshed(FirstPersonMover firstPersonMover) { if (firstPersonMover == null || firstPersonMover.gameObject == null || !firstPersonMover.IsAlive() || firstPersonMover.GetCharacterModel() == null) { return; } ModsManager.Instance.PassOnMod.AfterUpgradesRefreshed(firstPersonMover, firstPersonMover.GetComponent <UpgradeCollection>()); }
/// <summary> /// Returns the <see cref="FirstPersonMover"/>s currently equipped weapon, will return null if the <see cref="CharacterModel"/> is <see langword="null"/>, or the currently equipped <see cref="WeaponType"/> is <see cref="WeaponType.None"/> /// </summary> /// <param name="firstPersonMover"></param> /// <returns></returns> public static WeaponModel GetEquippedWeaponModel(this FirstPersonMover firstPersonMover) { if (!firstPersonMover.HasCharacterModel() || firstPersonMover.GetEquippedWeaponType() == WeaponType.None) { return(null); } WeaponType equippedWeaponType = firstPersonMover.GetEquippedWeaponType(); return(firstPersonMover.GetCharacterModel().GetWeaponModel(equippedWeaponType)); }
/// <summary> /// Returns if the given <see cref="FirstPersonMover"/> has all of the input restrictions in the given <see cref="InputRestrictions"/> bitfield /// </summary> /// <param name="firstPersonMover">The <see cref="FirstPersonMover"/> to check</param> /// <param name="inputRestriction">A bitfield of input restrictions to check for</param> /// <returns></returns> public static bool HasRestrictions(FirstPersonMover firstPersonMover, InputRestrictions inputRestriction) { validateInputRestrictions(inputRestriction); if (!_characterInputRestrictions.ContainsKey(firstPersonMover)) { return(false); } return((_characterInputRestrictions[firstPersonMover] & inputRestriction) == inputRestriction); }
public static void FirstPersonMover_RefreshUpgrades_Prefix(FirstPersonMover __instance) { if (__instance == null || __instance.gameObject == null || !__instance.IsAlive() || __instance.GetCharacterModel() == null) { return; } UpgradeCollection upgrade = __instance.GetComponent <UpgradeCollection>(); ModsManager.Instance.PassOnMod.OnUpgradesRefreshed(__instance, upgrade); }
/// <summary> /// Gives the specified upgrades to a FirstPersonMover /// </summary> /// <param name="Target"></param> /// <param name="Upgrades"></param> /// <param name="Levels"></param> public static void Give(FirstPersonMover Target, Dictionary <UpgradeType, int> upgrades) { List <UpgradeType> upgradeTypes = EnumTools.GetValues <UpgradeType>(); for (int i = 0; i < upgradeTypes.Count; i++) { if (upgrades.TryGetValue(upgradeTypes[i], out int level)) { Give(Target, GetUpgradeDescriptionFromTypeAndLevel(upgradeTypes[i], level)); } } }
/// <summary> /// Adds an input restriction on the given <see cref="FirstPersonMover"/> /// </summary> /// <param name="firstPersonMover">The target to add a restriction to</param> /// <param name="inputRestriction">A bitfield of input restrictions to apply</param> public static void AddRestriction(FirstPersonMover firstPersonMover, InputRestrictions inputRestriction) { validateInputRestrictions(inputRestriction); if (!_characterInputRestrictions.ContainsKey(firstPersonMover)) { _characterInputRestrictions.Add(firstPersonMover, 0); } _characterInputRestrictions[firstPersonMover] |= inputRestriction; firstPersonMover.AddDeathListener(filterDictionary); }
/// <summary> /// Creates an arrow and makes it fly in the given direction /// </summary> /// <param name="Owner">The FirstPersonMover that should be considered the owner of the arrow</param> /// <param name="StartPosition"></param> /// <param name="MoveDir"></param> /// <param name="fireSpreadDefinition"></param> /// <param name="BladeWidth"></param> /// <param name="MakeFlyBySound"></param> /// <param name="RotationZ"></param> /// <returns>The fired arrow</returns> public static ArrowProjectile CreateFlaming(FirstPersonMover Owner, Vector3 StartPosition, Vector3 MoveDir, FireSpreadDefinition fireSpreadDefinition, float BladeWidth = 1f, bool MakeFlyBySound = false, float RotationZ = 0f) { if (Owner == null) { return(null); } ArrowProjectile arrow = Create(Owner, StartPosition, MoveDir, BladeWidth, MakeFlyBySound, RotationZ); arrow.SetOnFire(fireSpreadDefinition); return(arrow); }
/// <summary> /// Creates an arrow and makes it fly in the given direction /// </summary> /// <param name="Owner">The FirstPersonMover that should be considered the owner of the arrow</param> /// <param name="StartPosition"></param> /// <param name="MoveDir"></param> /// <param name="BladeWidth"></param> /// <param name="MakeFlyBySound"></param> /// <param name="RotationZ"></param> /// <returns>The fired arrow</returns> public static ArrowProjectile Create(FirstPersonMover Owner, Vector3 StartPosition, Vector3 MoveDir, float BladeWidth = 1f, bool MakeFlyBySound = false, float RotationZ = 0f) { if (Owner == null) { return(null); } ArrowProjectile arrow = ProjectileManager.Instance.CreateInactiveArrow(false); arrow.transform.SetParent(LevelSpecificWorldRoot.Instance.transform, true); arrow.SetBladeWidth(BladeWidth); arrow.StartFlying(StartPosition, MoveDir, MakeFlyBySound, Owner, false, BoltNetwork.serverFrame, RotationZ); return(arrow); }
/// <summary> /// Calls this method on all mods /// </summary> /// <param name="me"></param> /// <param name="upgrades"></param> public override void OnUpgradesRefreshed(FirstPersonMover me, UpgradeCollection upgrades) { FirstPersonMover firstPersonMover = me.GetComponent <FirstPersonMover>(); if (!firstPersonMover.IsAlive() || firstPersonMover.GetCharacterModel() == null) { return; } List <Mod> mods = ModsManager.Instance.GetAllLoadedMods(); for (int i = 0; i < mods.Count; i++) { mods[i].OnUpgradesRefreshed(me, upgrades); } }
void Awake() { _timeToActivateInput = Time.time + 0.5f; _owner = GetComponent <FirstPersonMover>(); if (_owner == null) { throw new MissingComponentException("VR player must be on the same GameObject as a FirstPersonMover"); } _head = _owner.GetBodyPart(MechBodyPartType.Head).transform.parent.gameObject; _head.SetActive(false); _rightHand = _owner.GetBodyPart(MechBodyPartType.RightArm).transform.parent.gameObject; _leftHand = _owner.GetBodyPart(MechBodyPartType.LeftArm).transform.parent.gameObject; _owner.AddDeathListener(OnPlayerDeath); if (_rightHand == null) { throw new Exception("Right hand is null"); } if (_leftHand == null) { throw new Exception("Left hand is null"); } Transform armLowerL = _leftHand.transform.parent; Transform armUpperL = armLowerL.parent; Transform armLowerR = _rightHand.transform.parent; Transform armUpperR = armLowerR.parent; Transform ArmsRoot = armUpperL.parent; _leftArmIK = armUpperL.gameObject.AddComponent <LimbIK>(); _leftArmIK.solver.SetChain(armUpperL, armLowerL, _leftHand.transform, ArmsRoot); _rightArmIK = armUpperR.gameObject.AddComponent <LimbIK>(); _rightArmIK.solver.SetChain(armUpperR, armLowerR, _rightHand.transform, ArmsRoot); VRManager.Instance.Player.Scale = transform.localScale.y * 1.4f; }
/// <summary> /// Gets a WeaponModel from the given FirstPersonMover from the given WeaponType (Returns null if the FirstPersonMover does not have the weapon) /// </summary> /// <param name="firstPersonMover"></param> /// <param name="type"></param> /// <returns></returns> public static WeaponModel GetWeaponModelFromType(FirstPersonMover firstPersonMover, WeaponType type) { if (type == WeaponType.None || firstPersonMover == null) { return(null); } WeaponModel[] weaponModels = firstPersonMover.GetCharacterModel().WeaponModels; for (int i = 0; i < weaponModels.Length; i++) { if (weaponModels[i].WeaponType == type) { return(weaponModels[i]); } } return(null); }
/// <summary> /// Gives the specified upgrade to a FirstPersonMover /// </summary> /// <param name="Target"></param> /// <param name="Upgrade"></param> public static void Give(FirstPersonMover Target, UpgradeDescription Upgrade) { if (Target == null) { return; } if (Target.IsMainPlayer()) { GameDataManager.Instance.SetUpgradeLevel(Upgrade.UpgradeType, Upgrade.Level); UpgradeDescription upgrade = UpgradeManager.Instance.GetUpgrade(Upgrade.UpgradeType, Upgrade.Level); GlobalEventManager.Instance.Dispatch("UpgradeCompleted", upgrade); } else { UpgradeCollection upgradeCollection = Target.gameObject.GetComponent <UpgradeCollection>(); if (upgradeCollection == null) { debug.Log("Failed to give upgrade '" + Upgrade.UpgradeName + "' (Level: " + Upgrade.Level + ") to " + Target.CharacterName + " (UpgradeCollection is null)", Color.red); return; } UpgradeTypeAndLevel upgradeToGive = new UpgradeTypeAndLevel { UpgradeType = Upgrade.UpgradeType, Level = Upgrade.Level }; List <UpgradeTypeAndLevel> upgrades = ((PreconfiguredUpgradeCollection)upgradeCollection).Upgrades.ToList(); upgrades.Add(upgradeToGive); ((PreconfiguredUpgradeCollection)upgradeCollection).Upgrades = upgrades.ToArray(); ((PreconfiguredUpgradeCollection)upgradeCollection).InitializeUpgrades(); Target.RefreshUpgrades(); } Target.SetUpgradesNeedsRefreshing(); }
/// <summary> /// Gives the specified upgrade to a <see cref="FirstPersonMover"/> /// </summary> /// <param name="firstPersonMover"></param> /// <param name="upgradeType">The <see cref="UpgradeType"/> to give</param> /// <param name="level">The level of the upgrade</param> /// <exception cref="ArgumentNullException">If the given <see cref="FirstPersonMover"/> is <see langword="null"/></exception> /// <exception cref="ArgumentException">If the given <see cref="UpgradeType"/> and level has not been defined in <see cref="UpgradeManager.UpgradeDescriptions"/></exception> public static void GiveUpgrade(this FirstPersonMover firstPersonMover, UpgradeType upgradeType, int level) { if (firstPersonMover == null) { throw new ArgumentNullException(nameof(firstPersonMover)); } if (UpgradeManager.Instance.GetUpgrade(upgradeType, level) == null) { throw new ArgumentException("The upgrade with type \"" + upgradeType + "\" and level " + level + " has not been defined!"); } if (firstPersonMover.GetComponent <PreconfiguredUpgradeCollection>() != null) // If we are giving an upgrade to an enemy/ally { PreconfiguredUpgradeCollection upgradeCollection = firstPersonMover.GetComponent <PreconfiguredUpgradeCollection>(); UpgradeTypeAndLevel upgradeToGive = new UpgradeTypeAndLevel { UpgradeType = upgradeType, Level = level }; List <UpgradeTypeAndLevel> upgrades = upgradeCollection.Upgrades.ToList(); upgrades.Add(upgradeToGive); upgradeCollection.Upgrades = upgrades.ToArray(); upgradeCollection.InitializeUpgrades(); firstPersonMover.RefreshUpgrades(); } else if (firstPersonMover.GetComponent <PlayerUpgradeCollection>() != null) // If we are giving it to the player { GameDataManager.Instance.SetUpgradeLevel(upgradeType, level); // Set the level of the upgrade to the given one UpgradeDescription upgrade = UpgradeManager.Instance.GetUpgrade(upgradeType, level); GlobalEventManager.Instance.Dispatch(GlobalEvents.UpgradeCompleted, upgrade); } firstPersonMover.SetUpgradesNeedsRefreshing(); }
/// <summary> /// Gives the specified <see cref="UpgradeDescription"/> to a <see cref="FirstPersonMover"/> /// </summary> /// <param name="firstPersonMover"></param> /// <param name="Upgrade">The upgrade to give</param> public static void GiveUpgrade(this FirstPersonMover firstPersonMover, UpgradeDescription Upgrade) { firstPersonMover.GiveUpgrade(Upgrade.UpgradeType, Upgrade.Level); }
/// <summary> /// Gets the <see cref="InputRestrictions"/> for the given <see cref="FirstPersonMover"/>, if the <see cref="FirstPersonMover"/> is not in the input restrictions dictionary, a <see cref="KeyNotFoundException"/> is thrown, to avoid this, consider calling <see cref="HasAnyRestrictions(FirstPersonMover)"/> to check if any input restrictions are defined for a specific <see cref="FirstPersonMover"/> /// </summary> /// <param name="firstPersonMover">The <see cref="FirstPersonMover"/> to attempt to get the <see cref="InputRestrictions"/> of</param> /// <returns></returns> public static InputRestrictions GetInputRestrictions(FirstPersonMover firstPersonMover) { validateHasRestrictionsForCharacter(firstPersonMover); return(_characterInputRestrictions[firstPersonMover]); }
/// <summary> /// Initializes a new instance of the <see cref="WaitForCharacterModelInitialization"/> instruction /// </summary> /// <param name="firstPersonMover">The <see cref="FirstPersonMover"/> to check</param> public WaitForCharacterModelInitialization(FirstPersonMover firstPersonMover) { _firstPersonMover = firstPersonMover; }
public UpgradesAboutToBeRefreshedEvent(FirstPersonMover fpm) { FirstPersonMover = fpm; CanBeCancelled = false; }
/// <summary> /// Called at the end of <see cref="FirstPersonMover.RefreshUpgrades"/> /// </summary> /// <param name="owner"></param> /// <param name="upgrades">The <see cref="UpgradeCollection"/> on the <see cref="FirstPersonMover"/> object</param> public virtual void AfterUpgradesRefreshed(FirstPersonMover owner, UpgradeCollection upgrades) { }
/// <summary> /// Gives the specified upgrade to a FirstPersonMover /// </summary> /// <param name="Target"></param> /// <param name="Upgrade"></param> /// <param name="Level"></param> public static void Give(FirstPersonMover Target, UpgradeType Upgrade, int Level) { Give(Target, GetUpgradeDescriptionFromTypeAndLevel(Upgrade, Level)); }
// public string HarmonyID => "com.Mod-Bot.Mod." + ModInfo.UniqueID; /// <summary> /// Called in <see cref="Character.Start"/> if the <see cref="Character"/> is of type <see cref="FirstPersonMover"/> /// </summary> /// <param name="firstPersonMover">The <see cref="FirstPersonMover"/> that was spawned</param> public virtual void OnFirstPersonMoverSpawned(FirstPersonMover firstPersonMover) { }
/// <summary> /// Called in <see cref="Character.Update"/> if the <see cref="Character"/> is of type <see cref="FirstPersonMover"/> /// </summary> /// <param name="firstPersonMover">The <see cref="FirstPersonMover"/> that was updated</param> public virtual void OnFirstPersonMoverUpdate(FirstPersonMover firstPersonMover) { }