/// <summary> /// This is mainly used to update new Clients on connect. /// So we do not spam too many net messages at once for a direct /// client update, control the rate of update slowly: /// </summary> IEnumerator ControlledClientUpdate(GameObject requestor) { SendOverallUpdate(requestor); yield return(YieldHelper.DeciSecond); SendBloodUpdate(requestor); yield return(YieldHelper.DeciSecond); SendRespiratoryUpdate(requestor); yield return(YieldHelper.DeciSecond); if (livingHealthBehaviour.brainSystem != null) { SendBrainUpdate(requestor); yield return(YieldHelper.DeciSecond); } for (int i = 0; i < livingHealthBehaviour.BodyParts.Count; i++) { HealthBodyPartMessage.Send(requestor, gameObject, livingHealthBehaviour.BodyParts[i].Type, livingHealthBehaviour.BodyParts[i].BruteDamage, livingHealthBehaviour.BodyParts[i].BurnDamage); yield return(YieldHelper.DeciSecond); } }
public static void RunDamageSelf(string bodyPartString, int burnDamage, int bruteDamage) { if (CustomNetworkManager.Instance._isServer == false) { Logger.Log("Can only execute command from server."); return; } bool success = BodyPartType.TryParse(bodyPartString, true, out BodyPartType bodyPart); if (success == false) { Logger.Log("Invalid body part '" + bodyPartString + "'"); return; } bool playerSpawned = (PlayerManager.LocalPlayer != null); if (playerSpawned == false) { Logger.Log("Cannot damage player. Player has not spawned."); return; } Logger.Log("Debugger inflicting " + burnDamage + " burn damage and " + bruteDamage + " brute damage on " + bodyPart + " of " + PlayerManager.LocalPlayer.name); HealthBodyPartMessage.Send(PlayerManager.LocalPlayer, PlayerManager.LocalPlayer, bodyPart, burnDamage, bruteDamage); }
private void ServerApplyHeal(BodyPartBehaviour targetBodyPart) { targetBodyPart.HealDamage(40, healType); stackable.ServerConsume(1); HealthBodyPartMessage.Send(targetBodyPart.livingHealthBehaviour.gameObject, targetBodyPart.livingHealthBehaviour.gameObject, targetBodyPart.Type, targetBodyPart.livingHealthBehaviour.GetTotalBruteDamage(), targetBodyPart.livingHealthBehaviour.GetTotalBurnDamage()); }
public static HealthBodyPartMessage SendToAll(GameObject entityToUpdate, BodyPartType bodyPartType, float bruteDamage, float burnDamage) { HealthBodyPartMessage msg = new HealthBodyPartMessage { EntityToUpdate = entityToUpdate.GetComponent <NetworkIdentity>().netId, BodyPart = bodyPartType, BruteDamage = bruteDamage, BurnDamage = burnDamage }; msg.SendToAll(); return(msg); }
/// <summary> /// This is mainly used to update new Clients on connect. /// So we do not spam too many net messages at once for a direct /// client update, control the rate of update slowly: /// </summary> IEnumerator ControlledClientUpdate(GameObject requestor) { SendConsciousUpdate(requestor); yield return(WaitFor.Seconds(.1f)); SendOverallUpdate(requestor); yield return(WaitFor.Seconds(.1f)); SendBloodUpdate(requestor); yield return(WaitFor.Seconds(.1f)); SendRespiratoryUpdate(); yield return(WaitFor.Seconds(.1f)); SendTemperatureUpdate(); yield return(WaitFor.Seconds(.1f)); SendPressureUpdate(); yield return(WaitFor.Seconds(.1f)); if (livingHealthBehaviour.brainSystem != null) { SendBrainUpdate(requestor); yield return(WaitFor.Seconds(.1f)); } for (int i = 0; i < livingHealthBehaviour.BodyParts.Count; i++) { HealthBodyPartMessage.Send(requestor, gameObject, livingHealthBehaviour.BodyParts[i].Type, livingHealthBehaviour.BodyParts[i].BruteDamage, livingHealthBehaviour.BodyParts[i].BurnDamage); yield return(WaitFor.Seconds(.1f)); } }
public virtual void HealDamage(GameObject healingItem, int healAmt, DamageType damageTypeToHeal, BodyPartType bodyPartAim) { if (healAmt <= 0 || IsDead) { return; } if (bodyPartAim == BodyPartType.Groin) { bodyPartAim = BodyPartType.Chest; } if (bodyPartAim == BodyPartType.Eyes || bodyPartAim == BodyPartType.Mouth) { bodyPartAim = BodyPartType.Head; } if (BodyParts.Count == 0) { Logger.LogError($"There are no body parts to affect {gameObject.name}", Category.Health); return; } // See if any of the healing applied affects blood state bloodSystem.AffectBloodState(bodyPartAim, damageTypeToHeal, healAmt, true); if (damageTypeToHeal == DamageType.Brute || damageTypeToHeal == DamageType.Burn) { //Try to apply healing to the required body part bool appliedHealing = false; for (int i = 0; i < BodyParts.Count; i++) { if (BodyParts[i].Type == bodyPartAim) { BodyParts[i].HealDamage(healAmt, damageTypeToHeal); appliedHealing = true; HealthBodyPartMessage.SendToAll(gameObject, bodyPartAim, BodyParts[i].BruteDamage, BodyParts[i].BurnDamage); break; } } //If the body part does not exist then try to find the chest instead if (!appliedHealing) { var getChestIndex = BodyParts.FindIndex(x => x.Type == BodyPartType.Chest); if (getChestIndex != -1) { BodyParts[getChestIndex].HealDamage(healAmt, damageTypeToHeal); HealthBodyPartMessage.SendToAll(gameObject, bodyPartAim, BodyParts[getChestIndex].BruteDamage, BodyParts[getChestIndex].BurnDamage); } else { //If there is no default chest body part then do nothing Logger.LogError($"No chest body part found for {gameObject.name}", Category.Health); return; } } } var prevHealth = OverallHealth; Logger.LogTraceFormat("{3} received {0} {4} healing from {6} aimed for {5}. Health: {1}->{2}", Category.Health, healAmt, prevHealth, OverallHealth, gameObject.name, damageTypeToHeal, bodyPartAim, healingItem); }
public virtual void ApplyDamage(GameObject damagedBy, float damage, DamageType damageType, BodyPartType bodyPartAim = BodyPartType.Chest) { if (damage <= 0 || IsDead) { return; } if (bodyPartAim == BodyPartType.Groin) { bodyPartAim = BodyPartType.Chest; //Temporary fix for groin, when we add surgery this might need some changing. } if (bodyPartAim == BodyPartType.Eyes || bodyPartAim == BodyPartType.Mouth) { bodyPartAim = BodyPartType.Head; } LastDamageType = damageType; LastDamagedBy = damagedBy; if (BodyParts.Count == 0) { Logger.LogError($"There are no body parts to apply damage too for {gameObject.name}", Category.Health); return; } //See if damage affects the state of the blood: bloodSystem.AffectBloodState(bodyPartAim, damageType, damage); if (damageType == DamageType.Brute || damageType == DamageType.Burn) { //Try to apply damage to the required body part bool appliedDmg = false; for (int i = 0; i < BodyParts.Count; i++) { if (BodyParts[i].Type == bodyPartAim) { BodyParts[i].ReceiveDamage(damageType, damage); appliedDmg = true; HealthBodyPartMessage.SendToAll(gameObject, bodyPartAim, BodyParts[i].BruteDamage, BodyParts[i].BurnDamage); break; } } //If the body part does not exist then try to find the chest instead if (!appliedDmg) { var getChestIndex = BodyParts.FindIndex(x => x.Type == BodyPartType.Chest); if (getChestIndex != -1) { BodyParts[getChestIndex].ReceiveDamage(damageType, damage); HealthBodyPartMessage.SendToAll(gameObject, bodyPartAim, BodyParts[getChestIndex].BruteDamage, BodyParts[getChestIndex].BurnDamage); } else { //If there is no default chest body part then do nothing Logger.LogError($"No chest body part found for {gameObject.name}", Category.Health); return; } } } //For special effects spawning like blood: DetermineDamageEffects(damageType); var prevHealth = OverallHealth; Logger.LogTraceFormat("{3} received {0} {4} damage from {6} aimed for {5}. Health: {1}->{2}", Category.Health, damage, prevHealth, OverallHealth, gameObject.name, damageType, bodyPartAim, damagedBy); }