[B18] Custom Melee Sound | Implementation?

Started by O Negative, November 19, 2017, 04:36:39 AM

Previous topic - Next topic

O Negative

Goal: Have a melee weapon the plays unique/custom sounds on hit/miss.


In the past, I was able to achieve my goal by creating my own custom melee verb in an assembly.
A17
namespace HaloWeapons
{
public class Verb_EnergySwordAttack : Verb_MeleeAttack
{
private const int TargetCooldown = 50;

private const float DefaultHitChance = 0.6f;

protected override bool TryCastShot()
{
Pawn casterPawn = base.get_CasterPawn();
bool fullBodyBusy = casterPawn.stances.get_FullBodyBusy();
bool result;
if (fullBodyBusy)
{
result = false;
}
else
{
Thing thing = this.currentTarget.get_Thing();
bool flag = !base.CanHitTarget(thing);
if (flag)
{
Log.Warning(string.Concat(new object[]
{
casterPawn,
" meleed ",
thing,
" from out of melee position."
}));
}
casterPawn.get_Drawer().rotator.Face(thing.get_DrawPos());
bool flag2 = !this.IsTargetImmobile(this.currentTarget) && casterPawn.skills != null;
if (flag2)
{
casterPawn.skills.Learn(SkillDefOf.Melee, 250f, false);
}
bool flag3 = Rand.get_Value() < this.GetHitChance(thing);
bool flag4;
SoundDef soundDef;
if (flag3)
{
flag4 = true;
this.ApplyMeleeDamageToTarget(this.currentTarget);
bool flag5 = thing.def.category == 4;
if (flag5)
{
soundDef = this.SoundHitBuilding();
}
else
{
soundDef = this.SoundHitPawn();
}
}
else
{
flag4 = false;
soundDef = this.SoundMiss();
}
SoundStarter.PlayOneShot(soundDef, new TargetInfo(thing.get_Position(), casterPawn.get_Map(), false));
casterPawn.get_Drawer().Notify_MeleeAttackOn(thing);
Pawn pawn = thing as Pawn;
bool flag6 = pawn != null && !pawn.get_Dead();
if (flag6)
{
pawn.stances.StaggerFor(95);
bool flag7 = casterPawn.get_MentalStateDef() != MentalStateDefOf.SocialFighting || pawn.get_MentalStateDef() != MentalStateDefOf.SocialFighting;
if (flag7)
{
pawn.mindState.meleeThreat = casterPawn;
pawn.mindState.lastMeleeThreatHarmTick = Find.get_TickManager().get_TicksGame();
}
}
casterPawn.get_Drawer().rotator.FaceCell(thing.get_Position());
bool flag8 = casterPawn.caller != null;
if (flag8)
{
casterPawn.caller.Notify_DidMeleeAttack();
}
result = flag4;
}
return result;
}

[DebuggerHidden]
private IEnumerable<DamageInfo> DamageInfosToApply(LocalTargetInfo target)
{
Verb_EnergySwordAttack.<DamageInfosToApply>d__3 expr_07 = new Verb_EnergySwordAttack.<DamageInfosToApply>d__3(-2);
expr_07.<>4__this = this;
expr_07.<>3__target = target;
return expr_07;
}

private float GetHitChance(LocalTargetInfo target)
{
bool surpriseAttack = this.surpriseAttack;
float result;
if (surpriseAttack)
{
result = 1f;
}
else
{
bool flag = this.IsTargetImmobile(target);
if (flag)
{
result = 1f;
}
else
{
bool flag2 = base.get_CasterPawn().skills != null;
if (flag2)
{
result = StatExtension.GetStatValue(base.get_CasterPawn(), StatDefOf.MeleeHitChance, true);
}
else
{
result = 0.6f;
}
}
}
return result;
}

private bool IsTargetImmobile(LocalTargetInfo target)
{
Thing thing = target.get_Thing();
Pawn pawn = thing as Pawn;
return thing.def.category != 1 || pawn.get_Downed() || PawnUtility.GetPosture(pawn) > 0;
}

private void ApplyMeleeDamageToTarget(LocalTargetInfo target)
{
foreach (DamageInfo current in this.DamageInfosToApply(target))
{
bool thingDestroyed = target.get_ThingDestroyed();
if (thingDestroyed)
{
break;
}
target.get_Thing().TakeDamage(current);
}
}

private SoundDef SoundHitPawn()
{
bool flag = this.ownerEquipment != null && this.ownerEquipment.get_Stuff() != null;
SoundDef result;
if (flag)
{
bool flag2 = this.verbProps.meleeDamageDef.armorCategory == DamageArmorCategoryDefOf.Sharp;
if (flag2)
{
bool flag3 = !SoundDefHelper.NullOrUndefined(this.ownerEquipment.get_Stuff().stuffProps.soundMeleeHitSharp);
if (flag3)
{
result = this.ownerEquipment.get_Stuff().stuffProps.soundMeleeHitSharp;
return result;
}
}
else
{
bool flag4 = !SoundDefHelper.NullOrUndefined(this.ownerEquipment.get_Stuff().stuffProps.soundMeleeHitBlunt);
if (flag4)
{
result = this.ownerEquipment.get_Stuff().stuffProps.soundMeleeHitBlunt;
return result;
}
}
}
bool flag5 = base.get_CasterPawn() != null && !SoundDefHelper.NullOrUndefined(base.get_CasterPawn().def.race.soundMeleeHitPawn);
if (flag5)
{
result = SoundDef.Named("SwordHitPawn");
}
else
{
result = SoundDef.Named("SwordHitPawn");
}
return result;
}

private SoundDef SoundHitBuilding()
{
bool flag = this.ownerEquipment != null && this.ownerEquipment.get_Stuff() != null;
SoundDef result;
if (flag)
{
bool flag2 = this.verbProps.meleeDamageDef.armorCategory == DamageArmorCategoryDefOf.Sharp;
if (flag2)
{
bool flag3 = !SoundDefHelper.NullOrUndefined(this.ownerEquipment.get_Stuff().stuffProps.soundMeleeHitSharp);
if (flag3)
{
result = this.ownerEquipment.get_Stuff().stuffProps.soundMeleeHitSharp;
return result;
}
}
else
{
bool flag4 = !SoundDefHelper.NullOrUndefined(this.ownerEquipment.get_Stuff().stuffProps.soundMeleeHitBlunt);
if (flag4)
{
result = this.ownerEquipment.get_Stuff().stuffProps.soundMeleeHitBlunt;
return result;
}
}
}
bool flag5 = base.get_CasterPawn() != null && !SoundDefHelper.NullOrUndefined(base.get_CasterPawn().def.race.soundMeleeHitBuilding);
if (flag5)
{
result = SoundDef.Named("SwordHitBuilding");
}
else
{
result = SoundDef.Named("SwordHitBuilding");
}
return result;
}

private SoundDef SoundMiss()
{
bool flag = base.get_CasterPawn() != null && !SoundDefHelper.NullOrUndefined(base.get_CasterPawn().def.race.soundMeleeMiss);
SoundDef result;
if (flag)
{
result = SoundDef.Named("SwordMiss");
}
else
{
result = SoundDef.Named("SwordMiss");
}
return result;
}
}
}

The above is the A17 melee verb verbatim, with a few minor changes towards the end. I reference the sound files: SoundDef.Named("SwordHitPawn"), SoundDef.Named("SwordHitBuilding"), and SoundDef.Named("SwordMiss")


B18
The way melee verbs/actions are handled has changed significantly. Weapons are no longer assigned a melee verb - they now have a list of tools to be selected from - which means I can't really use my old method of changing the sounds.

I understand this isn't such a big deal for most weapon modders. If I'm not mistaken, most weapon mods out there don't focus much on melee weapons to begin with, and when they do the sounds aren't usually an issue because of the material of the weapon. However, when it comes to futuristic energy-based weapons (lightsabers and energy swords) the core game sounds just don't work quite right.

QuantumX

I have the same problem, not worked out how to get the sounds back on my melee weapons yet...

Hopefully someone knows.