// RimWorld.Verb_MeleeAttack public static void DamageInfosToApply_PostFix(Verb_MeleeAttack __instance, ref IEnumerable <DamageInfo> __result, LocalTargetInfo target) { List <DamageInfo> newList = new List <DamageInfo>(); //__result = null; ThingWithComps ownerEquipment = __instance.ownerEquipment; if (ownerEquipment != null) { //Log.Message("1"); ThingComp comp = ownerEquipment.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable); if (comp != null) { //Log.Message("2"); CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable; if (compSlotLoadable.Slots != null && compSlotLoadable.Slots.Count > 0) { //Log.Message("3"); List <SlotLoadable> statSlots = compSlotLoadable.Slots.FindAll((SlotLoadable z) => !z.IsEmpty() && ((SlotLoadableDef)z.def).doesChangeStats == true); if (statSlots != null && statSlots.Count > 0) { //Log.Message("4"); foreach (SlotLoadable slot in statSlots) { //Log.Message("5"); CompSlottedBonus slotBonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>(); if (slotBonus != null) { //Log.Message("6"); Type superClass = __instance.GetType().BaseType; if (slotBonus.Props.damageDef != null) { //Log.Message("7"); float num = __instance.verbProps.AdjustedMeleeDamageAmount(__instance, __instance.CasterPawn, __instance.ownerEquipment); DamageDef def = __instance.verbProps.meleeDamageDef; BodyPartGroupDef weaponBodyPartGroup = null; HediffDef weaponHediff = null; if (__instance.CasterIsPawn) { //Log.Message("8"); if (num >= 1f) { weaponBodyPartGroup = __instance.verbProps.linkedBodyPartsGroup; if (__instance.ownerHediffComp != null) { weaponHediff = __instance.ownerHediffComp.Def; } } else { num = 1f; def = DamageDefOf.Blunt; } } //Log.Message("9"); ThingDef def2; if (__instance.ownerEquipment != null) { def2 = __instance.ownerEquipment.def; } else { def2 = __instance.CasterPawn.def; } //Log.Message("10"); Vector3 angle = (target.Thing.Position - __instance.CasterPawn.Position).ToVector3(); //Log.Message("11"); Thing caster = __instance.caster; //Log.Message("12"); int newdamage = GenMath.RoundRandom(num); // Log.Message("applying damage "+newdamage+" out of "+num); DamageInfo damageInfo = new DamageInfo(slotBonus.Props.damageDef, newdamage, -1f, caster, null, def2); damageInfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside); damageInfo.SetWeaponBodyPartGroup(weaponBodyPartGroup); damageInfo.SetWeaponHediff(weaponHediff); damageInfo.SetAngle(angle); //Log.Message("13"); newList.Add(damageInfo); __result = newList.AsEnumerable <DamageInfo>(); } SlotBonusProps_VampiricEffect vampiricEffect = slotBonus.Props.vampiricHealChance; if (vampiricEffect != null) { //Log.Message("vampiricHealingCalled"); float randValue = Rand.Value; //Log.Message("randValue = " + randValue.ToString()); if (randValue <= vampiricEffect.chance) { MoteMaker.ThrowText(__instance.CasterPawn.DrawPos, __instance.CasterPawn.Map, "Vampiric Effect: Success", 6f); //MoteMaker.ThrowText(__instance.CasterPawn.DrawPos, __instance.CasterPawn.Map, "Success".Translate(), 6f); ApplyHealing(__instance.caster, vampiricEffect.woundLimit, target.Thing); } } } } } } } } }
public virtual string SlotDesc(SlotLoadable slot) { StringBuilder s = new StringBuilder(); s.AppendLine(slot.GetDescription()); if (!slot.IsEmpty()) { s.AppendLine(); s.AppendLine(string.Format(StringOf.CurrentlyLoaded, new object[] { slot.SlotOccupant.LabelCap })); if (((SlotLoadableDef)slot.def).doesChangeColor) { s.AppendLine(); s.AppendLine(StringOf.Effects); s.AppendLine(" " + StringOf.ChangesPrimaryColor); } if (((SlotLoadableDef)slot.def).doesChangeStats) { CompSlottedBonus slotBonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>(); if (slotBonus != null) { if (slotBonus.Props != null) { if (slotBonus.Props.statModifiers != null && slotBonus.Props.statModifiers.Count > 0) { s.AppendLine(); s.AppendLine(StringOf.StatModifiers); foreach (StatModifier mod in slotBonus.Props.statModifiers) { float v = DetermineSlottableStatAugment(slot.SlotOccupant, mod.stat); string modstring = mod.stat.ValueToString(v, ToStringNumberSense.Offset); //Log.Message("Determined slot stat augment "+v+" and made string "+modstring); s.AppendLine(" " + mod.stat.LabelCap + " " + modstring); //s.AppendLine("\t" + mod.stat.LabelCap + " " + mod.ToStringAsOffset); } /* * //Log.Message("fix this to display statModifiers"); * List<StatModifier> statMods = slot.SlotOccupant.def.statBases.FindAll( * (StatModifier z) => z.stat.category == StatCategoryDefOf.Weapon || * z.stat.category == StatCategoryDefOf.EquippedStatOffsets); * if (statMods != null && statMods.Count > 0) * { * s.AppendLine(); * s.AppendLine("StatModifiers".Translate() + ":"); * foreach (StatModifier mod in statMods) * { * s.AppendLine("\t" + mod.stat.LabelCap + " " + mod.ToStringAsOffset); * } * } */ } DamageDef damageDef = slotBonus.Props.damageDef; if (damageDef != null) { s.AppendLine(); s.AppendLine(string.Format(StringOf.DamageType, new object[] { damageDef.LabelCap })); } SlotBonusProps_DefensiveHealChance defHealChance = slotBonus.Props.defensiveHealChance; if (defHealChance != null) { string healText = StringOf.all; if (defHealChance.woundLimit != 0) { healText = defHealChance.woundLimit.ToString(); } s.AppendLine(" " + string.Format(StringOf.DefensiveHealChance, new object[] { healText, defHealChance.chance.ToStringPercent() })); } SlotBonusProps_VampiricEffect vampChance = slotBonus.Props.vampiricHealChance; if (vampChance != null) { string vampText = StringOf.all; if (vampChance.woundLimit != 0) { vampText = defHealChance.woundLimit.ToString(); } s.AppendLine(" " + string.Format(StringOf.VampiricChance, new object[] { vampText, vampChance.chance.ToStringPercent() })); } } } } } return(s.ToString()); }