custom melee attack?

Started by eatKenny, February 09, 2016, 02:53:10 PM

Previous topic - Next topic

eatKenny

hi, i want to make the sledgehammer from my mod "High Caliber" to deal double damage to the buildings, and when attacking human or animal it has 25% chance to stun them(like bullet stun chance). i was editing the verb_MeleeAttack but seems not working:/

any one want to help?

skullywag

Just checking you did set the custom verb on the weapon right?
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

eatKenny

Quote from: skullywag on February 09, 2016, 02:57:30 PM
Just checking you did set the custom verb on the weapon right?

yes, however it appears the damage is 5 dmg "human fist", not even the damage of the sledgehammer.

skullywag

if youve defined a damagedef in the verb (e.g <meleeDamageDef>Blunt</meleeDamageDef> then you just have done something wrong in the custom verb, upload it ill take a look.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

eatKenny

Quote from: skullywag on February 09, 2016, 03:24:58 PM
if youve defined a damagedef in the verb (e.g <meleeDamageDef>Blunt</meleeDamageDef> then you just have done something wrong in the custom verb, upload it ill take a look.

i just copied the verb_MeleeAttack and made some changes, not on the stun effect yet, but the 2x damage to buildings already failed :-[


using System;
using UnityEngine;
using Verse;
using Verse.Sound;
using RimWorld;

namespace HighCaliberCore
{
public class Verb_MeleeAttackSH : Verb
    {
private const int TargetCooldown = 50;

private const float DefaultHitChance = 0.6f;

private static readonly SoundDef DefaultSoundMeleeHitPawn = SoundDef.Named("Pawn_Melee_Punch_HitPawn");

private static readonly SoundDef DefaultSoundMeleeHitBuilding = SoundDef.Named("Pawn_Melee_Punch_HitBuilding");

private static readonly SoundDef DefaultSoundMeleeMiss = SoundDef.Named("Pawn_Melee_Punch_Miss");

protected override bool TryCastShot()
{
Pawn casterPawn = base.CasterPawn;
if (casterPawn.stances.FullBodyBusy)
{
return false;
}
Thing thing = this.currentTarget.Thing;
Pawn pawn = this.currentTarget.Thing as Pawn;
if (!base.CanHitTarget(thing))
{
Log.Warning(string.Concat(new object[]
{
casterPawn,
" meleed ",
thing,
" from out of melee position."
}));
}
casterPawn.drawer.rotator.FaceCell(thing.Position);
bool flag = thing.def.category != ThingCategory.Pawn || pawn.Downed || pawn.GetPosture() != PawnPosture.Standing;
float num = (float)this.verbProps.AdjustedMeleeDamageAmount(this, base.CasterPawn, this.ownerEquipment);
DamageDef def = this.verbProps.meleeDamageDef;
BodyPartGroupDef linkedBodyPartGroup = null;
HediffDef linkedHediffDef = null;
if (base.CasterIsPawn)
{
if (num >= 1f)
{
linkedBodyPartGroup = this.verbProps.linkedBodyPartsGroup;
if (this.ownerHediffComp != null)
{
linkedHediffDef = this.ownerHediffComp.Def;
}
}
else
{
num = 1f;
def = DamageDefOf.Blunt;
}
}
BodyPartDamageInfo value = new BodyPartDamageInfo(null, new BodyPartDepth?(BodyPartDepth.Outside));
ThingDef def2;
if (this.ownerEquipment != null)
{
def2 = this.ownerEquipment.def;
}
else
{
def2 = casterPawn.def;
}
DamageInfo dinfo = new DamageInfo(def, Mathf.RoundToInt(num), this.caster, (thing.Position - casterPawn.Position).ToVector3(), new BodyPartDamageInfo?(value), def2);
            DamageInfo dinfo_Building = new DamageInfo(def, Mathf.RoundToInt(num * 2), this.caster, (thing.Position - casterPawn.Position).ToVector3(), new BodyPartDamageInfo?(value), def2);
            dinfo.SetLinkedBodyPartGroup(linkedBodyPartGroup);
dinfo.SetLinkedHediffDef(linkedHediffDef);
float num2;
if (!flag)
{
if (casterPawn.skills != null)
{
num2 = casterPawn.GetStatValue(StatDefOf.MeleeHitChance, true);
casterPawn.skills.Learn(SkillDefOf.Melee, 150f);
}
else
{
num2 = 0.6f;
}
}
else
{
num2 = 1f;
}
bool result;
SoundDef soundDef;
if (Rand.Value < num2)
{
result = true;
if (thing.def.category == ThingCategory.Building)
{
                    thing.TakeDamage(dinfo_Building);
                    soundDef = this.SoundHitBuilding();
}
else
{
                    thing.TakeDamage(dinfo);
                    soundDef = this.SoundHitPawn();
}
}
else
{
result = false;
soundDef = this.SoundMiss();
}
soundDef.PlayOneShot(thing.Position);
casterPawn.drawer.Notify_MeleeAttackOn(thing);
if (pawn != null && !pawn.Dead)
{
Stance_Cooldown stance_Cooldown = pawn.stances.curStance as Stance_Cooldown;
if (stance_Cooldown == null || stance_Cooldown.ticksLeft >= 50)
{
pawn.stances.SetStance(new Stance_Cooldown(50, null));
}
pawn.mindState.meleeThreat = casterPawn;
pawn.mindState.lastMeleeThreatHarmTick = Find.TickManager.TicksGame;
}
casterPawn.drawer.rotator.FaceCell(thing.Position);
if (casterPawn.caller != null)
{
casterPawn.caller.Notify_DidMeleeAttack();
}
return result;
}

private SoundDef SoundHitPawn()
{
if (this.ownerEquipment != null && this.ownerEquipment.Stuff != null)
{
if (this.verbProps.meleeDamageDef.armorCategory == DamageArmorCategory.Sharp)
{
if (!this.ownerEquipment.Stuff.stuffProps.soundMeleeHitSharp.NullOrUndefined())
{
return this.ownerEquipment.Stuff.stuffProps.soundMeleeHitSharp;
}
}
else if (!this.ownerEquipment.Stuff.stuffProps.soundMeleeHitBlunt.NullOrUndefined())
{
return this.ownerEquipment.Stuff.stuffProps.soundMeleeHitBlunt;
}
}
if (base.CasterPawn != null && !base.CasterPawn.def.race.soundMeleeHitPawn.NullOrUndefined())
{
return base.CasterPawn.def.race.soundMeleeHitPawn;
}
return Verb_MeleeAttackSH.DefaultSoundMeleeHitPawn;
}

private SoundDef SoundHitBuilding()
{
if (this.ownerEquipment != null && this.ownerEquipment.Stuff != null)
{
if (this.verbProps.meleeDamageDef.armorCategory == DamageArmorCategory.Sharp)
{
if (!this.ownerEquipment.Stuff.stuffProps.soundMeleeHitSharp.NullOrUndefined())
{
return this.ownerEquipment.Stuff.stuffProps.soundMeleeHitSharp;
}
}
else if (!this.ownerEquipment.Stuff.stuffProps.soundMeleeHitBlunt.NullOrUndefined())
{
return this.ownerEquipment.Stuff.stuffProps.soundMeleeHitBlunt;
}
}
if (base.CasterPawn != null && !base.CasterPawn.def.race.soundMeleeHitBuilding.NullOrUndefined())
{
return base.CasterPawn.def.race.soundMeleeHitBuilding;
}
return Verb_MeleeAttackSH.DefaultSoundMeleeHitBuilding;
}

private SoundDef SoundMiss()
{
if (base.CasterPawn != null && !base.CasterPawn.def.race.soundMeleeMiss.NullOrUndefined())
{
return base.CasterPawn.def.race.soundMeleeMiss;
}
return Verb_MeleeAttackSH.DefaultSoundMeleeMiss;
}
}
}