-
Notifications
You must be signed in to change notification settings - Fork 1
feat: ZS_Dead equivalent — death XP and loot init on NPC kill #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
77f6808
d9a0534
7319917
27ee711
1fbb1af
4d9a3cd
4a2e129
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,10 @@ public class DebugChannelTypesCollection : CollectionWrapper<DeveloperConfigEnum | |
|
|
||
| [Tooltip("Enable player→NPC melee combat (hit detection, damage, hurt/death animations). WIP - debug damage values only.")] | ||
| public bool EnableCombatSystem; | ||
|
|
||
| [ConditionalField(fieldToCheck: nameof(EnableCombatSystem), compareValues: true)] | ||
| [Tooltip("Call B_DeathXP on kill to grant XP. WIP - XP values may be incorrect.")] | ||
| public bool EnableDeathXP; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this needs to be guarded by a feature flag at all. Should do no harm to the game at runtime. |
||
|
|
||
| [ConditionalField(fieldToCheck: nameof(EnableNpcs), compareValues: true)] | ||
| public bool EnableNpcMeshCulling = true; | ||
|
|
@@ -291,5 +295,6 @@ public class DebugChannelTypesCollection : CollectionWrapper<DeveloperConfigEnum | |
| public bool EnableDecalVisuals; | ||
| public bool EnableParticleEffects; | ||
|
|
||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ public class FightService | |
| [Inject] private PhysicsService _physicsService; | ||
| [Inject] private NpcHelperService _npcHelperService; | ||
| [Inject] private readonly ConfigService _configService; | ||
| [Inject] private readonly Gothic.Core.Services.GameStateService _gameStateService; | ||
| [Inject] private readonly NpcService _npcService; | ||
|
|
||
| public void Init() | ||
| { | ||
|
|
@@ -39,6 +41,8 @@ private void OnHit(NpcContainer attacker, NpcContainer target, Vector3 __) | |
| Logger.Log($"[FightService.OnHit] {target.Instance.GetName(NpcNameSlot.Slot0)} is DEAD", LogCat.Npc); | ||
| target.Props.BodyState = VmGothicEnums.BodyState.BsDead; | ||
| OnDyingChangeAnimation(target); | ||
| if (_configService.Dev.EnableDeathXP) | ||
| OnNpcDied(target, attacker); | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -96,6 +100,36 @@ private bool OnHitUpdateHealth(NpcContainer attacker, NpcContainer target) | |
| return hitPoints <= 0; | ||
| } | ||
|
|
||
| private void OnNpcDied(NpcContainer dead, NpcContainer killer) | ||
| { | ||
| var vm = _gameStateService.GothicVm; | ||
| var aivPlundered = vm.GetSymbolByName("AIV_PLUNDERED")?.GetInt(0) ?? 8; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put symbol into any of the *Constants. files. |
||
| dead.Instance.SetAiVar(aivPlundered, 0); | ||
|
|
||
| var oldSelf = vm.GlobalSelf; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. We might have this more often to switch self/other to something different, then switch it back afterwards. |
||
| var oldOther = vm.GlobalOther; | ||
| vm.GlobalSelf = dead.Instance; | ||
| vm.GlobalOther = killer.Instance; | ||
|
|
||
| if (_configService.Dev.EnableDeathXP && killer.PrefabProps.IsHero()) | ||
| { | ||
| var bDeathXp = vm.GetSymbolByName("B_DeathXP"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constants. |
||
| if (bDeathXp != null) | ||
| { | ||
| vm.Call(bDeathXp.Index); | ||
| _npcService.SyncHeroInstanceToVob(); | ||
| Logger.Log($"[FightService.OnNpcDied] B_DeathXP: {dead.Instance.GetName(NpcNameSlot.Slot0)} killed by hero", LogCat.Npc); | ||
| } | ||
| } | ||
|
|
||
| var bGiveDeathInv = vm.GetSymbolByName("B_GiveDeathInv"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use existing constants file for it: |
||
| if (bGiveDeathInv != null) | ||
| vm.Call(bGiveDeathInv.Index); | ||
|
|
||
| vm.GlobalSelf = oldSelf; | ||
| vm.GlobalOther = oldOther; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// C_ITEM.damageType is a DAM_* bitmask whose bit positions match the PROT_* indices. | ||
| /// Weapons carry one damage type; the first set bit wins. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,6 +247,15 @@ public void ExtNpcChangeAttribute(NpcInstance npc, int attributeId, int value) | |
| vob.Attributes[attributeId] = value; | ||
| } | ||
|
|
||
| public void SyncHeroInstanceToVob() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. Why is it needed now? |
||
| { | ||
| var hero = GetHeroContainer(); | ||
| hero.Vob.Level = hero.Instance.Level; | ||
| hero.Vob.Xp = hero.Instance.Exp; | ||
| hero.Vob.XpNextLevel = hero.Instance.ExpNext; | ||
| hero.Vob.Lp = hero.Instance.Lp; | ||
| } | ||
|
|
||
| public NpcContainer GetHeroContainer() | ||
| { | ||
| return ((NpcInstance)_gameStateService.GothicVm.GlobalHero).GetUserData(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the value might be incorrect? Can you add it to be non-WIP? ;-)