Browse Source

Sync learned/changed spells

pull/6040/head
obligaron 3 years ago committed by Anders Jenbo
parent
commit
bf86114ec3
  1. 12
      Source/debug.cpp
  2. 10
      Source/items.cpp
  3. 18
      Source/msg.cpp
  4. 8
      Source/msg.h
  5. 43
      Source/objects.cpp

12
Source/debug.cpp

@ -92,14 +92,6 @@ uint32_t glMid2Seed[NUMLEVELS];
uint32_t glMid3Seed[NUMLEVELS]; uint32_t glMid3Seed[NUMLEVELS];
uint32_t glEndSeed[NUMLEVELS]; uint32_t glEndSeed[NUMLEVELS];
void SetSpellLevelCheat(SpellID spl, uint8_t spllvl)
{
Player &myPlayer = *MyPlayer;
myPlayer._pMemSpells |= GetSpellBitmask(spl);
myPlayer._pSplLvl[static_cast<int8_t>(spl)] = spllvl;
}
void PrintDebugMonster(const Monster &monster) void PrintDebugMonster(const Monster &monster)
{ {
EventPlrMsg(StrCat( EventPlrMsg(StrCat(
@ -530,9 +522,9 @@ std::string DebugCmdMinStats(const string_view parameter)
std::string DebugCmdSetSpellsLevel(const string_view parameter) std::string DebugCmdSetSpellsLevel(const string_view parameter)
{ {
uint8_t level = static_cast<uint8_t>(std::max(0, atoi(parameter.data()))); uint8_t level = static_cast<uint8_t>(std::max(0, atoi(parameter.data())));
for (int i = static_cast<int8_t>(SpellID::Firebolt); i < MAX_SPELLS; i++) { for (uint8_t i = static_cast<uint8_t>(SpellID::Firebolt); i < MAX_SPELLS; i++) {
if (GetSpellBookLevel(static_cast<SpellID>(i)) != -1) { if (GetSpellBookLevel(static_cast<SpellID>(i)) != -1) {
SetSpellLevelCheat(static_cast<SpellID>(i), level); NetSendCmdParam2(true, CMD_CHANGE_SPELL_LEVEL, i, level);
} }
} }
if (level == 0) if (level == 0)

10
Source/items.cpp

@ -4052,10 +4052,10 @@ void UseItem(size_t pnum, item_misc_id mid, SpellID spellID, int spellFrom)
NetSendCmdLocParam4(true, CMD_SPELLXY, cursPosition, static_cast<int8_t>(spellID), static_cast<uint8_t>(SpellType::Scroll), spellLevel, static_cast<uint16_t>(spellFrom)); NetSendCmdLocParam4(true, CMD_SPELLXY, cursPosition, static_cast<int8_t>(spellID), static_cast<uint8_t>(SpellType::Scroll), spellLevel, static_cast<uint16_t>(spellFrom));
} }
break; break;
case IMISC_BOOK: case IMISC_BOOK: {
player._pMemSpells |= GetSpellBitmask(spellID); uint8_t newSpellLevel = player._pSplLvl[static_cast<int8_t>(spellID)] + 1;
if (player._pSplLvl[static_cast<int8_t>(spellID)] < MaxSpellLevel) if (newSpellLevel <= MaxSpellLevel)
player._pSplLvl[static_cast<int8_t>(spellID)]++; NetSendCmdParam2(true, CMD_CHANGE_SPELL_LEVEL, static_cast<uint16_t>(spellID), newSpellLevel);
if (HasNoneOf(player._pIFlags, ItemSpecialEffect::NoMana)) { if (HasNoneOf(player._pIFlags, ItemSpecialEffect::NoMana)) {
player._pMana += GetSpellData(spellID).sManaCost << 6; player._pMana += GetSpellData(spellID).sManaCost << 6;
player._pMana = std::min(player._pMana, player._pMaxMana); player._pMana = std::min(player._pMana, player._pMaxMana);
@ -4071,7 +4071,7 @@ void UseItem(size_t pnum, item_misc_id mid, SpellID spellID, int spellFrom)
} }
} }
RedrawComponent(PanelDrawComponent::Mana); RedrawComponent(PanelDrawComponent::Mana);
break; } break;
case IMISC_MAPOFDOOM: case IMISC_MAPOFDOOM:
doom_init(); doom_init();
break; break;

18
Source/msg.cpp

@ -2304,17 +2304,21 @@ size_t OnCheatExperience(const TCmd *pCmd, size_t pnum) // NOLINT(misc-unused-pa
return sizeof(*pCmd); return sizeof(*pCmd);
} }
size_t OnCheatSpellLevel(const TCmd *pCmd, size_t pnum) // NOLINT(misc-unused-parameters) size_t OnChangeSpellLevel(const TCmd *pCmd, size_t pnum) // NOLINT(misc-unused-parameters)
{ {
#ifdef _DEBUG const auto &message = *reinterpret_cast<const TCmdParam2 *>(pCmd);
const SpellID spellID = static_cast<SpellID>(SDL_SwapLE16(message.wParam1));
const uint8_t spellLevel = std::min(static_cast<uint8_t>(SDL_SwapLE16(message.wParam2)), MaxSpellLevel);
if (gbBufferMsgs == 1) { if (gbBufferMsgs == 1) {
SendPacket(pnum, pCmd, sizeof(*pCmd)); SendPacket(pnum, pCmd, sizeof(*pCmd));
} else { } else {
Player &player = Players[pnum]; Player &player = Players[pnum];
player._pSplLvl[static_cast<int8_t>(player._pRSpell)]++; player._pMemSpells |= GetSpellBitmask(spellID);
player._pSplLvl[static_cast<size_t>(spellID)] = spellLevel;
} }
#endif
return sizeof(*pCmd); return sizeof(message);
} }
size_t OnDebug(const TCmd *pCmd) size_t OnDebug(const TCmd *pCmd)
@ -3267,8 +3271,8 @@ size_t ParseCmd(size_t pnum, const TCmd *pCmd)
return OnSyncQuest(pCmd, pnum); return OnSyncQuest(pCmd, pnum);
case CMD_CHEAT_EXPERIENCE: case CMD_CHEAT_EXPERIENCE:
return OnCheatExperience(pCmd, pnum); return OnCheatExperience(pCmd, pnum);
case CMD_CHEAT_SPELL_LEVEL: case CMD_CHANGE_SPELL_LEVEL:
return OnCheatSpellLevel(pCmd, pnum); return OnChangeSpellLevel(pCmd, pnum);
case CMD_SETSHIELD: case CMD_SETSHIELD:
return OnSetShield(pCmd, player); return OnSetShield(pCmd, player);
case CMD_REMSHIELD: case CMD_REMSHIELD:

8
Source/msg.h

@ -178,10 +178,12 @@ enum _cmd_id : uint8_t {
// //
// body (TCmd) // body (TCmd)
CMD_CHEAT_EXPERIENCE, CMD_CHEAT_EXPERIENCE,
// Cheat: increase active spell level of player. // Change spell level of player.
// //
// body (TCmd) // body (TCmdParam2)
CMD_CHEAT_SPELL_LEVEL, // int16_t spellID
// int16_t spellLevel
CMD_CHANGE_SPELL_LEVEL,
// Debug command (nop). // Debug command (nop).
// //
// body (TCmd) // body (TCmd)

43
Source/objects.cpp

@ -1979,10 +1979,11 @@ void OperateBook(Player &player, Object &book, bool sendmsg)
} }
if (setlvlnum == SL_BONECHAMB) { if (setlvlnum == SL_BONECHAMB) {
player._pMemSpells |= GetSpellBitmask(SpellID::Guardian);
if (player._pSplLvl[static_cast<int8_t>(SpellID::Guardian)] < MaxSpellLevel)
player._pSplLvl[static_cast<int8_t>(SpellID::Guardian)]++;
if (sendmsg) { if (sendmsg) {
uint8_t newSpellLevel = player._pSplLvl[static_cast<int8_t>(SpellID::Guardian)] + 1;
if (newSpellLevel <= MaxSpellLevel)
NetSendCmdParam2(true, CMD_CHANGE_SPELL_LEVEL, static_cast<uint16_t>(SpellID::Guardian), newSpellLevel);
Quests[Q_SCHAMB]._qactive = QUEST_DONE; Quests[Q_SCHAMB]._qactive = QUEST_DONE;
NetSendCmdQuest(true, Quests[Q_SCHAMB]); NetSendCmdQuest(true, Quests[Q_SCHAMB]);
} }
@ -2526,30 +2527,29 @@ void OperateShrineEnchanted(Player &player)
int cnt = 0; int cnt = 0;
uint64_t spell = 1; uint64_t spell = 1;
int maxSpells = gbIsHellfire ? MAX_SPELLS : 37; uint8_t maxSpells = gbIsHellfire ? MAX_SPELLS : 37;
uint64_t spells = player._pMemSpells; uint64_t spells = player._pMemSpells;
for (int j = 0; j < maxSpells; j++) { for (uint16_t j = 0; j < maxSpells; j++) {
if ((spell & spells) != 0) if ((spell & spells) != 0)
cnt++; cnt++;
spell *= 2; spell *= 2;
} }
if (cnt > 1) { if (cnt > 1) {
int spellToReduce;
do {
spellToReduce = GenerateRnd(maxSpells) + 1;
} while ((player._pMemSpells & GetSpellBitmask(static_cast<SpellID>(spellToReduce))) == 0);
spell = 1; spell = 1;
for (int j = static_cast<int8_t>(SpellID::Firebolt); j < maxSpells; j++) { // BUGFIX: < MAX_SPELLS, there is no spell with MAX_SPELLS index (fixed) for (uint8_t j = static_cast<uint8_t>(SpellID::Firebolt); j < maxSpells; j++) { // BUGFIX: < MAX_SPELLS, there is no spell with MAX_SPELLS index (fixed)
if ((player._pMemSpells & spell) != 0) { if ((player._pMemSpells & spell) != 0 && player._pSplLvl[j] < MaxSpellLevel && j != spellToReduce) {
if (player._pSplLvl[j] < MaxSpellLevel) NetSendCmdParam2(true, CMD_CHANGE_SPELL_LEVEL, j, static_cast<uint8_t>(player._pSplLvl[j] + 1));
player._pSplLvl[j]++;
} }
spell *= 2; spell *= 2;
} }
int r;
do { if (player._pSplLvl[spellToReduce] > 0)
r = GenerateRnd(maxSpells); NetSendCmdParam2(true, CMD_CHANGE_SPELL_LEVEL, spellToReduce, player._pSplLvl[spellToReduce] - 1);
} while ((player._pMemSpells & GetSpellBitmask(static_cast<SpellID>(r + 1))) == 0);
if (player._pSplLvl[r + 1] >= 2)
player._pSplLvl[r + 1] -= 2;
else
player._pSplLvl[r + 1] = 0;
} }
InitDiabloMsg(EMSG_SHRINE_ENCHANTED); InitDiabloMsg(EMSG_SHRINE_ENCHANTED);
@ -2579,10 +2579,11 @@ void OperateShrineCostOfWisdom(Player &player, SpellID spellId, diablo_message m
player._pMemSpells |= GetSpellBitmask(spellId); player._pMemSpells |= GetSpellBitmask(spellId);
if (player._pSplLvl[static_cast<int8_t>(spellId)] < MaxSpellLevel) uint8_t curSpellLevel = player._pSplLvl[static_cast<int8_t>(spellId)];
player._pSplLvl[static_cast<int8_t>(spellId)]++; if (curSpellLevel < MaxSpellLevel) {
if (player._pSplLvl[static_cast<int8_t>(spellId)] < MaxSpellLevel) uint8_t newSpellLevel = std::min(static_cast<uint8_t>(curSpellLevel + 2), MaxSpellLevel);
player._pSplLvl[static_cast<int8_t>(spellId)]++; NetSendCmdParam2(true, CMD_CHANGE_SPELL_LEVEL, static_cast<uint16_t>(spellId), newSpellLevel);
}
uint32_t t = player._pMaxManaBase / 10; uint32_t t = player._pMaxManaBase / 10;
int v1 = player._pMana - player._pManaBase; int v1 = player._pMana - player._pManaBase;

Loading…
Cancel
Save