From 681a877061f1985b39f3b214a30a8f6ee8f72b65 Mon Sep 17 00:00:00 2001 From: Mitachi <70312009+Mitachi2611@users.noreply.github.com> Date: Wed, 22 Jun 2022 04:23:24 +0200 Subject: [PATCH] Initial commit Update char.cpp --- .gitattributes | 2 + README.md | 2 + .../example/receive_item_test.quest | 7 +++ .../example/swap_item_example.quest | 24 +++++++++ .../common/service or CommonDefines.h | 3 ++ how-to/Srcs-Server/game/src/char.cpp | 15 ++++++ how-to/Srcs-Server/game/src/char.h | 10 ++++ how-to/Srcs-Server/game/src/char_item.cpp | 51 +++++++++++++++++++ how-to/Srcs-Server/game/src/cmd_gm.cpp | 12 +++++ how-to/Srcs-Server/game/src/exchange.cpp | 10 ++++ how-to/Srcs-Server/game/src/quest.h | 9 ++++ how-to/Srcs-Server/game/src/questmanager.cpp | 50 ++++++++++++++++++ how-to/Srcs-Server/game/src/questmanager.h | 9 ++++ how-to/Srcs-Server/game/src/questnpc.cpp | 18 +++++++ how-to/Srcs-Server/game/src/questnpc.h | 9 ++++ how-to/Srcs-Server/game/src/shop.cpp | 18 +++++++ how-to/Srcs-Server/game/src/shopEx.cpp | 17 +++++++ 17 files changed, 266 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 how-to/LocaleSrv-Quest/example/receive_item_test.quest create mode 100644 how-to/LocaleSrv-Quest/example/swap_item_example.quest create mode 100644 how-to/Srcs-Server/common/service or CommonDefines.h create mode 100644 how-to/Srcs-Server/game/src/char.cpp create mode 100644 how-to/Srcs-Server/game/src/char.h create mode 100644 how-to/Srcs-Server/game/src/char_item.cpp create mode 100644 how-to/Srcs-Server/game/src/cmd_gm.cpp create mode 100644 how-to/Srcs-Server/game/src/exchange.cpp create mode 100644 how-to/Srcs-Server/game/src/quest.h create mode 100644 how-to/Srcs-Server/game/src/questmanager.cpp create mode 100644 how-to/Srcs-Server/game/src/questmanager.h create mode 100644 how-to/Srcs-Server/game/src/questnpc.cpp create mode 100644 how-to/Srcs-Server/game/src/questnpc.h create mode 100644 how-to/Srcs-Server/game/src/shop.cpp create mode 100644 how-to/Srcs-Server/game/src/shopEx.cpp diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/README.md b/README.md new file mode 100644 index 0000000..ba20308 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# m2-receive-quest-trigger + diff --git a/how-to/LocaleSrv-Quest/example/receive_item_test.quest b/how-to/LocaleSrv-Quest/example/receive_item_test.quest new file mode 100644 index 0000000..f98bcd9 --- /dev/null +++ b/how-to/LocaleSrv-Quest/example/receive_item_test.quest @@ -0,0 +1,7 @@ +quest receive_item_test begin + state start begin + when 70001.receive begin + syschat(string.format("(TEST) -> Count Item: %d", pc.count_item(70001))) + end + end +end \ No newline at end of file diff --git a/how-to/LocaleSrv-Quest/example/swap_item_example.quest b/how-to/LocaleSrv-Quest/example/swap_item_example.quest new file mode 100644 index 0000000..278de3d --- /dev/null +++ b/how-to/LocaleSrv-Quest/example/swap_item_example.quest @@ -0,0 +1,24 @@ +quest swap_item begin + state start begin + when 70001.receive begin + + local item_to_change = 70001 + local count_needed = 10 + + local reward_vnum = 19 + local reward_count = 1 + + while(pc.count_item(item_to_change) >= count_needed) do + if not pc.enough_inventory(reward_vnum) then + syschat("You don't have enough space to receive the item, free up space.") + syschat("After freeing up space, you will have to receive it again.") + break + end + pc.remove_item(item_to_change, count_needed) + pc.give_item2(reward_vnum, reward_count) + syschat(string.format("Congratulations! You have collected %s x %d! In return you will receive: %s x %d", item.get_name(item_to_change), count_needed, item.get_name(reward_vnum), reward_count )) + end + + end + end +end \ No newline at end of file diff --git a/how-to/Srcs-Server/common/service or CommonDefines.h b/how-to/Srcs-Server/common/service or CommonDefines.h new file mode 100644 index 0000000..da191ea --- /dev/null +++ b/how-to/Srcs-Server/common/service or CommonDefines.h @@ -0,0 +1,3 @@ +// Add: + +#define ENABLE_QUEST_RECEIVE_ITEM \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/char.cpp b/how-to/Srcs-Server/game/src/char.cpp new file mode 100644 index 0000000..5f9b7e8 --- /dev/null +++ b/how-to/Srcs-Server/game/src/char.cpp @@ -0,0 +1,15 @@ +//1.) Search: + +int CHARACTER::GetSkillPowerByLevel(int level, bool bMob) const +{ + return CTableBySkill::instance().GetSkillPowerByLevelFromType(GetJob(), GetSkillGroup(), MINMAX(0, level, SKILL_MAX_LEVEL), bMob); +} + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM +void CHARACTER::SenderRecvItem(unsigned int pc, LPITEM item) +{ + quest::CQuestManager::instance().ReceiveItem(pc, item); +} +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/char.h b/how-to/Srcs-Server/game/src/char.h new file mode 100644 index 0000000..2796d41 --- /dev/null +++ b/how-to/Srcs-Server/game/src/char.h @@ -0,0 +1,10 @@ +//1.) Search: + + public: + int GetSkillPowerByLevel(int level, bool bMob = false) const; + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + void SenderRecvItem(unsigned int pc, LPITEM item); +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/char_item.cpp b/how-to/Srcs-Server/game/src/char_item.cpp new file mode 100644 index 0000000..5909a5d --- /dev/null +++ b/how-to/Srcs-Server/game/src/char_item.cpp @@ -0,0 +1,51 @@ +//1.) Search: + + item2->SetCount(item2->GetCount() + bCount2); + + if (bCount == 0) + { + ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), item2->GetName()); + M2_DESTROY_ITEM(item); + if (item2->GetType() == ITEM_QUEST) + quest::CQuestManager::instance().PickupItem (GetPlayerID(), item2); + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + SenderRecvItem(GetPlayerID(), item2); +#endif + +//2.) Search: + + char szHint[32+1]; + snprintf(szHint, sizeof(szHint), "%s %u %u", item->GetName(), item->GetCount(), item->GetOriginalVnum()); + LogManager::instance().ItemLog(this, item, "GET", szHint); + ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), item->GetName()); + + if (item->GetType() == ITEM_QUEST) + quest::CQuestManager::instance().PickupItem (GetPlayerID(), item); + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + SenderRecvItem(GetPlayerID(), item); +#endif + +//3.) Search: + + if (owner == this) + ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), item->GetName()); + else + { + owner->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s 님으로부터 %s"), GetName(), item->GetName()); + ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 전달: %s 님에게 %s"), owner->GetName(), item->GetName()); + } + + if (item->GetType() == ITEM_QUEST) + quest::CQuestManager::instance().PickupItem (owner->GetPlayerID(), item); + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + owner->SenderRecvItem(owner->GetPlayerID(), item); +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/cmd_gm.cpp b/how-to/Srcs-Server/game/src/cmd_gm.cpp new file mode 100644 index 0000000..f6408c2 --- /dev/null +++ b/how-to/Srcs-Server/game/src/cmd_gm.cpp @@ -0,0 +1,12 @@ +//1.) Search: + + if (iEmptyPos != -1) + { + item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos)); + LogManager::instance().ItemLog(ch, item, "GM", item->GetName()); + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + ch->SenderRecvItem(ch->GetPlayerID(), item); +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/exchange.cpp b/how-to/Srcs-Server/game/src/exchange.cpp new file mode 100644 index 0000000..78f3a0b --- /dev/null +++ b/how-to/Srcs-Server/game/src/exchange.cpp @@ -0,0 +1,10 @@ +//1.) Search: + + m_apItems[i] = NULL; + } + +// and add before, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + victim->SenderRecvItem(victim->GetPlayerID(), item); +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/quest.h b/how-to/Srcs-Server/game/src/quest.h new file mode 100644 index 0000000..af6d392 --- /dev/null +++ b/how-to/Srcs-Server/game/src/quest.h @@ -0,0 +1,9 @@ +//1.) Search: + + QUEST_ITEM_INFORMER_EVENT, + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + QUEST_ITEM_RECEIVE_EVENT, +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/questmanager.cpp b/how-to/Srcs-Server/game/src/questmanager.cpp new file mode 100644 index 0000000..a867f68 --- /dev/null +++ b/how-to/Srcs-Server/game/src/questmanager.cpp @@ -0,0 +1,50 @@ +//1.) Search: + + m_mapEventName.insert(TEventNameMap::value_type("item_informer", QUEST_ITEM_INFORMER_EVENT)); + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + m_mapEventName.insert(TEventNameMap::value_type("receive", QUEST_ITEM_RECEIVE_EVENT)); +#endif + +//2.) Search: + + void CQuestManager::AttrOut(unsigned int pc, LPCHARACTER ch, int attr) + { + ... + } + +// and add under the whole function, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + bool CQuestManager::ReceiveItem(unsigned int pc, LPITEM item) + { + if (test_server) + sys_log(0, "questmanager::ReceiveItem Start : itemVnum : %d PC : %d", item->GetOriginalVnum(), pc); + + PC* pPC; + if ((pPC = GetPC(pc))) + { + if (!CheckQuestLoaded(pPC)) + { + LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(pc); + if (ch) + { + ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("����Ʈ�� �ε��ϴ� ���Դϴ�. ��ø� ��ٷ� �ֽʽÿ�.")); + } + return false; + } + + // call script + SetCurrentItem(item); + + return m_mapNPC[item->GetVnum()].OnReceive(*pPC); + } + else + { + sys_err("QUEST RECEIVE_ITEM_EVENT no such pc id : %d", pc); + return false; + } + } +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/questmanager.h b/how-to/Srcs-Server/game/src/questmanager.h new file mode 100644 index 0000000..5ed7e72 --- /dev/null +++ b/how-to/Srcs-Server/game/src/questmanager.h @@ -0,0 +1,9 @@ +//1.) Search: + + void AttrOut(unsigned int pc, LPCHARACTER ch, int attr); + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + bool ReceiveItem(unsigned int pc, LPITEM item); +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/questnpc.cpp b/how-to/Srcs-Server/game/src/questnpc.cpp new file mode 100644 index 0000000..f3f3b31 --- /dev/null +++ b/how-to/Srcs-Server/game/src/questnpc.cpp @@ -0,0 +1,18 @@ +//1.) Search: + + bool NPC::OnTakeItem(PC& pc) + { + ... + } + +// and add before, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + bool NPC::OnReceive(PC& pc) + { + if (m_vnum == 0) + return HandleReceiveAllEvent(pc, QUEST_ITEM_RECEIVE_EVENT); + else + return HandleEvent(pc, QUEST_ITEM_RECEIVE_EVENT); + } +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/questnpc.h b/how-to/Srcs-Server/game/src/questnpc.h new file mode 100644 index 0000000..ed7c8ca --- /dev/null +++ b/how-to/Srcs-Server/game/src/questnpc.h @@ -0,0 +1,9 @@ +//1.) Search: + + bool OnAttrOut(PC& pc); + +// and add after, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + bool OnReceive(PC& pc); +#endif \ No newline at end of file diff --git a/how-to/Srcs-Server/game/src/shop.cpp b/how-to/Srcs-Server/game/src/shop.cpp new file mode 100644 index 0000000..e3e6966 --- /dev/null +++ b/how-to/Srcs-Server/game/src/shop.cpp @@ -0,0 +1,18 @@ +//1.) Search: + + if (item->GetVnum() >= 80003 && item->GetVnum() <= 80007) + { + LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), PERSONAL_SHOP_BUY, ""); + } + + DBManager::instance().SendMoneyLog(MONEY_LOG_SHOP, item->GetVnum(), -dwPrice); + } + + if (item) + sys_log(0, "SHOP: BUY: name %s %s(x %d):%u price %u", ch->GetName(), item->GetName(), item->GetCount(), item->GetID(), dwPrice); + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + ch->SenderRecvItem(ch->GetPlayerID(), item); +#endif diff --git a/how-to/Srcs-Server/game/src/shopEx.cpp b/how-to/Srcs-Server/game/src/shopEx.cpp new file mode 100644 index 0000000..b48b7bf --- /dev/null +++ b/how-to/Srcs-Server/game/src/shopEx.cpp @@ -0,0 +1,17 @@ +//1.) Search: + + if (item->GetVnum() >= 80003 && item->GetVnum() <= 80007) + { + LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), PERSONAL_SHOP_BUY, ""); + } + + DBManager::instance().SendMoneyLog(MONEY_LOG_SHOP, item->GetVnum(), -dwPrice); + + if (item) + sys_log(0, "ShopEx: BUY: name %s %s(x %d):%u price %u", ch->GetName(), item->GetName(), item->GetCount(), item->GetID(), dwPrice); + +// and add under, this: + +#ifdef ENABLE_QUEST_RECEIVE_ITEM + ch->SenderRecvItem(ch->GetPlayerID(), item); +#endif \ No newline at end of file