Varro Posted February 9, 2025 Posted February 9, 2025 (edited) I'm here for learning, I'm very new and trying to understand Redux 5065 source. That said, I noticed in the game that when selling items to any shop npc doesn't give you any gold. The value is mentioned in the item description and the item does disappear. Thank you! Edited February 9, 2025 by Varro Quote
Spirited Posted February 10, 2025 Posted February 10, 2025 1 hour ago, Varro said: I'm here for learning, I'm very new and trying to understand Redux 5065 source. That said, I noticed in the game that when selling items to any shop npc doesn't give you any gold. The value is mentioned in the item description and the item does disappear. Thank you! The first thing I'd suggest doing is searching for the message processing for MsgItem (the message type that handles buying and selling items from NPCs). In Redux, that's under Network/GameServer.cs. It looks like there's already handling for it, so it may be worth setting a breakpoint here and stepping through the handler. That way, you can make sure the item is being found and that the logic actually works as intended. Quote
Varro Posted February 10, 2025 Author Posted February 10, 2025 Fixed by Spirited, thank you! old code - sellPrice *= (uint)(sellItem.Durability / sellItem.MaximumDurability); sellPrice *= (uint)(sellItem.MaximumDurability / sellItem.Durability); New code^ Quote
Spirited Posted February 11, 2025 Posted February 11, 2025 4 hours ago, Varro said: Fixed by Spirited, thank you! old code - sellPrice *= (uint)(sellItem.Durability / sellItem.MaximumDurability); sellPrice *= (uint)(sellItem.MaximumDurability / sellItem.Durability); New code^ Hmm, that doesn't sound right to me. Hehe So, the issue with that line is more that the type it's casting to is truncating the result to zero. The order of the divide is expected to work. It's trying to calculate a percentage of the item's remaining value. So for example, if you have 100 maximum durability on an item but it only has 50 durability remaining, that would be 0.50 (or 50%). If you try to divide two integers, though, it'll truncate the result as an integer and return 0. Then, the code above type casts it into an unsigned integer (which does nothing since it'll always result in zero). A real fix would be to cast one or both of the durability variables to a double type. Then, you'd multiple that double (the percentage of remaining durability) against the sell-back price of the item (giving you a percentage of the sell-back cost). Quote
Varro Posted February 11, 2025 Author Posted February 11, 2025 8 hours ago, Spirited said: Hmm, that doesn't sound right to me. Hehe So, the issue with that line is more that the type it's casting to is truncating the result to zero. The order of the divide is expected to work. It's trying to calculate a percentage of the item's remaining value. So for example, if you have 100 maximum durability on an item but it only has 50 durability remaining, that would be 0.50 (or 50%). If you try to divide two integers, though, it'll truncate the result as an integer and return 0. Then, the code above type casts it into an unsigned integer (which does nothing since it'll always result in zero). A real fix would be to cast one or both of the durability variables to a double type. Then, you'd multiple that double (the percentage of remaining durability) against the sell-back price of the item (giving you a percentage of the sell-back cost). Oh I'm very sorry! I'll have a closer look Quote
Spirited Posted February 12, 2025 Posted February 12, 2025 15 hours ago, Varro said: Oh I'm very sorry! I'll have a closer look You're fine! And if you fix it, feel free to submit a pull request back to the Redux repo. I'd be happy to peer review it and get it merged. It may be worth moving it to GitHub first, though. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.