public void attack(HealthComponent healthComponent) { AnimateAttack(); healthComponent.GetHit(damage); attacking = true; UIManager.setInfoChanged(true); }
public static void levelUp(int levels, HealthComponent health, AttackComponent attack) { health.MaxHealth *= healthMultiplier; health.CurrentHealth *= healthMultiplier; attack.Damage *= damageMultiplier; attack.StunTime *= stunTimeMultiplier; }
void Awake() { _equipment = GetComponent<EquipmentComponent>(); _movement = GetComponent<MovementComponent>(); _health = GetComponent<HealthComponent>(); _skelAnim = GetComponent<SkeletonAnimation>(); _health.armorValue = _equipment.GetArmor(); }
void SendDamage(HealthComponent healtComp) { healtComp.SendMessage("TakeDamage", GetWeaponDamage(), SendMessageOptions.DontRequireReceiver); if (gameObject.tag == "EnemyProjectile") { Destroy(gameObject); } }
public Entity ReplaceHealth(int newHealth) { HealthComponent component; if (hasHealth) { WillRemoveComponent(ComponentIds.Health); component = health; } else { component = new HealthComponent(); } component.health = newHealth; return ReplaceComponent(ComponentIds.Health, component); }
public TestOldMan(int playerNumber = 0) { mPlayerNumber = playerNumber; mPosition = new PositionComponent(this, 100, 100); mRotation = new RotationComponent(this); //mRenderable = new RenderableComponent(this); mPhysics = new PhysicsComponent(this); mAnimated = new AnimatedComponent(this); mInput = new InputComponent(this); mController = new PlayerControllerComponent(this); mHealth = new HealthComponent(this, 100.0f); }
void Start() { healthComponent = new HealthComponent(); maxMana = 0; healthComponent.MaxHealth = 1000; currentMana = 0; healthComponent.CurrentHealth = 999; characterName = "Item Shop"; className = "Shop building"; picture = Resources.Load<Sprite>("Icons/shop"); selectedCircle = this.gameObject.transform.FindChild("SelectedCircle").gameObject; buttons = new GameObject[4,3]; buttons[0,0] = instantiateButton("Icons/potion_health", "+50 health", false, applyHealthPotion, 50L); }
public TestNess(int playerNumber = 0) { mPlayerNumber = playerNumber; mPosition = new PositionComponent(this, 100, 100); mRotation = new RotationComponent(this); //mRenderable = new RenderableComponent(this); mPhysics = new PhysicsComponent(this); mAnimated = new AnimatedComponent(this); mInput = new InputComponent(this); mController = new PlayerControllerComponent(this); //switch (mPlayerNumber) //{ // case 0: // // Player 0 means no human control. // break; // case 1: // mInput.PlayerIndex = PlayerIndex.One; // break; // case 2: // mInput.PlayerIndex = PlayerIndex.Two; // break; // case 3: // mInput.PlayerIndex = PlayerIndex.Three; // break; // case 4: // mInput.PlayerIndex = PlayerIndex.Four; // break; //} mHealth = new HealthComponent(this, 100.0f); }
protected void ApplyDamage(HealthComponent healthComponent) { healthComponent.ApplyDamage(DamagePerHit); }
// PRAGMA MARK - Public // PRAGMA MARK - Protected protected void Awake() { _healthComponent = GetComponent<HealthComponent>(); _gunController = GetComponentsInChildren<GunController>()[0]; _rigidbody = GetComponent<Rigidbody2D>(); _rightArm = transform.Find("Body/RightArm"); _leftArm = transform.Find("Body/LeftArm"); }
////// Hooks ////// private void HealthComponent_UpdateLastHitTime(On.RoR2.HealthComponent.orig_UpdateLastHitTime orig, HealthComponent self, float damageValue, Vector3 damagePosition, bool damageIsSilent, GameObject attacker) { orig(self, damageValue, damagePosition, damageIsSilent, attacker); if (NetworkServer.active && self.body && damageValue > 0f) { var cpt = self.GetComponent <KleinBottleTimeTracker>(); if (!cpt) { cpt = self.gameObject.AddComponent <KleinBottleTimeTracker>(); } if (Time.fixedTime - cpt.LastTimestamp < PROC_ICD) { return; } else { cpt.LastTimestamp = Time.fixedTime; } var count = GetCount(self.body); var pChance = (1f - Mathf.Pow(1 - procChance / 100f, count)) * 100f; var proc = Util.CheckRoll(pChance, self.body.master); if (proc) { RoR2.Projectile.ProjectileManager.instance.FireProjectile( blackHolePrefab, self.body.corePosition, Quaternion.identity, self.body.gameObject, 0f, 0f, false); var teamMembers = new List <TeamComponent>(); bool isFF = FriendlyFireManager.friendlyFireMode != FriendlyFireManager.FriendlyFireMode.Off; var scan = ((TeamIndex[])Enum.GetValues(typeof(TeamIndex))); var myTeam = TeamComponent.GetObjectTeam(self.body.gameObject); foreach (var ind in scan) { if (isFF || myTeam != ind) { teamMembers.AddRange(TeamComponent.GetTeamMembers(ind)); } } teamMembers.Remove(self.body.teamComponent); float sqrad = PULL_RADIUS * PULL_RADIUS; var isCrit = self.body.RollCrit(); foreach (TeamComponent tcpt in teamMembers) { var velVec = tcpt.transform.position - self.transform.position; if (velVec.sqrMagnitude <= sqrad) { bool shouldPull = meleeSurvivorBodyNames.Contains(self.body.name); if (self.body.name == "ToolbotBody(Clone)") { shouldPull &= self.body.skillLocator.primary.skillDef.skillName == "FireBuzzsaw"; } if (invertBodyNames) { shouldPull = !shouldPull; } if (shouldPull) { var(vInitial, _) = CalculateVelocityForFinalPosition(tcpt.transform.position, self.transform.position, 0f); velVec = vInitial; } else { float theta; if (velVec.x == 0 && velVec.z == 0) { theta = UnityEngine.Random.value * Mathf.PI * 2f; } else { theta = Mathf.Atan2(velVec.z, velVec.x); } float mag = velVec.magnitude; if (mag == 0) { mag = velVec.y; } var pitch = Mathf.Asin(velVec.y / mag); pitch = Remap(pitch, -1, 1, 0.325f, 0.675f); velVec = new Vector3(Mathf.Cos(theta) * Mathf.Cos(pitch), Mathf.Sin(pitch), Mathf.Sin(theta) * Mathf.Cos(pitch)); } if (tcpt.body && tcpt.body.isActiveAndEnabled) { if (tcpt.body.healthComponent) { tcpt.body.healthComponent.TakeDamage(new DamageInfo { attacker = self.gameObject, canRejectForce = true, crit = isCrit, damage = self.body.damage * damageFrac, damageColorIndex = DamageColorIndex.Item, damageType = DamageType.AOE, force = Vector3.zero, inflictor = null, position = tcpt.body.corePosition, procChainMask = default,
//Check if it's out of the screen in a wrap direction, if so, wrap. public override void Update(float deltaTime) { foreach (Entity e in getApplicableEntities()) { PositionComponent posComp = ( PositionComponent )e.getComponent(GlobalVars.POSITION_COMPONENT_NAME); VelocityComponent velComp = ( VelocityComponent )e.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME); ScreenEdgeComponent scrEdgComp = ( ScreenEdgeComponent )e.getComponent(GlobalVars.SCREEN_EDGE_COMPONENT_NAME); //Intersect sides of screen check if (scrEdgComp.right == 1 && posComp.x + posComp.width / 2 >= level.levelWidth && velComp.x >= 0) { stopRight(posComp, velComp); } if (scrEdgComp.left == 1 && posComp.x - posComp.width / 2 <= 0 && velComp.x <= 0) { stopLeft(posComp, velComp); } if (scrEdgComp.down == 1 && posComp.y + posComp.height / 2 >= level.levelHeight && velComp.y >= 0) { stopDown(posComp, velComp); } if (scrEdgComp.up == 1 && posComp.y - posComp.height / 2 <= 0 && velComp.y <= 0) { stopUp(posComp, velComp); } float buffer = 3.0f; //Off sides of screen check if (posComp.x > (level.levelWidth + posComp.width / 2 - buffer) && velComp.x > 0) { if (scrEdgComp.right == 2) { wrapRight(posComp); } else if (scrEdgComp.right == 3) { level.removeEntity(posComp.myEntity); } else if (scrEdgComp.right == 4) { level.beginEndLevel(); level.removeEntity(posComp.myEntity); } else if (scrEdgComp.right == 5) { if (!e.hasComponent(GlobalVars.HEALTH_COMPONENT_NAME)) { return; } HealthComponent healthComp = ( HealthComponent )e.getComponent(GlobalVars.HEALTH_COMPONENT_NAME); healthComp.subtractFromHealth(healthComp.maxHealth + 1); } } if (posComp.x < (-posComp.width / 2 + buffer) && velComp.x < 0) { if (scrEdgComp.left == 2) { wrapLeft(posComp); } else if (scrEdgComp.left == 3) { level.removeEntity(posComp.myEntity); } else if (scrEdgComp.left == 4) { level.beginEndLevel(); level.removeEntity(posComp.myEntity); } else if (scrEdgComp.left == 5) { if (!e.hasComponent(GlobalVars.HEALTH_COMPONENT_NAME)) { return; } HealthComponent healthComp = ( HealthComponent )e.getComponent(GlobalVars.HEALTH_COMPONENT_NAME); healthComp.subtractFromHealth(healthComp.maxHealth); } } if (posComp.y > (level.levelHeight + posComp.height / 2 - buffer) && velComp.y > 0) { if (scrEdgComp.down == 2) { wrapDown(posComp); } else if (scrEdgComp.down == 3) { level.removeEntity(posComp.myEntity); } else if (scrEdgComp.down == 4) { level.beginEndLevel(); level.removeEntity(posComp.myEntity); } else if (scrEdgComp.down == 5) { if (!e.hasComponent(GlobalVars.HEALTH_COMPONENT_NAME)) { return; } HealthComponent healthComp = ( HealthComponent )e.getComponent(GlobalVars.HEALTH_COMPONENT_NAME); healthComp.subtractFromHealth(healthComp.maxHealth); } } if (posComp.y < (-posComp.height / 2 + buffer) && velComp.y < 0) { if (scrEdgComp.up == 2) { wrapUp(posComp); } else if (scrEdgComp.down == 3) { level.removeEntity(posComp.myEntity); } else if (scrEdgComp.up == 4) { level.beginEndLevel(); level.removeEntity(posComp.myEntity); } else if (scrEdgComp.up == 5) { if (!e.hasComponent(GlobalVars.HEALTH_COMPONENT_NAME)) { return; } HealthComponent healthComp = ( HealthComponent )e.getComponent(GlobalVars.HEALTH_COMPONENT_NAME); healthComp.subtractFromHealth(healthComp.maxHealth); } } } }
private static void On_HCTakeDamage(On.RoR2.HealthComponent.orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo) { if (!self.body) { orig(self, damageInfo); return; } var cpt = self.body.GetComponent <ScepterToolbotDashTracker>(); if (!cpt || !cpt.enabled) { orig(self, damageInfo); return; } cpt.trackedDamageTaken += damageInfo.damage; damageInfo.damage /= 2f; orig(self, damageInfo); }
public abstract void Execute(HealthComponent target);
/// <summary> /// Handles Player versus Wall collision /// </summary> /// <param name="Player"> Id of the player entity </param> /// <param name="WallEnt"> Id of the wall entity </param> private void PlayerVsWallColl(int Player, int WallEnt, GameTime gameTime) { PlayerComponent playerComp = ComponentManager.Instance.GetEntityComponent <PlayerComponent>(Player); VelocityComponent pvc = ComponentManager.Instance.GetEntityComponent <VelocityComponent>(Player); DirectionComponent pdc = ComponentManager.Instance.GetEntityComponent <DirectionComponent>(Player); CollisionRectangleComponent crc1 = ComponentManager.Instance.GetEntityComponent <CollisionRectangleComponent>(WallEnt); CollisionRectangleComponent crc2 = ComponentManager.Instance.GetEntityComponent <CollisionRectangleComponent>(Player); PositionComponent pc = ComponentManager.Instance.GetEntityComponent <PositionComponent>(Player); PositionComponent pcwall = ComponentManager.Instance.GetEntityComponent <PositionComponent>(WallEnt); WallComponent wall = ComponentManager.Instance.GetEntityComponent <WallComponent>(WallEnt); if (wall.wall == Wall.LeftWall) { if (crc2.CollisionRec.X + crc2.CollisionRec.Width * 0.5 < crc1.CollisionRec.X) { pc.position.X = Game.Instance.GraphicsDevice.Viewport.Width - 1 - crc2.CollisionRec.Width * 0.5f; } } else if (wall.wall == Wall.RightWall) { if (crc2.CollisionRec.X + crc2.CollisionRec.Width * 0.5 > crc1.CollisionRec.X) { pc.position.X = 1 - crc2.CollisionRec.Width * 0.5f; } } else if (wall.wall == Wall.TopWall && !playerComp.isFalling) { if (pdc.directio != Direction.Still) { changeDir(pdc); pdc.preDir = pdc.directio; pdc.directio = Direction.Still; } pvc.velocity.Y = 0; pvc.velocity.Y += 500 * (float)gameTime.ElapsedGameTime.TotalSeconds; playerComp.isFalling = true; HealthComponent hc = ComponentManager.Instance.GetEntityComponent <HealthComponent>(Player); //hc.health -= 1; } else if (wall.wall == Wall.BottomWall) { //@TODO // only loose life when the player jump on the floor, not when the player falls to the ground // and have some kind of timer unti you can jump away OnFloorComponent fc = ComponentManager.Instance.GetEntityComponent <OnFloorComponent>(Player); playerComp.isFalling = false; if (pdc.directio != Direction.Still) { pvc.velocity.Y = 0; changeDir(pdc); pdc.preDir = pdc.directio; pdc.directio = Direction.Still; } //else if(pdc.directio == Direction.Still) //{ // pvc.velocity.Y = 0; //} pvc.velocity.Y = 0; pvc.velocity.Y -= 500F * (float)gameTime.ElapsedGameTime.TotalSeconds; HealthComponent hc = ComponentManager.Instance.GetEntityComponent <HealthComponent>(Player); if (fc == null) { fc = new OnFloorComponent(); ComponentManager.Instance.AddComponentToEntity(Player, fc); hc.health -= 1; ComponentManager.Instance.AddComponentToEntity(Player, new SoundEffectComponent("splat")); } } }
public void RegisterBehaviour(HealthComponent behaviour) { HealthComponentList.Add(behaviour); }
public void HealthComponentTest() { HealthComponent c = new HealthComponent(10); Assert.AreEqual(10, c.Health, "Health value incorrect"); }
/// <summary> /// A method for handling player versus player collision /// </summary> /// <param name="ent1"> ID of entity 1 </param> /// <param name="ent2"> ID of entity 2 </param> /// <param name="gt"></param> private void PlayerVsPlayerCollision(int ent1, int ent2, GameTime gt) { PlayerComponent pcp1 = ComponentManager.Instance.GetEntityComponent <PlayerComponent>(ent1); PlayerComponent pcp2 = ComponentManager.Instance.GetEntityComponent <PlayerComponent>(ent2); PositionComponent pos1 = ComponentManager.Instance.GetEntityComponent <PositionComponent>(ent1); PositionComponent pos2 = ComponentManager.Instance.GetEntityComponent <PositionComponent>(ent2); CollisionRectangleComponent crc1 = ComponentManager.Instance.GetEntityComponent <CollisionRectangleComponent>(ent1); CollisionRectangleComponent crc2 = ComponentManager.Instance.GetEntityComponent <CollisionRectangleComponent>(ent2); DirectionComponent dcp1 = ComponentManager.Instance.GetEntityComponent <DirectionComponent>(ent1); DirectionComponent dcp2 = ComponentManager.Instance.GetEntityComponent <DirectionComponent>(ent2); VelocityComponent vcp1 = ComponentManager.Instance.GetEntityComponent <VelocityComponent>(ent1); VelocityComponent vcp2 = ComponentManager.Instance.GetEntityComponent <VelocityComponent>(ent2); BallOfSpikesPowerUpComponent bspc1 = ComponentManager.Instance.GetEntityComponent <BallOfSpikesPowerUpComponent>(ent1); BallOfSpikesPowerUpComponent bspc2 = ComponentManager.Instance.GetEntityComponent <BallOfSpikesPowerUpComponent>(ent2); if (pos1.position.Y + crc1.CollisionRec.Height * 0.5f < pos2.position.Y) { // entity 1 is above entity 2 if (!pcp1.isFalling && !pcp2.isFalling) { if (dcp2.directio != Direction.Still) { changeDir(dcp2); dcp2.preDir = dcp2.directio; dcp2.directio = Direction.Still; } vcp2.velocity.Y = 0; vcp1.velocity.Y = -200f; ComponentManager.Instance.AddComponentToEntity(ent2, new SoundEffectComponent("hit")); ComponentManager.Instance.AddComponentToEntity(ent1, new SoundEffectComponent("grunt")); //if enitity 2 dosent have ballofspikePUPcomponent loose life if (bspc2 == null) { HealthComponent hc2 = ComponentManager.Instance.GetEntityComponent <HealthComponent>(ent2); //hc2.health -= 1; pcp2.isFalling = true; } //else if enitity 1 dosent have ballofspikePUPcomponent loose life else if (bspc1 == null) { HealthComponent hc1 = ComponentManager.Instance.GetEntityComponent <HealthComponent>(ent1); //hc1.health -= 1; pcp1.isFalling = true; } } } else if (pos2.position.Y + crc2.CollisionRec.Height * 0.5f < pos1.position.Y) { // entity 2 is above entity 1 if (!pcp1.isFalling && !pcp2.isFalling) { if (dcp1.directio != Direction.Still) { changeDir(dcp1); dcp1.preDir = dcp1.directio; dcp1.directio = Direction.Still; } vcp1.velocity.Y = 0; vcp2.velocity.Y = -200f; ComponentManager.Instance.AddComponentToEntity(ent1, new SoundEffectComponent("hit")); ComponentManager.Instance.AddComponentToEntity(ent2, new SoundEffectComponent("grunt")); //if enitity 1 dosent have ballofspikePUPcomponent loose life if (bspc1 == null) { HealthComponent hc1 = ComponentManager.Instance.GetEntityComponent <HealthComponent>(ent1); //hc1.health -= 1; pcp1.isFalling = true; } //else if enitity 2 dosent have ballofspikePUPcomponent loose life else if (bspc2 == null) { HealthComponent hc2 = ComponentManager.Instance.GetEntityComponent <HealthComponent>(ent2); //hc2.health -= 1; pcp2.isFalling = true; } } } else // both are on the same "level" { if (!pcp2.isFalling && !pcp1.isFalling) { if (dcp1.directio != Direction.Still) { changeDir(dcp1); dcp1.preDir = dcp1.directio; dcp1.directio = Direction.Still; } vcp1.velocity.Y = 0; if (dcp2.directio != Direction.Still) { changeDir(dcp2); dcp2.preDir = dcp2.directio; dcp2.directio = Direction.Still; } vcp2.velocity.Y = 0; ComponentManager.Instance.AddComponentToEntity(ent2, new SoundEffectComponent("sidehit")); ComponentManager.Instance.AddComponentToEntity(ent1, new SoundEffectComponent("sidehit")); //If enitity 1 dosent have ballofspikePUPcomponent loose life if (bspc1 == null) { HealthComponent hc1 = ComponentManager.Instance.GetEntityComponent <HealthComponent>(ent1); //hc1.health -= 1; pcp1.isFalling = true; } //If enitity 2 dosent have ballofspikePUPcomponent loose life if (bspc2 == null) { HealthComponent hc2 = ComponentManager.Instance.GetEntityComponent <HealthComponent>(ent2); //hc2.health -= 1; pcp2.isFalling = true; } pushAway(ent1, ent2, gt); } } }
private void IsAlive(ref NodeStatus status) { HealthComponent healthComponent = Owner.FirstComponentOfType <HealthComponent>(); status = healthComponent.IsAlive ? NodeStatus.Success : NodeStatus.Failed; }
public void OnControllerColliderHit(HealthComponent healthComponent) { healthComponent.RestoreHealth(amount); Destroy(gameObject); }
private void OnPlayerHealthSet(HealthComponent healthComponent) { HealthComponent = healthComponent; }
public ExperienceComponent(HealthComponent healthComponent, AttackComponent attackComponent) { this.healthComponent = healthComponent; this.attackComponent = attackComponent; }
private static void BrittleCrownDamageHook(On.RoR2.HealthComponent.orig_TakeDamage orig, HealthComponent self, DamageInfo info) { if (!NetworkServer.active) { orig(self, info); //It is not our place to fix faulty mods calling this. return; } if (!ShareSuite.MoneyIsShared.Value || !(bool)self.body || !(bool)self.body.inventory ) { orig(self, info); return; } #region Sharedmoney // The idea here is that we track amount of money pre and post function evaluation. // We can subsequently apply the difference to the shared pool. var body = self.body; var preDamageMoney = self.body.master.money; orig(self, info); if (!self.alive) { return; } var postDamageMoney = self.body.master.money; // Ignore all of this if we do not actually have the item if (body.inventory.GetItemCount(ItemCatalog.FindItemIndex("GoldOnHit")) <= 0) { return; } // Apply the calculation to the shared money pool SharedMoneyValue += (int)postDamageMoney - (int)preDamageMoney; // Add impact effect foreach (var player in PlayerCharacterMasterController.instances) { if (!(bool)player.master.GetBody() || player.master.GetBody() == body) { continue; } EffectManager.SimpleImpactEffect(Resources.Load <GameObject>( "Prefabs/Effects/ImpactEffects/CoinImpact"), player.master.GetBody().corePosition, Vector3.up, true); } #endregion }
public Entity AddHealth(int newHealth) { var component = new HealthComponent(); component.health = newHealth; return AddHealth(component); }
private void ParticlePool_OnRegisterHealth(HealthComponent healthComponent) { healthComponent.OnDie += () => Spawn(healthComponent.transform.position); }
private void LoadHealthComponent(GameEntity entity, HealthComponentInfo info) { var comp = new HealthComponent(); entity.AddComponent(comp); comp.LoadInfo(info); }
private void StoreDamage(On.RoR2.HealthComponent.orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo) { //TODO: all of these has to make sure if 1. player is alive 2. player is not teleporting 3. player has a item 4. player has a hc var InventoryCount = GetCount(self.body); var hcGameObject = self.gameObject; var hcHitManager = hcGameObject.GetComponentInChildren <HitlagManager>()?.gameObject; //check if the component exists or not if (InventoryCount <= 0) { if (hcHitManager) { #if DEBUG TurboEdition._logger.LogWarning(ItemName + " HLM was created, but user lost all items, storeForgiveness is: " + storeForgiveness); #endif if (!storeForgiveness) { hcGameObject.GetComponentInChildren <HitlagManager>().ReleaseAll(true); return; } hcGameObject.GetComponentInChildren <HitlagManager>().CleanseAll(true); //UnityEngine.Object.Destroy(hcHitManager); } } else { if (!hcHitManager && self) //creates a manager if user has item and a hc { hcHitManager = UnityEngine.Object.Instantiate(hitManager); hcHitManager.GetComponent <NetworkedBodyAttachment>().AttachToGameObjectAndSpawn(self.gameObject); //hcGameObject.GetComponent<HitlagManager>().NetMaxCapacity = storeMaxCapacity; #if DEBUG TurboEdition._logger.LogWarning(ItemName + " No HLM created, creating one with capacity: " + storeMaxCapacity); #endif } if (hcHitManager && self && damageInfo.damage > 0) { #if DEBUG TurboEdition._logger.LogWarning(ItemName + " Theres a HLM, so we are going to delay " + damageInfo.damage + " of damage."); #endif if (damageInfo.damageType == DamageType.FallDamage && !storesFall) { #if DEBUG TurboEdition._logger.LogWarning(ItemName + " Damage type was " + damageInfo.damageType + " but storesFall config is " + storesFall); #endif orig(self, damageInfo); return; } if (damageInfo.dotIndex != DotController.DotIndex.None && !storesDoTs) { #if DEBUG TurboEdition._logger.LogWarning(ItemName + " Damage type was " + damageInfo.damageType + " but storesDoTs config is " + storesDoTs); #endif orig(self, damageInfo); return; } //We update the manager with the new delay //This is different to the original idea where each instance of damage would have its own release time based on item count of when the damage was taken. i.e if user gets damaged at 5 delay, loses an item, all delayed damage will be released earlier hcHitManager.GetComponent <HitlagManager>().NetTimeToReleaseAt = (hitlagInitial + (InventoryCount - 1) * hitlagStack); #if DEBUG TurboEdition._logger.LogWarning(ItemName + " Updated " + hcHitManager + " to have delay of " + (hitlagInitial + (InventoryCount - 1) * hitlagStack)); #endif //We define a new instance var hitInstance = new HitlagInstance { //I wonder if its better to pass these as arguments than doing this, desu. CmpOrig = orig, CmpSelf = self, CmpDI = damageInfo }; #if DEBUG TurboEdition._logger.LogWarning(ItemName + " Creating a new " + hitInstance); #endif var component = hcGameObject.GetComponentInChildren <HitlagManager>(); component.AddInstance(Run.FixedTimeStamp.now, hitInstance); component.NetTotalDamage += hitInstance.CmpDI.damage; #if DEBUG TurboEdition._logger.LogWarning(ItemName + " Added it to the list with timestamp " + Run.FixedTimeStamp.now); #endif return; } #if DEBUG TurboEdition._logger.LogWarning(ItemName + " Didn't delay any damage, calling orig."); #endif } orig(self, damageInfo); }
private static void HealthComponent_TakeDamage(On.RoR2.HealthComponent.orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo) { orig(self, damageInfo); if (NetworkServer.active && RunArtifactManager.instance.IsArtifactEnabled(ArtifactOfGenetics.artifactDef)) { if (damageInfo.attacker is GameObject attackerObject) { if (attackerObject != null && attackerObject.GetComponent <CharacterBody>() is CharacterBody attackerBody) { if (attackerBody != null && attackerBody.inventory?.GetItemCount(GeneTokens.blockerDef) == 0) { MonsterGeneBehaviour attackerGene = livingGenes.Find(x => x.characterBody == attackerBody); if (attackerGene != null) { attackerGene.damageDealt += damageInfo.damage; } } } } else if (damageInfo.inflictor is GameObject inflictorObject) { if (inflictorObject != null && inflictorObject.GetComponent <CharacterBody>() is CharacterBody inflictorBody) { if (inflictorBody != null && inflictorBody.inventory?.GetItemCount(GeneTokens.blockerDef) == 0) { MonsterGeneBehaviour inflictorGene = livingGenes.Find(x => x.characterBody == inflictorBody); if (inflictorGene != null) { inflictorGene.damageDealt += damageInfo.damage; } } } } } }
public void SetEnableOnDistanceOrDamage() { enable_on_distance_or_damage = true; health_component = GetComponent <HealthComponent>(); health_component.on_health_change += OnHealth; }
private void CalculateBerryBuff(On.RoR2.HealthComponent.orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo) { var InventoryCount = GetCount(self.body); if (InventoryCount > 0) { self.body.AddTimedBuffAuthority(NumbBerryBuff, baseBerryBuffDuration + (addBerryBuffDuration * (InventoryCount - 1))); } orig(self, damageInfo); }
private void Awake() { _healthComponent = GetComponent <HealthComponent>(); _movementComponent = GetComponent <MovementComponent>(); }
private bool FindTarget(CharacterBody cb) { TeamIndex ownerTeam = cb.teamComponent.teamIndex; #if DEBUG TurboEdition._logger.LogWarning(EquipmentName + " Getting the team of the owner... " + ownerTeam); #endif for (TeamIndex teamCounter = TeamIndex.Neutral; teamCounter < TeamIndex.Count; teamCounter++) { #if DEBUG TurboEdition._logger.LogWarning(EquipmentName + " Trying to find the enemy team to owners... " + teamCounter); #endif if (TeamManager.IsTeamEnemy(ownerTeam, teamCounter)) { var enemyMember = TeamComponent.GetTeamMembers(teamCounter); #if DEBUG TurboEdition._logger.LogWarning(EquipmentName + " Found the enemy team to owners: " + teamCounter); #endif if (teamCounter != TeamIndex.Neutral && enemyMember.Count <= 0) { return(false); } //Added extra check for neutral since it ALWAYS tries to cycle through neutral enemies first (ie pots or barrels), if the extra check wasn't there it would return and never check for monsters. for (int aC = 0; aC < attackCount; aC++) { #if DEBUG TurboEdition._logger.LogWarning(EquipmentName + " Trying to attack somebody, " + (aC + 1) + " out of " + attackCount); #endif for (int i = 0; i < enemyMember.Count; i++) { //Get the health component to see if its alive / its an enemy / thing we can MURDER HealthComponent healthComponent = enemyMember[i].GetComponent <HealthComponent>(); GameObject enemyObject = enemyMember[i].gameObject; if (healthComponent) { //Something something we are getting the cb direction, not the actual camera, and with aimDirection we are getting the aiming, not the actual camera //It might break if something disconnects the aim movement from the camera //Vector3 cbForward = cb.transform.TransformDirection(Vector3.forward); Vector3 cbForward = cb.inputBank.aimDirection; Vector3 enemyPos = enemyObject.transform.position - cb.transform.position; if (HasLoS(cb.gameObject, enemyObject) && Vector3.Dot(cbForward, enemyPos) > 0.4f) // Dot returns 1 if they point in exactly the same direction, -1 if they point in completely opposite directions and zero if the vectors are perpendicular. { #if DEBUG TurboEdition._logger.LogWarning(EquipmentName + " Found a suitable enemy inside the fov/range/whatever: " + enemyObject + " at " + enemyPos); #endif if (NetworkServer.active) { DamageInfo damageInfo = new DamageInfo { damage = CalcDamage(cb, teamCounter), crit = false, damageType = DamageType.BypassArmor, procCoefficient = 0, //Because f**k autoplay damageColorIndex = DamageColorIndex.Default, rejected = false, //I dunno if I can force bypassing bears this way attacker = cb.gameObject, }; healthComponent.TakeDamage(damageInfo); #if DEBUG TurboEdition._logger.LogWarning(EquipmentName + " Damaged " + healthComponent + " for " + damageInfo); #endif return(true); } } } } } } } return(false); }
public static void Invoke_OnHealthInitialized(HealthComponent healthComponent) { OnHealthInitialized?.Invoke(healthComponent); }
static Boolean NotNull(HealthComponent hc) => hc && hc.alive;
public static void HealthComponent_TakeDamage(On.RoR2.HealthComponent.orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo) { if (damageInfo == null) { orig(self, damageInfo); return; } CharacterBody characterBody = self.gameObject.GetComponent <CharacterBody>(); CharacterBody attackerCharacterBody = damageInfo.attacker.GetComponent <CharacterBody>(); if (attackerCharacterBody.baseNameToken == "STRONGSTANFRAGMENT_NAME" || attackerCharacterBody.baseNameToken == "WEAKSTANFRAGMENT_NAME") { damageInfo.attacker = attackerCharacterBody.master.minionOwnership.ownerMaster.GetBody().gameObject; } orig(self, damageInfo); }
public BoardCell AddChild(BoardItem child, int x, int z, HealthComponent buildingHealth, bool checkSkirt) { return(this.AddChild(child, x, z, buildingHealth, checkSkirt, true)); }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").transform; health = GetComponent <HealthComponent>(); }
void Awake() { _healthcomponent = GetComponent<HealthComponent>(); _movement = GetComponent<MovementComponent>(); _animComponent = GetComponent<AnimationComponent>(); float random = Random.Range ( -25f, 25f ); _movement.BASESPEED += random; }
private void UpdateHealth(HealthComponent health, HealthConfigComponent healthConfig, HealthBarComponent healthBar) { float num = health.CurrentHealth / healthConfig.BaseHealth; healthBar.ProgressValue = num; }
public Entity AddHealth(HealthComponent component) { return AddComponent(ComponentIds.Health, component); }
private void ShipSpawned(HealthComponent healthComponent) { healthComponent.healthChangedEvent += delegate(HealthComponent victim, float damage, float healthLeft) { StopTime(); }; }
public void UnregisterBehaviour(HealthComponent behaviour) { HealthComponentList.Remove(behaviour); }
internal static void CreatePrefab() { // first clone the commando prefab so we can turn that into our own survivor characterPrefab = PrefabAPI.InstantiateClone(Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody"), "WispPreview", true, "C:\\Users\\test\\Documents\\ror2mods\\ExampleSurvivor\\ExampleSurvivor\\ExampleSurvivor\\ExampleSurvivor.cs", "CreatePrefab", 151); //Debug.Log("Loaded prefab"); characterPrefab.GetComponent <NetworkIdentity>().localPlayerAuthority = true; //Debug.Log("Set local player authority"); #region charactermodel // create the model here, we're gonna replace commando's model with our own GameObject model = CreateModel(characterPrefab); GameObject gameObject = new GameObject("ModelBase"); gameObject.transform.parent = characterPrefab.transform; gameObject.transform.localPosition = new Vector3(0f, -0.81f, 0f); gameObject.transform.localRotation = Quaternion.identity; gameObject.transform.localScale = new Vector3(1f, 1f, 1f); //Debug.Log("Created model base"); GameObject gameObject2 = new GameObject("CameraPivot"); gameObject2.transform.parent = gameObject.transform; gameObject2.transform.localPosition = new Vector3(0f, 1.6f, 0f); gameObject2.transform.localRotation = Quaternion.identity; gameObject2.transform.localScale = Vector3.one; //Debug.Log("Created camera pivot"); GameObject gameObject3 = new GameObject("AimOrigin"); gameObject3.transform.parent = gameObject.transform; gameObject3.transform.localPosition = new Vector3(0f, 1.4f, 0f); gameObject3.transform.localRotation = Quaternion.identity; gameObject3.transform.localScale = Vector3.one; //Debug.Log("Created aim origin"); Transform transform = model.transform; transform.parent = gameObject.transform; transform.localPosition = Vector3.zero; transform.localScale = new Vector3(1f, 1f, 1f); transform.localRotation = Quaternion.identity; //Debug.Log("Created character transform"); CharacterDirection characterDirection = characterPrefab.GetComponent <CharacterDirection>(); characterDirection.moveVector = Vector3.zero; characterDirection.targetTransform = gameObject.transform; characterDirection.overrideAnimatorForwardTransform = null; characterDirection.rootMotionAccumulator = null; characterDirection.modelAnimator = model.GetComponentInChildren <Animator>(); characterDirection.driveFromRootRotation = false; characterDirection.turnSpeed = 720f; //Debug.Log("Set character direction"); #endregion #region basestats // set up the character body here CharacterBody bodyComponent = characterPrefab.GetComponent <CharacterBody>(); bodyComponent.bodyIndex = -1; bodyComponent.baseNameToken = "WISP_NAME"; // name token bodyComponent.subtitleNameToken = "WISP_SUBTITLE"; // subtitle token- used for umbras bodyComponent.bodyFlags = CharacterBody.BodyFlags.ImmuneToExecutes; bodyComponent.rootMotionInMainState = false; bodyComponent.mainRootSpeed = 0; bodyComponent.baseMaxHealth = 82.5f; bodyComponent.levelMaxHealth = 24.75f; bodyComponent.baseRegen = 1f; bodyComponent.levelRegen = 0.25f; bodyComponent.baseMaxShield = 0; bodyComponent.levelMaxShield = 0f; bodyComponent.baseMoveSpeed = 7; bodyComponent.levelMoveSpeed = 0; bodyComponent.baseAcceleration = 80; bodyComponent.baseJumpPower = 15; bodyComponent.levelJumpPower = 0; bodyComponent.baseDamage = 6; bodyComponent.levelDamage = 1.2f; bodyComponent.baseAttackSpeed = 1; bodyComponent.levelAttackSpeed = 0; bodyComponent.baseCrit = 1; bodyComponent.levelCrit = 0; bodyComponent.baseArmor = 0; bodyComponent.levelArmor = 0; bodyComponent.baseJumpCount = 1; bodyComponent.sprintingSpeedMultiplier = 1.45f; bodyComponent.wasLucky = false; bodyComponent.hideCrosshair = false; bodyComponent.aimOriginTransform = gameObject3.transform; bodyComponent.hullClassification = HullClassification.Human; bodyComponent.portraitIcon = Assets.charPortrait; bodyComponent.isChampion = false; bodyComponent.currentVehicle = null; bodyComponent.skinIndex = 0U; //Debug.Log("Created character body"); #endregion #region spawning-and-states //Replace the existing spawn animation EntityStateMachine entityStateMachine = characterPrefab.GetComponent <EntityStateMachine>(); entityStateMachine.initialStateType = new SerializableEntityStateType(typeof(EntityStates.WispSurvivorStates.Spawn)); bodyComponent.currentVehicle = null; bodyComponent.preferredPodPrefab = null; bodyComponent.preferredInitialStateType = entityStateMachine.initialStateType; //Change our main state to account for the float functionality entityStateMachine.mainStateType = new SerializableEntityStateType(typeof(EntityStates.WispSurvivorStates.WispCharacterMain)); characterPrefab.AddComponent <TetherHandler>(); #endregion #region movement-camera // the charactermotor controls the survivor's movement and stuff CharacterMotor characterMotor = characterPrefab.GetComponent <CharacterMotor>(); characterMotor.walkSpeedPenaltyCoefficient = 1f; characterMotor.characterDirection = characterDirection; characterMotor.muteWalkMotion = false; characterMotor.mass = 100f; //characterMotor.airControl = 0.75f; characterMotor.airControl = 5f; characterMotor.disableAirControlUntilCollision = false; characterMotor.generateParametersOnAwake = true; //characterMotor.useGravity = true; //characterMotor.isFlying = false; //Debug.Log("Created character motor"); InputBankTest inputBankTest = characterPrefab.GetComponent <InputBankTest>(); inputBankTest.moveVector = Vector3.zero; CameraTargetParams cameraTargetParams = characterPrefab.GetComponent <CameraTargetParams>(); cameraTargetParams.cameraParams = Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody").GetComponent <CameraTargetParams>().cameraParams; cameraTargetParams.cameraPivotTransform = null; cameraTargetParams.aimMode = CameraTargetParams.AimType.Standard; cameraTargetParams.recoil = Vector2.zero; cameraTargetParams.idealLocalCameraPos = Vector3.zero; cameraTargetParams.dontRaycastToPivot = false; //Debug.Log("Created camera target parameters"); // this component is used to locate the character model(duh), important to set this up here ModelLocator modelLocator = characterPrefab.GetComponent <ModelLocator>(); modelLocator.modelTransform = transform; modelLocator.modelBaseTransform = gameObject.transform; modelLocator.dontReleaseModelOnDeath = false; modelLocator.autoUpdateModelTransform = true; modelLocator.dontDetatchFromParent = false; modelLocator.noCorpse = false; modelLocator.normalizeToFloor = false; // set true if you want your character to rotate on terrain like acrid does modelLocator.preserveModel = false; //Debug.Log("Created model locator"); #endregion // childlocator is something that must be set up in the unity project, it's used to find any child objects for things like footsteps or muzzle flashes // also important to set up if you want quality ChildLocator childLocator = model.GetComponent <ChildLocator>(); //Debug.Log("Established child locator reference"); // this component is used to handle all overlays and whatever on your character, without setting this up you won't get any cool effects like burning or freeze on the character // it goes on the model object of course CharacterModel characterModel = model.AddComponent <CharacterModel>(); characterModel.body = bodyComponent; characterModel.baseRendererInfos = new CharacterModel.RendererInfo[] { // set up multiple rendererinfos if needed, but for this example there's only the one new CharacterModel.RendererInfo { defaultMaterial = model.GetComponentInChildren <SkinnedMeshRenderer>().material, renderer = model.GetComponentInChildren <SkinnedMeshRenderer>(), defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On, ignoreOverlays = true //Disable overlays for incorrectly formatted character } }; characterModel.autoPopulateLightInfos = true; characterModel.invisibilityCount = 0; characterModel.temporaryOverlays = new List <TemporaryOverlay>(); //Debug.Log("Created character model"); #region skin SkinnedMeshRenderer mainRenderer = (characterModel.baseRendererInfos[0].renderer as SkinnedMeshRenderer); if (!mainRenderer) { Debug.LogError("No main renderer found!"); } if (!mainRenderer.sharedMesh) { Debug.LogError("No shared mesh found for main renderer!"); } ModelSkinController modelSkinController = model.AddComponent <ModelSkinController>(); LanguageAPI.Add("WISP_DEFAULT_SKIN", "Default"); LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo); skinDefInfo.BaseSkins = Array.Empty <SkinDef>(); skinDefInfo.MinionSkinReplacements = new SkinDef.MinionSkinReplacement[0]; skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0]; GameObject[] allObjects = new GameObject[0]; skinDefInfo.GameObjectActivations = getActivations(allObjects); skinDefInfo.Icon = Assets.skin; skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[] { new SkinDef.MeshReplacement { renderer = mainRenderer, mesh = mainRenderer.sharedMesh } }; skinDefInfo.Name = "WISP_DEFAULT_SKIN"; skinDefInfo.NameToken = "WISP_DEFAULT_SKIN"; skinDefInfo.RendererInfos = characterModel.baseRendererInfos; skinDefInfo.RootObject = model; skinDefInfo.UnlockableName = ""; SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo); var skinDefs = new List <SkinDef>() { defaultSkin }; modelSkinController.skins = skinDefs.ToArray(); //Debug.Log("Created skin"); #endregion #region team-health TeamComponent teamComponent = null; if (characterPrefab.GetComponent <TeamComponent>() != null) { teamComponent = characterPrefab.GetComponent <TeamComponent>(); } else { teamComponent = characterPrefab.GetComponent <TeamComponent>(); } teamComponent.hideAllyCardDisplay = false; teamComponent.teamIndex = TeamIndex.None; HealthComponent healthComponent = characterPrefab.GetComponent <HealthComponent>(); healthComponent.health = 82.5f; healthComponent.shield = 0f; healthComponent.barrier = 0f; healthComponent.magnetiCharge = 0f; healthComponent.body = null; healthComponent.dontShowHealthbar = false; healthComponent.globalDeathEventChanceCoefficient = 1f; //Debug.Log("Created components"); #endregion characterPrefab.GetComponent <Interactor>().maxInteractionDistance = 3f; characterPrefab.GetComponent <InteractionDriver>().highlightInteractor = true; // this disables ragdoll since the character's not set up for it, and instead plays a death animation CharacterDeathBehavior characterDeathBehavior = characterPrefab.GetComponent <CharacterDeathBehavior>(); characterDeathBehavior.deathStateMachine = characterPrefab.GetComponent <EntityStateMachine>(); characterDeathBehavior.deathState = new SerializableEntityStateType(typeof(GenericCharacterDeath)); // edit the sfxlocator if you want different sounds SfxLocator sfxLocator = characterPrefab.GetComponent <SfxLocator>(); sfxLocator.deathSound = "Play_ui_player_death"; sfxLocator.barkSound = ""; sfxLocator.openSound = ""; sfxLocator.landingSound = "Play_char_land"; sfxLocator.fallDamageSound = "Play_char_land_fall_damage"; sfxLocator.aliveLoopStart = ""; sfxLocator.aliveLoopStop = ""; //Debug.Log("Created sfx"); Rigidbody rigidbody = characterPrefab.GetComponent <Rigidbody>(); rigidbody.mass = 50f; rigidbody.drag = 0f; rigidbody.angularDrag = 0f; rigidbody.useGravity = false; rigidbody.isKinematic = true; rigidbody.interpolation = RigidbodyInterpolation.None; rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete; rigidbody.constraints = RigidbodyConstraints.None; //Debug.Log("Created rigidbody"); CapsuleCollider capsuleCollider = characterPrefab.GetComponent <CapsuleCollider>(); capsuleCollider.isTrigger = false; capsuleCollider.material = null; capsuleCollider.center = new Vector3(0f, 0f, 0f); capsuleCollider.radius = 0.5f; capsuleCollider.height = 1.82f; capsuleCollider.direction = 1; //Debug.Log("Created capsule collider"); KinematicCharacterMotor kinematicCharacterMotor = characterPrefab.GetComponent <KinematicCharacterMotor>(); kinematicCharacterMotor.CharacterController = characterMotor; kinematicCharacterMotor.Capsule = capsuleCollider; kinematicCharacterMotor.Rigidbody = rigidbody; capsuleCollider.radius = 0.5f; capsuleCollider.height = 1.82f; capsuleCollider.center = new Vector3(0, 0, 0); capsuleCollider.material = null; kinematicCharacterMotor.DetectDiscreteCollisions = false; kinematicCharacterMotor.GroundDetectionExtraDistance = 0f; kinematicCharacterMotor.MaxStepHeight = 0.2f; kinematicCharacterMotor.MinRequiredStepDepth = 0.1f; kinematicCharacterMotor.MaxStableSlopeAngle = 55f; kinematicCharacterMotor.MaxStableDistanceFromLedge = 0.5f; kinematicCharacterMotor.PreventSnappingOnLedges = false; kinematicCharacterMotor.MaxStableDenivelationAngle = 55f; kinematicCharacterMotor.RigidbodyInteractionType = RigidbodyInteractionType.None; kinematicCharacterMotor.PreserveAttachedRigidbodyMomentum = true; kinematicCharacterMotor.HasPlanarConstraint = false; kinematicCharacterMotor.PlanarConstraintAxis = Vector3.up; kinematicCharacterMotor.StepHandling = StepHandlingMethod.None; kinematicCharacterMotor.LedgeHandling = true; kinematicCharacterMotor.InteractiveRigidbodyHandling = true; kinematicCharacterMotor.SafeMovement = false; //Debug.Log("Set physics"); // this sets up the character's hurtbox, kinda confusing, but should be fine as long as it's set up in unity right HurtBoxGroup hurtBoxGroup = model.AddComponent <HurtBoxGroup>(); //Debug.Log("Set reference to hurtBoxGroup"); if (model.GetComponentInChildren <CapsuleCollider>() == null) { Debug.LogError("Could not find capsule collider!"); } HurtBox componentInChildren = model.GetComponentInChildren <CapsuleCollider>().gameObject.AddComponent <HurtBox>(); //Debug.Log("Added hurtbox component to capsule collider"); componentInChildren.gameObject.layer = LayerIndex.entityPrecise.intVal; componentInChildren.healthComponent = healthComponent; componentInChildren.isBullseye = true; componentInChildren.damageModifier = HurtBox.DamageModifier.Normal; componentInChildren.hurtBoxGroup = hurtBoxGroup; componentInChildren.indexInGroup = 0; hurtBoxGroup.hurtBoxes = new HurtBox[] { componentInChildren }; hurtBoxGroup.mainHurtBox = componentInChildren; hurtBoxGroup.bullseyeCount = 1; //Debug.Log("Set components"); // this is for handling footsteps, not needed but polish is always good FootstepHandler footstepHandler = model.AddComponent <FootstepHandler>(); footstepHandler.baseFootstepString = "Play_player_footstep"; footstepHandler.sprintFootstepOverrideString = ""; footstepHandler.enableFootstepDust = true; footstepHandler.footstepDustPrefab = Assets.footstepPrefab; // ragdoll controller is a pain to set up so we won't be doing that here.. RagdollController ragdollController = model.AddComponent <RagdollController>(); ragdollController.bones = null; ragdollController.componentsToDisableOnRagdoll = null; // this handles the pitch and yaw animations, but honestly they are nasty and a huge pain to set up so i didn't bother AimAnimator aimAnimator = model.AddComponent <AimAnimator>(); aimAnimator.inputBank = inputBankTest; aimAnimator.directionComponent = characterDirection; aimAnimator.pitchRangeMax = 55f; aimAnimator.pitchRangeMin = -50f; aimAnimator.yawRangeMin = -44f; aimAnimator.yawRangeMax = 44f; aimAnimator.pitchGiveupRange = 30f; aimAnimator.yawGiveupRange = 10f; aimAnimator.giveupDuration = 8f; //Debug.Log("Finished setup"); }
void OnEnable() { _target = (HealthComponent)target; }
public static void CreatePrefab() { // first clone the commando prefab so we can turn that into our own survivor characterPrefab = PrefabAPI.InstantiateClone(Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody"), "RocketeerBody", true, "C:\\Users\\Tinde\\Desktop\\Lurgypai\\ROR2\\mods\\Projects\\files\\ExampleSurvivor\\ExampleSurvivor\\ExampleSurvivor\\ExampleSurvivor\\Rocketeer.cs", "CreatePrefab", 151); characterPrefab.GetComponent <NetworkIdentity>().localPlayerAuthority = true; // set up the character body here CharacterBody bodyComponent = characterPrefab.GetComponent <CharacterBody>(); GameObject gameObject4 = new GameObject("AimOrigin"); bodyComponent.name = "RocketeerBody"; bodyComponent.baseNameToken = "ROCKETEER_NAME"; bodyComponent.subtitleNameToken = "ROCKETEER_SUBTITLE"; bodyComponent.bodyFlags = CharacterBody.BodyFlags.ImmuneToExecutes; bodyComponent.rootMotionInMainState = false; bodyComponent.mainRootSpeed = 0f; bodyComponent.baseMaxHealth = 85f; bodyComponent.levelMaxHealth = 20f; bodyComponent.baseRegen = 1.0f; bodyComponent.levelRegen = 0.2f; bodyComponent.baseMaxShield = 0f; bodyComponent.levelMaxShield = 0f; bodyComponent.baseMoveSpeed = 7f; bodyComponent.levelMoveSpeed = 0f; bodyComponent.baseAcceleration = 80f; bodyComponent.baseJumpPower = 15f; bodyComponent.levelJumpPower = 0f; bodyComponent.baseDamage = 13f; bodyComponent.levelDamage = 2.7f; bodyComponent.baseAttackSpeed = 1f; bodyComponent.levelAttackSpeed = 0f; bodyComponent.baseCrit = 1f; bodyComponent.levelCrit = 0f; bodyComponent.baseArmor = 20f; bodyComponent.levelArmor = 0f; bodyComponent.baseJumpCount = 1; bodyComponent.sprintingSpeedMultiplier = 1.45f; bodyComponent.wasLucky = false; bodyComponent.hideCrosshair = false; bodyComponent.crosshairPrefab = Resources.Load <GameObject>("Prefabs/Crosshair/StandardCrosshair"); bodyComponent.aimOriginTransform = gameObject4.transform; bodyComponent.hullClassification = HullClassification.Human; bodyComponent.isChampion = false; bodyComponent.currentVehicle = null; bodyComponent.skinIndex = 0U; bodyComponent.bodyColor = characterColor; bodyComponent.tag = "Player"; // the charactermotor controls the survivor's movement and stuff CharacterMotor characterMotor = characterPrefab.GetComponent <CharacterMotor>(); characterMotor.walkSpeedPenaltyCoefficient = 1f; characterMotor.muteWalkMotion = false; characterMotor.mass = 95f; characterMotor.airControl = 0.7f; characterMotor.disableAirControlUntilCollision = false; characterMotor.generateParametersOnAwake = true; //characterMotor.useGravity = true; //characterMotor.isFlying = false; InputBankTest inputBankTest = characterPrefab.GetComponent <InputBankTest>(); inputBankTest.moveVector = Vector3.zero; CameraTargetParams cameraTargetParams = characterPrefab.GetComponent <CameraTargetParams>(); cameraTargetParams.cameraParams = Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody").GetComponent <CameraTargetParams>().cameraParams; cameraTargetParams.cameraPivotTransform = null; cameraTargetParams.recoil = Vector2.zero; cameraTargetParams.idealLocalCameraPos = Vector3.zero; cameraTargetParams.dontRaycastToPivot = false; // this component is used to locate the character model(duh), important to set this up here ModelLocator modelLocator = characterPrefab.GetComponent <ModelLocator>(); //modelLocator.modelTransform = transform; //modelLocator.modelBaseTransform = gameObject.transform; modelLocator.dontReleaseModelOnDeath = false; modelLocator.autoUpdateModelTransform = true; modelLocator.dontDetatchFromParent = false; modelLocator.noCorpse = false; modelLocator.normalizeToFloor = false; // set true if you want your character to rotate on terrain like acrid does modelLocator.preserveModel = false; TeamComponent teamComponent = null; if (characterPrefab.GetComponent <TeamComponent>() != null) { teamComponent = characterPrefab.GetComponent <TeamComponent>(); } else { teamComponent = characterPrefab.GetComponent <TeamComponent>(); } teamComponent.hideAllyCardDisplay = false; teamComponent.teamIndex = TeamIndex.None; HealthComponent healthComponent = characterPrefab.GetComponent <HealthComponent>(); healthComponent.health = 100f; healthComponent.shield = 0f; healthComponent.barrier = 0f; healthComponent.magnetiCharge = 0f; healthComponent.body = null; healthComponent.dontShowHealthbar = false; healthComponent.globalDeathEventChanceCoefficient = 1f; characterPrefab.GetComponent <Interactor>().maxInteractionDistance = 3f; characterPrefab.GetComponent <InteractionDriver>().highlightInteractor = true; // this disables ragdoll since the character's not set up for it, and instead plays a death animation CharacterDeathBehavior characterDeathBehavior = characterPrefab.GetComponent <CharacterDeathBehavior>(); characterDeathBehavior.deathStateMachine = characterPrefab.GetComponent <EntityStateMachine>(); characterDeathBehavior.deathState = new SerializableEntityStateType(typeof(GenericCharacterDeath)); // edit the sfxlocator if you want different sounds SfxLocator sfxLocator = characterPrefab.GetComponent <SfxLocator>(); sfxLocator.deathSound = "Play_ui_player_death"; sfxLocator.barkSound = ""; sfxLocator.openSound = ""; sfxLocator.landingSound = "Play_char_land"; sfxLocator.fallDamageSound = "Play_char_land_fall_damage"; sfxLocator.aliveLoopStart = ""; sfxLocator.aliveLoopStop = ""; Rigidbody rigidbody = characterPrefab.GetComponent <Rigidbody>(); rigidbody.mass = 100f; rigidbody.drag = 0f; rigidbody.angularDrag = 0f; rigidbody.useGravity = false; rigidbody.isKinematic = true; rigidbody.interpolation = RigidbodyInterpolation.None; rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete; rigidbody.constraints = RigidbodyConstraints.None; CapsuleCollider capsuleCollider = characterPrefab.GetComponent <CapsuleCollider>(); capsuleCollider.isTrigger = false; capsuleCollider.material = null; capsuleCollider.center = new Vector3(0f, 0f, 0f); capsuleCollider.radius = 0.5f; capsuleCollider.height = 1.82f; capsuleCollider.direction = 1; KinematicCharacterMotor kinematicCharacterMotor = characterPrefab.GetComponent <KinematicCharacterMotor>(); kinematicCharacterMotor.CharacterController = characterMotor; kinematicCharacterMotor.Capsule = capsuleCollider; kinematicCharacterMotor.Rigidbody = rigidbody; capsuleCollider.radius = 0.5f; capsuleCollider.height = 1.82f; capsuleCollider.center = new Vector3(0, 0, 0); capsuleCollider.material = null; kinematicCharacterMotor.DetectDiscreteCollisions = false; kinematicCharacterMotor.GroundDetectionExtraDistance = 0f; kinematicCharacterMotor.MaxStepHeight = 0.2f; kinematicCharacterMotor.MinRequiredStepDepth = 0.1f; kinematicCharacterMotor.MaxStableSlopeAngle = 55f; kinematicCharacterMotor.MaxStableDistanceFromLedge = 0.5f; kinematicCharacterMotor.PreventSnappingOnLedges = false; kinematicCharacterMotor.MaxStableDenivelationAngle = 55f; kinematicCharacterMotor.RigidbodyInteractionType = RigidbodyInteractionType.None; kinematicCharacterMotor.PreserveAttachedRigidbodyMomentum = true; kinematicCharacterMotor.HasPlanarConstraint = false; kinematicCharacterMotor.PlanarConstraintAxis = Vector3.up; kinematicCharacterMotor.StepHandling = StepHandlingMethod.None; kinematicCharacterMotor.LedgeHandling = true; kinematicCharacterMotor.InteractiveRigidbodyHandling = true; kinematicCharacterMotor.SafeMovement = false; characterPrefab.AddComponent <RocketeerShinyJetpackController>(); }
void UpdateThreatAssessment(float dt) { float threatDist = 1000f; float dist = 100f; float num = float.PositiveInfinity; Collider[] colliders = Physics.OverlapSphere(character.transform.position, 100f, LayerIndex.entityPrecise.mask); Collider[] colliders1 = Physics.OverlapSphere(character.transform.position, 25f, LayerIndex.projectile.mask); if (colliders.Length > 30 || colliders1.Length > 30) { threatDist = 0f; } else { foreach (Collider collider in colliders) { float distance = Vector3.Distance(character.transform.position, collider.transform.position); if (distance < num) { HurtBox a = collider.GetComponent <HurtBox>(); if (a) { HealthComponent b = a.healthComponent; if (b && (b.gameObject == character.gameObject || b.body.teamComponent.teamIndex <= TeamIndex.Player)) { continue; } if (distance == 0) { threatDist = 0; break; } num = distance; } } } if (threatDist != 0f) { foreach (Collider collider in colliders1) { float distance = Vector3.Distance(character.transform.position, collider.transform.position); if (distance < num) { //HurtBox a = collider.GetComponent<HurtBox>(); //if (a) //{ // HealthComponent b = a.healthComponent; // if (b && b.gameObject == character.gameObject) // { // continue; // } // if (distance == 0) // { // threatDist = 0; // break; // } // num = distance; //} RoR2.Projectile.ProjectileController projectileController = collider.transform.root.GetComponentInChildren <RoR2.Projectile.ProjectileController>(); if (projectileController) { if (projectileController.teamFilter.teamIndex <= TeamIndex.Player || projectileController.owner == character.gameObject) { continue; } } if (distance == 0) { threatDist = 0; break; } num = distance; } } } if (!float.IsPositiveInfinity(num)) { threatDist = num; } else { threatDist = dist; } } //List<Collider> colliderList = new List<Collider>(); //Collider[] tempColliders; //Collider[] tempColliders2; //tempColliders = Physics.OverlapBox(character.transform.position, new Vector3(50f, 50f, 50f), character.transform.rotation, LayerIndex.projectile.mask); //tempColliders2 = Physics.OverlapBox(character.transform.position, new Vector3(50f, 50f, 50f), character.transform.rotation, LayerIndex.entityPrecise.mask); //if (tempColliders.Length > 0) //{ // foreach (Collider col in tempColliders) // { // if (col.gameObject.transform.root.GetComponentInChildren<RoR2.Projectile.ProjectileController>().owner!=character.gameObject) // colliderList.Add(col); // } //} //if (tempColliders2.Length > 0) //{ // foreach (Collider coll in tempColliders2) // { // if (coll.gameObject.transform.root.GetComponentInChildren<CharacterBody>() != null) // { // GameObject root = coll.gameObject.transform.root.gameObject; // if (root.GetComponentInChildren<CharacterBody>().teamComponent.teamIndex >= TeamIndex.Monster && root.GetComponentInChildren<HurtBoxGroup>().mainHurtBox.collider == coll) // colliderList.Add(coll); // } // else // { // R2API.Utils.ChatMessage.Send("Found " + coll.gameObject.name + "'s collider"); // } // } //} //if (colliderList.Contains(character.mainHurtBox.collider)) // R2API.Utils.ChatMessage.Send("Still added Samus' collider"); //if (colliderList.Count != 0) //{ //R2API.Utils.ChatMessage.Send(dt+": found " + colliderList.Count + " colliders"); //foreach (Collider item in colliderList) //{ // float tempDist = Vector3.Distance( item.transform.position,temp); // if (tempDist < dist&&item!=character.mainHurtBox.collider) // dist = tempDist; //} //R2API.Utils.ChatMessage.Send("closest dist: "+dist); //if (dist < threatDist) // threatDist = dist; //} //colliderList.Clear(); //solveEnvironentDamage(); //if(envDamage) //{ // threatDist = 0f; //} if (threatIntf.isActive(false)) { threatIntf.SetThreatDistance(threatDist); } }
private void SetPlayerShieldHelper(ref HealthComponent playerHealthComponent, ref PlayerComponent playerComponent, bool invulnerable) { playerHealthComponent.Invulnerable = invulnerable; playerComponent.Shield.SetActive(invulnerable); }