Skip to content
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

Exposing detailed knife details #431

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

Falderebet
Copy link
Contributor

Why this PR is needed

As of now it is not possible to see what "type" of knife players have equipped as they are all maped to EqKnife. This PR is an attempt to make that possible.

What this PR adds

  • New EquipmentTypes for the different knives.
  • Refactored MapEquipment as it no longer needs to handle "edge" cases that knives where previously.

wep = eqNameToWeapon[eqName]
}
// If the eqName isn't known it will be EqUnknown as that is the default value for EquipmentType
wep := eqNameToWeapon[eqName]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this doesn't really scale well for when they add new knifes - we would need to update the parser every time. and worse, our consumers would need to upgrade, otherwise they will get EqUnknown for the new knife, which would be really hard to debug.

I suggest that we instead expose the raw eqName somewhere upstream in the call chain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point, I will take a look at it!

Copy link
Contributor Author

@Falderebet Falderebet Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**Edit - I found the attribute "m_sWeaponName". Is that what you (@markus-wa) meant regarding exposing the raw eqName?

If so disregard the rest of the comment.

***Edit2 - I digged a bit deeper regarding the "m_sWeaponName" property, and it seems like it is not possible to get any relevant data from it. I have not found any other properties that holds weapon name data. Let me know if you know of any.


I don't think there is a good way to handle valve adding new knives. However, I think there are some options:

  1. Exposing the weapon "code"/itemindex - eg. we give the consumers the possibility to see what code the EqUnkown has.

    • Pros:
      • This technically means that consumers can still handle new knives even before the parser is updated.
    • Cons:
      • It will still to a degree be hard for consumers to debug, as they only get a weapon code and nothing "human readable".
      • Parser will still need to be updated to handle new knives with EqTypes and so forth.
  2. Exposing a more raw weapon string.

    • Pros:
      • Makes it more human readable for consumers to debug.
    • Cons:
      • The parser needs to be updated before consumers can add new knives.

After writing this out I find myself gravitating more towards option 1. As the raw weapon string is not something coming from the engine but something we attach from the item index.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also why not keeping strings.Contains(eqName, "knife") as a fallback when wep is unknown?
i think it's better to have weapon_knife instead of "Unknown" when we know it's a knife

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also why not keeping strings.Contains(eqName, "knife") as a fallback when wep is unknown? i think it's better to have weapon_knife instead of "Unknown" when we know it's a knife

My thought was that the parser defines what a knife "is". Therefore it would be an error in the parser if the EqName did not map to an EqType.

I can add it back, I guess it is nice to have if new knives are added and the eqname/eqtype map is not updated.

Copy link
Owner

@markus-wa markus-wa Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually - I don't think we can add new EqKnifeXYZ types anyway as it's not backwards compatible and would lead to confusion (e.g. if the user wants to check if a kill was a knife kill, using EqKnife is more straight forward than checking all cases.

So we should expose this as additional data, not as replacement.

So we'll need another way of solving this - not yet sure how exactly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the idea of adding a field to the equipment struct with additional detailes about the weapon/equipment?

Let me know if there is something I can do. :)

Copy link
Owner

@markus-wa markus-wa Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good! Maybe something similar to what we already have with Equipment.OriginalString but for this new string?

@markus-wa markus-wa self-assigned this Oct 16, 2023
Copy link
Owner

@markus-wa markus-wa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed in comments

@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8bf8a71) 80.38% compared to head (3256112) 80.53%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #431      +/-   ##
==========================================
+ Coverage   80.38%   80.53%   +0.14%     
==========================================
  Files          47       47              
  Lines        6257     6304      +47     
==========================================
+ Hits         5030     5077      +47     
  Misses       1018     1018              
  Partials      209      209              
Files Coverage Δ
pkg/demoinfocs/common/equipment.go 91.66% <100.00%> (+1.66%) ⬆️
pkg/demoinfocs/datatables.go 92.10% <100.00%> (+0.06%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

EqKnifeOutdoor EquipmentType = 437
EqKnifeStiletto EquipmentType = 438
EqKnifeWidowmaker EquipmentType = 439
EqKnifeSkeleton EquipmentType = 440
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the RawEquipment part looks good now - but this part will need to be removed as it's not backwards compatible as mentioned in the other thread.

So all we should do for now is expose RawEquipment.

Maybe we can have a separate type KnifeType and constants KnifeTypeXYZ with a map KnifeTypes map[string]KnifeType which includes all known knife types to still provide some kind of mapping.

The good thing about this is that if a new knife comes out the users can just add it to the map themselves,. as the map will be mutable.

I think this would be the best middleground

eqNameToWeapon["knife_outdoor"] = EqKnifeOutdoor
eqNameToWeapon["knife_stiletto"] = EqKnifeStiletto
eqNameToWeapon["knife_widowmaker"] = EqKnifeWidowmaker
eqNameToWeapon["knife_skeleton"] = EqKnifeSkeleton
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, would need to be moved to the new map I wrote about

eqElementToName[EqKnifeOutdoor] = "Outdoor Knife"
eqElementToName[EqKnifeStiletto] = "Stiletto Knife"
eqElementToName[EqKnifeWidowmaker] = "Widowmaker Knife"
eqElementToName[EqKnifeSkeleton] = "Skeleton Knife"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would have to be in a new map knifeTypeToName - don't forget to implement the String() method on KnifeType

521: EqKnifeOutdoor, // weapon_knife_outdoor
522: EqKnifeStiletto, // weapon_knife_stiletto
523: EqKnifeWidowmaker, // weapon_knife_widowmaker
525: EqKnifeSkeleton, // weapon_knife_skeleton
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these would need to be put in a new map as well KnifeTypeIndexMapping

@markus-wa
Copy link
Owner

thanks for the changes @Falderebet - sorry this is taking a while, but I think it's important to get this right to prevent issues in the future - thanks for your patience here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants