public virtual bool TakeDamage(WIMaterialType materialType, Vector3 damagePoint, float attemptedDamage, Vector3 attemptedForce, string damageSource, out float actualDamage, out bool isDead) { actualDamage = attemptedDamage; isDead = false; TotalDamage += actualDamage; return(true); }
public static int MatTypeToInt(WIMaterialType mat) { switch (mat) { case WIMaterialType.Stone: return(1); case WIMaterialType.Bone: return(2); case WIMaterialType.Crystal: return(3); case WIMaterialType.Fabric: return(4); case WIMaterialType.Glass: return(5); case WIMaterialType.Wood: return(2); case WIMaterialType.Plant: return(4); case WIMaterialType.Metal: return(5); default: return(1); } }
public virtual bool TakeDamage(WIMaterialType materialType, Vector3 damagePoint, float attemptedDamage, Vector3 attemptedForce, string damageSource, out float actualDamage, out bool isDead) { actualDamage = attemptedDamage; isDead = false; State.TotalDamage += actualDamage; if (HasPlayerFocus) { GUIHud.Get.ShowProgressBar(Colors.Get.GeneralHighlightColor, Colors.Darken(Colors.Get.GenericNeutralValue), NormalizedDamage); } if (State.SpawnOnDamaage && State.TotalDamage >= State.SpawnDamageMinimum) //reset { State.TotalDamage = 0f; //spawn a thing WorldItem worlditem = null; if (WorldItems.CloneRandomFromCategory(State.SpawnCategory, ParentChunk.AboveGroundGroup, out worlditem)) { //spit it out at the player Vector3 direction = (Player.Local.Position - damagePoint).normalized * 5f; worlditem.tr.parent = ParentChunk.AboveGroundGroup.transform; worlditem.tr.position = damagePoint; worlditem.Props.Local.FreezeOnStartup = false; worlditem.Props.Local.Transform.CopyFrom(worlditem.tr); worlditem.Initialize(); worlditem.SetMode(WIMode.World); worlditem.ApplyForce(direction, damagePoint); FXManager.Get.SpawnFX(worlditem.tr, "DrawAttentionToItem"); worlditem.GetOrAdd <DespawnOnPlayerLeave>(); } } return(true); }
public float BaseArmorReductionMultiplier(WIMaterialType damageSourceMaterial, WIMaterialType armorMaterial) { float multiplier = 1.0f; KeyValuePair <WIMaterialType, WIMaterialType> pair = new KeyValuePair <WIMaterialType, WIMaterialType> (damageSourceMaterial, armorMaterial); MaterialArmorMatrix.TryGetValue(pair, out multiplier); return(multiplier); }
public float BaseWeaponDamageMultiplier(WIMaterialType weaponMaterial, WIMaterialType objectMaterial) { float multiplier = 1.0f; KeyValuePair <WIMaterialType, WIMaterialType> pair = new KeyValuePair <WIMaterialType, WIMaterialType> (weaponMaterial, objectMaterial); MaterialDamageMatrix.TryGetValue(pair, out multiplier); return(multiplier); }
public int ArmorLevel(WIMaterialType type) { //use the lookup we generated earlier if (mArmorLevelLookup.ContainsKey(type)) { return(mArmorLevelLookup[type]); } return(0); }
public int ArmorLevel(WIMaterialType materialType) { if (Flags.Check((uint)MaterialTypes, (uint)materialType, Flags.CheckType.MatchAny)) { return(BaseDamageProtection); } return(0); }
public float BaseFallDamageMultiplier(WIMaterialType groundMaterial, WIMaterialType fallingObjectMaterial) { float multiplier = 1.0f; KeyValuePair <WIMaterialType, WIMaterialType> pair = new KeyValuePair <WIMaterialType, WIMaterialType> (groundMaterial, fallingObjectMaterial); MaterialDamageMatrix.TryGetValue(pair, out multiplier); return(multiplier); }
public int ArmorLevel(WIMaterialType materialType) { Armor armor = null; if (worlditem.Has <Armor> (out armor)) { return(armor.ArmorLevel(materialType)); } return(0); }
public void InstantKill(WIMaterialType type, string causeOfDeath, bool spawnDamage) { State.LastDamageTaken = Mathf.Clamp((State.Durability - State.DamageTaken), 0f, Mathf.Infinity); State.LastDamagePoint = transform.position; State.LastDamageMaterial = WIMaterialType.None; State.CauseOfDeath = causeOfDeath; if (spawnDamage) { //spawn damage } worlditem.SetMode(WIMode.Destroyed); }
public string MaterialTypeToFXType(WIMaterialType type) { switch (type) { case WIMaterialType.Bone: return(BoneDamageFX); case WIMaterialType.Crystal: return(CrystalDamageFX); case WIMaterialType.Dirt: default: return(DirtDamageFX); case WIMaterialType.Fabric: return(FabricDamageFX); case WIMaterialType.Fire: return(FireDamageFX); case WIMaterialType.Flesh: return(FleshDamageFX); case WIMaterialType.Food: return(FoodDamageFX); case WIMaterialType.Glass: return(GlassDamageFX); case WIMaterialType.Ice: return(IceDamageFX); case WIMaterialType.Liquid: return(LiquidDamageFX); case WIMaterialType.Metal: return(MetalDamageFX); case WIMaterialType.Plant: return(PlantDamageFX); case WIMaterialType.Stone: return(StoneDamageFX); case WIMaterialType.Wood: return(WoodDamageFX); } }
public static WIMaterialType GroundTypeToMaterialType(GroundType type) { WIMaterialType material = WIMaterialType.Dirt; switch (type) { case GroundType.Stone: material = WIMaterialType.Stone; break; case GroundType.Wood: material = WIMaterialType.Wood; break; case GroundType.Leaves: material = WIMaterialType.Plant; break; case GroundType.Metal: material = WIMaterialType.Metal; break; case GroundType.Water: material = WIMaterialType.Liquid; break; case GroundType.Mud: material = WIMaterialType.Dirt; break; case GroundType.Snow: material = WIMaterialType.Dirt; break; default: break; } return(material); }
public bool TakeDamage(WIMaterialType materialType, Vector3 damagePoint, float attemptedDamage, Vector3 attemptedForce, string source, out float actualDamage, out bool isDead) { if (player.IsHijacked || !player.HasSpawned) { isDead = false; actualDamage = 0f; return(false); } if (attemptedDamage < MinimumDamageThreshold || !mInitialized || !player.HasSpawned) { isDead = false; actualDamage = 0.0f; return(false); } bool hasDamageAbsorber = false; if (player.Carrier.HasWorldItem) { hasDamageAbsorber = player.Carrier.worlditem.Is <Shield> (out DamageAbsorber); } else if (player.Tool.HasWorldItem) { hasDamageAbsorber = player.Tool.worlditem.Is <Shield> (out DamageAbsorber); } //do we have a shield? if so pass the damage along to the shield //other armor stuff has already been calculated by the damage manager //this is the only bit that it can't know about //(on characters a shield is treated as a piece of armor) if (hasDamageAbsorber) { bool absorberIsDead = false; bool absorbedDamage = DamageAbsorber.worlditem.Get <Damageable> ().TakeDamage( materialType, damagePoint, attemptedDamage, attemptedForce, source, out actualDamage, out absorberIsDead); isDead = false; //obviously since the absorber took the heat return(absorbedDamage); } if (source == "FallDamage") { //fall damage can't kill you unless it's above the death threshold if (DamageLeft < attemptedDamage) { attemptedDamage = DamageLeft - 1f; } } //otherwise just take the damage actualDamage = attemptedDamage; DamageLastTaken = actualDamage; DamageLastSource = source; isDead = IsDead; //we don't set actual death here Player.Local.Status.ReduceStatus(actualDamage / MeterValueMultiplier, "Health"); Player.Local.FPSCamera.DoBomb(Vector3.one, 0.0001f * attemptedForce.magnitude, 0.001f * attemptedForce.magnitude); Player.Local.FPSController.AddSoftForce(attemptedForce, 3f); Player.Get.AvatarActions.ReceiveAction(AvatarAction.SurvivalTakeDamage, WorldClock.AdjustedRealTime); return(true); }
public void SendDamage(DamagePackage damage, BodyPart bodyPart) { damageReceiver = damage.Target; damageHandler = null; damageWorldItem = null; damage.OnPackageSent.SafeInvoke(); if (damageReceiver != null) { //check if it's a player because it's the eaiest switch (damageReceiver.IOIType) { case ItemOfInterestType.Player: damageHandler = Player.Local.DamageHandler; break; case ItemOfInterestType.WorldItem: Damageable damageable = null; damageWorldItem = damageReceiver.worlditem; if (damageReceiver.worlditem.Is <Damageable> (out damageable)) { damageHandler = damageable; } else { //if it's an instant kill, destroy it now if (damage.InstantKill) { Debug.Log("Instant kill in damage manager"); damage.HitTarget = true; damage.TargetIsDead = true; damage.DamageDealt = damage.DamageSent; damageReceiver.worlditem.RemoveFromGame(); return; } } break; case ItemOfInterestType.Scenery: DamageableChild dc = null; if (damageReceiver.gameObject.HasComponent <DamageableChild> (out dc)) //get the parent from the damageable child { damageHandler = dc.DamageableParent; } else { //if it's not a world item and it's not a body part check for a general damage handler //this includes the player's damage handler damageHandler = (IDamageable)damageReceiver.gameObject.GetComponent(typeof(IDamageable)); } break; default: break; } } //apply damage using the damage handler if (damageHandler != null) { receiverMaterial = damageHandler.BaseMaterialType; receiverArmorMaterials = damageHandler.ArmorMaterialTypes; int receiverArmorLevel = 0; if (receiverArmorMaterials != WIMaterialType.None) { receiverArmorLevel = damageHandler.ArmorLevel(receiverArmorMaterials); } //get damage multiplier for material types //TODO re-enable these //damage.DamageSent = damage.DamageSent * BaseWeaponDamageMultiplier (damage.SenderMaterial, receiverMaterial); //damage.DamageSent = damage.DamageSent * BaseArmorReductionMultiplier (damage.SenderMaterial, receiverArmorMaterials); //check if there's a material bonus for this damage sender if (damage.MaterialBonus != WIMaterialType.None) { if (Flags.Check((uint)receiverMaterial, (uint)damage.MaterialBonus, Flags.CheckType.MatchAny)) { damage.DamageSent *= Globals.DamageMaterialBonusMultiplier; } } if (damage.MaterialPenalty != WIMaterialType.None) { if (Flags.Check((uint)receiverMaterial, (uint)damage.MaterialPenalty, Flags.CheckType.MatchAny)) { damage.DamageSent *= Globals.DamageMaterialPenaltyMultiplier; } } damageHandler.LastDamageSource = damage.Source; //this has a good chance of being null damageHandler.LastBodyPartHit = bodyPart; if (damage.InstantKill) { damageHandler.InstantKill(damage.Source); } else { damage.HitTarget = damageHandler.TakeDamage(damage.SenderMaterial, damage.Point, damage.DamageSent, damage.Force, damage.SenderName, out damage.DamageDealt, out damage.TargetIsDead); } if (damage.HitTarget) { SpawnDamageFX(damage.Point, receiverMaterial, damage.DamageDealt); PlayDamageSound(damage.Point, receiverMaterial, damage.DamageDealt); if (bodyPart != null && !damage.TargetIsDead) { switch (bodyPart.Type) { case BodyPartType.Eye: GUI.GUIManager.PostSuccess("Inflicted eye wound"); damage.DamageSent = Globals.DamageBodyPartEyeMultiplier; break; case BodyPartType.Head: case BodyPartType.Face: case BodyPartType.Neck: GUI.GUIManager.PostSuccess("Inflicted head wound"); damage.DamageSent *= Globals.DamageBodyPartHeadMultiplier; break; case BodyPartType.Chest: case BodyPartType.Hip: case BodyPartType.Segment: case BodyPartType.Shoulder: case BodyPartType.None: default: GUI.GUIManager.PostSuccess("Inflicted torso wound"); damage.DamageSent *= Globals.DamageBodyPartTorsoMultiplier; break; case BodyPartType.Finger: case BodyPartType.Hand: case BodyPartType.Wrist: case BodyPartType.Arm: case BodyPartType.Foot: case BodyPartType.Shin: case BodyPartType.Leg: GUI.GUIManager.PostSuccess("Inflicted limb wound"); damage.DamageSent *= Globals.DamageBodyPartLimbMultiplier; break; } } } damage.OnPackageReceived.SafeInvoke(); } else { //if we didn't find a damage handler but we did find a worlditem //send force to the worlditem so it doesn't just sit there if (damageWorldItem != null) { damageWorldItem.ApplyForce(damage.Force, damage.Point); } } //play the sender's fx no matter what SpawnDamageFX(damage.Point, damage.SenderMaterial, damage.DamageDealt); PlayDamageSound(damage.Point, damage.SenderMaterial, damage.DamageDealt); }
public int ArmorLevel(WIMaterialType materialType) { return(0); }
public int ArmorLevel(WIMaterialType type) { return(player.Wearables.ArmorLevel(type)); }
public void SpawnDamageFX(Vector3 point, WIMaterialType type, float intensity) { FXManager.Get.SpawnFX(point, MaterialTypeToFXType(type)); }
public void PlayDamageSound(Vector3 point, WIMaterialType type, float intensity) { mDamageAudioSource.position = point; MasterAudio.PlaySound(MasterAudio.SoundType.Damage, mDamageAudioSource, MaterialTypeToSoundType(type)); }
public static int CalculateLocalPrice(int basePrice, IWIBase item) { if (item == null) { Debug.Log("Local price in recepticle null, returning"); return(basePrice); } int sizeMult = (int)item.Size; int matMult = 1; WIMaterialType mat = WIMaterialType.Dirt; if (item.IsWorldItem) { mat = item.worlditem.Props.Global.MaterialType; } else { mat = item.GetStackItem(WIMode.None).GlobalProps.MaterialType; } switch (mat) { case WIMaterialType.Stone: matMult = 10; break; case WIMaterialType.Bone: matMult = 15; break; case WIMaterialType.Crystal: matMult = 20; break; case WIMaterialType.Fabric: matMult = 3; break; case WIMaterialType.Glass: matMult = 8; break; case WIMaterialType.Wood: matMult = 7; break; case WIMaterialType.Plant: matMult = 11; break; case WIMaterialType.Metal: matMult = 13; break; default: break; } basePrice *= sizeMult; basePrice *= matMult; if (item.IsStackContainer) { for (int i = 0; i < item.StackContainer.StackList.Count; i++) { for (int j = 0; j < item.StackContainer.StackList [i].Items.Count; j++) { basePrice += Mathf.CeilToInt(item.StackContainer.StackList [i].Items [j].BaseCurrencyValue); } } } return(basePrice); }
public void RefreshClothing() { if (mArmorLevelLookup == null) { //haven't initialized yet mArmorLevelLookup = new Dictionary <WIMaterialType, int>(); mAllMaterialTypes = new List <WIMaterialType>(); WIMaterialType[] enumTypes = (WIMaterialType[])Enum.GetValues(typeof(WIMaterialType)); mAllMaterialTypes.AddRange(enumTypes); } else { mArmorLevelLookup.Clear(); } //add all possible material types to the lookup so we don't have to check for keys later for (int i = 0; i < mAllMaterialTypes.Count; i++) { mArmorLevelLookup.Add(mAllMaterialTypes[i], 0); } ArmorMaterialTypes = WIMaterialType.None; ColdProtection = 0; HeatProtection = 0; DamageProtection = 0; EnergyProtection = 0; VisibilityChange = 0; StrengthChange = 0; for (int i = 0; i < State.UpperBodyContainer.StackList.Count; i++) { mCheckStack = State.UpperBodyContainer.StackList[i]; if (mCheckStack.HasTopItem) { mCheckItem = mCheckStack.TopItem; ////Debug.Log("Container has top item " + mCheckItem.FileName); if (WorldItems.Get.PackPrefab(mCheckItem.PackName, mCheckItem.PrefabName, out mCheckWearableWorldItem)) { if (mCheckWearableWorldItem.Is <Wearable>(out mCheckWearable)) { ColdProtection += mCheckWearable.ColdProtection; HeatProtection += mCheckWearable.HeatProtection; EnergyProtection += mCheckWearable.EnergyProtection; VisibilityChange += mCheckWearable.VisibilityChange; StrengthChange += mCheckWearable.StrengthChange; } if (mCheckWearableWorldItem.Is <Armor>(out mCheckArmor)) { DamageProtection += mCheckArmor.BaseDamageProtection; ArmorMaterialTypes |= mCheckArmor.MaterialTypes; } } } } for (int i = 0; i < State.LowerBodyContainer.StackList.Count; i++) { mCheckStack = State.LowerBodyContainer.StackList[i]; if (mCheckStack.HasTopItem) { mCheckItem = mCheckStack.TopItem; ////Debug.Log("Container has top item " + mCheckItem.FileName); if (WorldItems.Get.PackPrefab(mCheckItem.PackName, mCheckItem.PrefabName, out mCheckWearableWorldItem)) { if (mCheckWearableWorldItem.Is <Wearable>(out mCheckWearable)) { ColdProtection += mCheckWearable.ColdProtection; HeatProtection += mCheckWearable.HeatProtection; EnergyProtection += mCheckWearable.EnergyProtection; VisibilityChange += mCheckWearable.VisibilityChange; StrengthChange += mCheckWearable.StrengthChange; } if (mCheckWearableWorldItem.Is <Armor>(out mCheckArmor)) { //add the armor's general damage protection DamageProtection += mCheckArmor.BaseDamageProtection; //add its specific kinds of protection to the lookup //check each material type and see if the armor protects against it for (int j = 0; j < mAllMaterialTypes.Count; j++) { mArmorLevelLookup[mAllMaterialTypes[j]] = mArmorLevelLookup[mAllMaterialTypes[j]] + mCheckArmor.ArmorLevel(mAllMaterialTypes[j]); } } } } } }
protected void AddMaterialEntry(WIMaterialType dealer, WIMaterialType recipient, float multiplier) { //KeyValuePair <WIMaterialType, WIMaterialType> entry = new KeyValuePair <WIMaterialType, WIMaterialType> (dealer, recipient); //MaterialDamageMatrix.Add (entry, multiplier); }
public bool IsMadeOf(WIMaterialType materialType) { return(Frontiers.Flags.Check((uint)Props.Global.MaterialType, (uint)materialType, Frontiers.Flags.CheckType.MatchAny)); }
protected void AddArmorEntry(WIMaterialType dealer, WIMaterialType armor, float multiplier) { //KeyValuePair <WIMaterialType, WIMaterialType> entry = new KeyValuePair <WIMaterialType, WIMaterialType> (dealer, armor); //MaterialDamageMatrix.Add (entry, multiplier); }
public void TakeFallDamage(float fallImpact) { if (WorldClock.AdjustedRealTime < (player.LastSpawnTime + gMinimumTimeBeforeFallDamage)) { Debug.Log("Fall damage attempted before minimum spawn time elapsed, ignoring"); return; } if (player.IsHijacked || !player.HasSpawned) { return; } float actualDamage; float attemptedDamage = fallImpact * Globals.FallDamageImpactMultiplier; bool isDead; float impactThreshold = Mathf.Infinity; float deathThreshold = Mathf.Infinity; float breakBoneThreshold = Mathf.Infinity; switch (Profile.Get.CurrentGame.Difficulty.FallDamage) { case FallDamageStyle.None: //don't do anything return; case FallDamageStyle.Forgiving: attemptedDamage *= Globals.DamageFallDamageForgivingMultiplier; deathThreshold = Globals.DamageFallDamageForgivingImpactDeathThreshold; impactThreshold = Globals.DamageFallDamageForgivingImpactThreshold; breakBoneThreshold = Globals.DamageFallDamageForgivingBrokenBoneThreshold; break; case FallDamageStyle.Realistic: attemptedDamage *= Globals.DamageFallDamageRealisticMultiplier; deathThreshold = Globals.DamageFallDamageRealisticImpactDeathThreshold; impactThreshold = Globals.DamageFallDamageRealisticImpactThreshold; breakBoneThreshold = Globals.DamageFallDamageRealisticBrokenBoneThreshold; break; } if (attemptedDamage < impactThreshold) { return; } else if (attemptedDamage > deathThreshold) { player.Die("FallDamage"); return; } else { WIMaterialType fallOn = DamageManager.GroundTypeToMaterialType(Player.Local.Surroundings.State.GroundBeneathPlayer); TakeDamage(fallOn, Player.Local.Position, attemptedDamage, Vector3.zero, "FallDamage", out actualDamage, out isDead); bool breakBone = false; if (actualDamage >= breakBoneThreshold) { breakBone = true; } else if (actualDamage >= breakBoneThreshold) //TODO move these to globals { if (Random.value < 0.1f) { breakBone = true; } } if (breakBone) { Player.Local.Status.AddCondition("BrokenBone"); } } }
public virtual bool TakeDamage(WIMaterialType materialType, Vector3 damagePoint, float attemptedDamage, Vector3 attemptedForce, string sourceName, out float actualDamage, out bool isDead) { if (!mInitialized) { actualDamage = 0f; isDead = false; return(false); } if (State.IsDead) { actualDamage = 0.0f; isDead = true; worlditem.ApplyForce(attemptedForce, damagePoint); if (LastBodyPartHit != null) { LastBodyPartHit.ForceOnConvertToRagdoll = attemptedForce; } return(false); } actualDamage = attemptedDamage; //this is where we apply body part modifiers and succeptibilities if (Flags.Check((uint)State.MaterialPenalties, (uint)materialType, Flags.CheckType.MatchAny)) { actualDamage *= Globals.DamageMaterialBonusMultiplier; //apply the bonus to this source } else if (Flags.Check((uint)State.MaterialBonuses, (uint)materialType, Flags.CheckType.MatchAny)) { actualDamage *= Globals.DamageMaterialPenaltyMultiplier; //apply the penalty to this source } if (State.SourcePenalties.Contains(sourceName)) { actualDamage *= Globals.DamageMaterialBonusMultiplier; //apply the bonus to this source } else if (State.SourceBonuses.Contains(sourceName)) { actualDamage *= Globals.DamageMaterialPenaltyMultiplier; //apply the penalty to this source } if (actualDamage > State.MinimumDamageThreshold) { //if we haven't taken a reputation penalty for damaging someone else's property //check and see if we're owned by someone else if (!State.HasCausedReputationPenalty) { if (WorldItems.IsOwnedBySomeoneOtherThanPlayer(worlditem, out mCheckOwner)) { //TODO tie reputation loss to item value Profile.Get.CurrentGame.Character.Rep.LosePersonalReputation(mCheckOwner.worlditem.FileName, mCheckOwner.worlditem.DisplayName, 1); State.HasCausedReputationPenalty = true; } } State.LastDamagePoint = damagePoint; State.LastDamageMaterial = materialType; State.LastDamageSource = sourceName; State.LastDamageForce = attemptedForce; State.LastDamageTaken = actualDamage; State.DamageTaken += actualDamage; //see if the force exceeds our 'throw' threshold if (attemptedForce.magnitude > State.MinimumForceThreshold) { if (ApplyForceAutomatically) { worlditem.ApplyForce(attemptedForce, damagePoint); } else { OnForceApplied.SafeInvoke(); } } if (LastBodyPartHit != null) { LastBodyPartHit.ForceOnConvertToRagdoll = attemptedForce; } //now that we've set everything up, send the damage messages OnTakeDamage.SafeInvoke(); if (actualDamage >= State.OverkillDamageThreshold) { State.LastDamageTaken = actualDamage * State.OverkillDamageMultiplier; State.DamageTaken += actualDamage * State.OverkillDamageMultiplier; OnTakeOverkillDamage.SafeInvoke(); } else if (actualDamage >= State.CriticalDamageThreshold) { State.LastDamageTaken = actualDamage * State.CriticalDamageMultiplier; State.DamageTaken += actualDamage * State.CriticalDamageMultiplier; OnTakeCriticalDamage.SafeInvoke(); } //now check to see if we're dead isDead = State.IsDead; if (isDead) { OnDieResult(); } return(true); } isDead = false; return(false); }