吾爱尚玩资源基地
标题:
LOL:有趣的变态魔兽私服服务端的答题系统参考
[打印本页]
作者:
admin
时间:
2016-4-18 22:46
标题:
LOL:有趣的变态魔兽私服服务端的答题系统参考
diff --git a/src/game/Chat.cpp b/src/game/Chat.cppindex 8f7d802..375d495 100644
--- a/src/game/Chat.cpp
+++ b/src/game/Chat.cpp
@@ -643,6 +643,7 @@ ChatCommand * ChatHandler::getCommandTable()
{ "flusharenapoints",SEC_ADMINISTRATOR, false, &ChatHandler::HandleFlushArenaPointsCommand, "", NULL },
{ "repairitems", SEC_GAMEMASTER, true, &ChatHandler::HandleRepairitemsCommand, "", NULL },
{ "waterwalk", SEC_GAMEMASTER, false, &ChatHandler::HandleWaterwalkCommand, "", NULL },
+ { "dt", SEC_PLAYER, false, &ChatHandler::HandleQuestion, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
diff --git a/src/game/Chat.h b/src/game/Chat.h
index ac03a6f..582d493 100644
--- a/src/game/Chat.h
+++ b/src/game/Chat.h
@@ -491,6 +491,8 @@ class ChatHandler
bool HandleSet32Bit(const char* args);
bool HandleSaveAllCommand(const char* args);
+ bool HandleQuestion(const char* args);
+
Player* getSelectedPlayer();
Creature* getSelectedCreature();
Unit* getSelectedUnit();
diff --git a/src/game/Language.h b/src/game/Language.h
index e1c15fb..9cdc9f0 100644
--- a/src/game/Language.h
+++ b/src/game/Language.h
@@ -781,5 +781,12 @@ enum MangosStrings
// NOT RESERVED IDS 12000-1999999999
// `db_script_string` table index 2000000000-2000009999 (MIN_DB_SCRIPT_STRING_ID-MAX_DB_SCRIPT_STRING_ID)
// For other tables maybe 2000010000-2147483647 (max index)
+ LANG_AUTO_QUESTION = 11100, //|CFF00FFFF[答题公告]:|R%s [奖金%s金币]
+ LANG_AUTO_QUESTION_ABCD = 11099, //|CFF00FFFF 选项|R |CFFFF0000A.|R%s |CFFFF0000B.|R%s |CFFFF0000C.|R%s |CFFFF0000D.|R%s
+ LANG_AUTO_QUESTION_OK = 11101, //|CFF00FFFF[答题公告]:|R|CFFFFFF00回答正确|R
+ LANG_AUTO_QUESTION_ERROR = 11102, //|CFF00FFFF[答题公告]:|R|CFFFF0000回答错误|R
+ LANG_AUTO_QUESTION_RIGHT = 11103, //|CFF00FFFF[答题公告]:|R玩家%s|CFFFFFF00回答正确|R
+ LANG_AUTO_QUESTION_NOT_ANSWER_TIME = 11104, //|CFF00FFFF[答题公告]:|R|CFFFF0000非答题时间|R
+ LANG_AUTO_QUESTION_OFF = 11105, //|CFFFF0000答题系统功能关闭中!|R
};
#endif
diff --git a/src/game/Level0.cpp b/src/game/Level0.cpp
index 557ca91..b840111 100644
--- a/src/game/Level0.cpp
+++ b/src/game/Level0.cpp
@@ -29,6 +29,8 @@
#include "revision.h"
#include "revision_nr.h"
#include "Util.h"
+#include "UTF8Cn.h"
+#include "worldpacket.h"
bool ChatHandler::HandleHelpCommand(const char* args)
{
@@ -261,3 +263,60 @@ bool ChatHandler::HandleServerMotdCommand(const char* /*args*/)
PSendSysMessage(LANG_MOTD_CURRENT, sWorld.GetMotd());
return true;
}
+
+//答题命令
+bool ChatHandler::HandleQuestion(const char* args)
+{
+ if(sWorld.getAutoQuestion(AUTO_QUESTION_ON) != 1)
+ {
+ this->PSendSysMessage(LANG_AUTO_QUESTION_OFF);
+ return true;
+ }
+
+ std::string str = _strupr((char*)args);
+ if(!str.length())
+ return false;
+
+ QueryResult *result;
+ result = WorldDatabase.PQuery("SELECT `ok`,`integral` FROM `auto_question` WHERE flag <> 0");
+
+ if(!result)
+ {
+ sWorld.SendWorldText(LANG_AUTO_QUESTION_NOT_ANSWER_TIME);
+ return true;
+ }
+
+ Field *fields = result->Fetch();
+ std::string answer = _strupr((char*)fields[0].GetString());
+ int32 money = fields[1].GetInt16();
+ delete result;
+
+ if(str == answer)
+ {
+ WorldDatabase.PExecute("UPDATE `auto_question` SET `flag` = 0 WHERE `flag` <> 0");
+ m_session->GetPlayer()->ModifyMoney(money*10000);
+ std::string userName = m_session->GetPlayer()->GetName();
+ PSendSysMessage(LANG_AUTO_QUESTION_OK);
+
+ if(sWorld.getAutoQuestion(AUTO_QUESTION_CENTER) == 0 || sWorld.getAutoQuestion(AUTO_QUESTION_CENTER) == 2)
+ sWorld.SendWorldText(LANG_AUTO_QUESTION_RIGHT,UTF8Cn::GetNameLink(userName).c_str());
+
+ if(sWorld.getAutoQuestion(AUTO_QUESTION_CENTER) == 1 || sWorld.getAutoQuestion(AUTO_QUESTION_CENTER) == 2)
+ {
+ std::string messageStr =UTF8Cn::ConvertToUTF8Chinese("|CFF00FFFF[答题公告]:|R玩家|CFFFFFF00[")+userName+UTF8Cn::ConvertToUTF8Chinese("]|R回答正确!");
+
+ WorldPacket data(SMSG_NOTIFICATION, (messageStr.size()+1));
+ data << messageStr;
+ sWorld.SendGlobalMessage(&data);
+ }
+ }
+ else
+ {
+ m_session->GetPlayer()->ModifyMoney(-(int32)sWorld.getAutoQuestion(AUTO_QUESTION_ERROR));
+ PSendSysMessage(LANG_AUTO_QUESTION_ERROR);
+ }
+
+ //sLog.outString("system info: '%s'",str.c_str());
+
+ return true;
+}
\ No newline at end of file
diff --git a/src/game/World.cpp b/src/game/World.cpp
index d8a5ab6..5e48d5c 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -62,6 +62,7 @@
#include "WaypointManager.h"
#include "GMTicketMgr.h"
#include "Util.h"
+#include "Language.h"
INSTANTIATE_SINGLETON_1( World );
@@ -1036,6 +1037,11 @@ void World::LoadConfigSettings(bool reload)
sLog.outString( "WORLD: VMap support included. LineOfSight:%i, getHeight:%i",enableLOS, enableHeight);
sLog.outString( "WORLD: VMap data directory is: %svmaps",m_dataPath.c_str());
sLog.outString( "WORLD: VMap config keys are: vmap.enableLOS, vmap.enableHeight, vmap.ignoreMapIds, vmap.ignoreSpellIds");
+
+ auto_question[AUTO_QUESTION_ON] = sConfig.GetIntDefault("AutoQuestion.On", 0);
+ auto_question[AUTO_QUESTION_TIMER] = sConfig.GetIntDefault("AutoQuestion.Timer", 300000);
+ auto_question[AUTO_QUESTION_ERROR] = sConfig.GetIntDefault("AutoQuestion.Error", 10000);
+ auto_question[AUTO_QUESTION_CENTER] = sConfig.GetIntDefault("AutoQuestion.Center", 0);
}
/// Initialize the World
@@ -1403,6 +1409,8 @@ void World::SetInitialWorldSettings()
m_timers[WUPDATE_CORPSES].SetInterval(20*MINUTE*IN_MILISECONDS);
//erase corpses every 20 minutes
+ WorldDatabase.PExecute("UPDATE `auto_question` SET `flag` = 0 WHERE `flag` <> 0");
+ m_timers[WUPDATE_AUTOQUESTION].SetInterval(getAutoQuestion(AUTO_QUESTION_TIMER));
//to set mailtimer to return mails every day between 4 and 5 am
//mailtimer is increased when updating auctions
//one second is 1000 -(tested on win system)
@@ -1442,6 +1450,7 @@ void World::SetInitialWorldSettings()
uint32 nextGameEvent = gameeventmgr.Initialize();
m_timers[WUPDATE_EVENTS].SetInterval(nextGameEvent); //depend on next event
+ sLog.outString("Starting AutoQuestion system by LZQGOLD..." );
sLog.outString( "WORLD: World initialized" );
}
@@ -1594,6 +1603,15 @@ void World::Update(uint32 diff)
m_timers[WUPDATE_EVENTS].Reset();
}
+ if(getAutoQuestion(AUTO_QUESTION_ON) == 1)
+ {
+ if (m_timers[WUPDATE_AUTOQUESTION].Passed())
+ {
+ m_timers[WUPDATE_AUTOQUESTION].Reset();
+ SendQuestion();
+ }
+ }
+
/// </ul>
///- Move all creatures with "delayed move" and remove and delete all objects with "delayed remove"
MapManager::Instance().DoDelayedMovesAndRemoves();
@@ -2016,6 +2034,36 @@ void World::ProcessCliCommands()
zprint("mangos>");
}
+void World::SendQuestion()
+{
+ int32 guid;
+ std::string text,a,b,c,d,money;
+
+ QueryResult *result;
+ if(!(result = WorldDatabase.PQuery("SELECT `guid`,`text`,`a`,`b`,`c`,`d`,`integral` FROM `auto_question` where `flag` <> 0 LIMIT 1")))
+ result = WorldDatabase.PQuery("SELECT `guid`,`text`,`a`,`b`,`c`,`d`,`integral` FROM `auto_question` ORDER BY RAND() LIMIT 1");
+
+ if(!result)
+ return;
+
+ Field *fields = result->Fetch();
+ guid = fields[0].GetInt16();
+ text = fields[1].GetString();
+ a = fields[2].GetString();
+ b = fields[3].GetString();
+ c = fields[4].GetString();
+ d = fields[5].GetString();
+ money = fields[6].GetString();
+ delete result;
+
+ if(WorldDatabase.PExecute("UPDATE `auto_question` SET `flag` = 1 WHERE `guid` = '%i'",guid))
+ {
+ sWorld.SendWorldText(LANG_AUTO_QUESTION, text.c_str(), money.c_str());
+ sWorld.SendWorldText(LANG_AUTO_QUESTION_ABCD, a.c_str(),b.c_str(),c.c_str(),d.c_str());
+ sLog.outString("AutoQuestion: '%s'",text.c_str());
+ }
+}
+
void World::InitResultQueue()
{
m_resultQueue = new SqlResultQueue;
diff --git a/src/game/World.h b/src/game/World.h
index e4ff977..b201f0f 100644
--- a/src/game/World.h
+++ b/src/game/World.h
@@ -77,7 +77,8 @@ enum WorldTimers
WUPDATE_UPTIME = 4,
WUPDATE_CORPSES = 5,
WUPDATE_EVENTS = 6,
- WUPDATE_COUNT = 7
+ WUPDATE_AUTOQUESTION = 7,
+ WUPDATE_COUNT = 8
};
/// Configuration elements
@@ -324,6 +325,15 @@ enum RealmZone
REALM_ZONE_CN9 = 29 // basic-Latin at create, any at login
};
+enum AutoQuestion
+{
+ AUTO_QUESTION_ON, //是否开启自动答题系统
+ AUTO_QUESTION_TIMER, //自动答题计时时间
+ AUTO_QUESTION_ERROR, //答错扣除金钱
+ AUTO_QUESTION_CENTER, //答题公告显示位置,1屏幕中间,0屏幕左下角,2同时
+ AUTO_QUESTION_VALUE_COUNT
+};
+
// DB scripting commands
#define SCRIPT_COMMAND_TALK 0 // source = unit, target=any, datalong ( 0=say, 1=whisper, 2=yell, 3=emote text)
#define SCRIPT_COMMAND_EMOTE 1 // source = unit, datalong = anim_id
@@ -474,6 +484,16 @@ class World
return 0;
}
+ void SendQuestion();
+
+ uint32 getAutoQuestion(uint32 index) const
+ {
+ if(index<AUTO_QUESTION_VALUE_COUNT)
+ return auto_question[index];
+ else
+ return 0;
+ }
+
/// Are we on a "Player versus Player" server?
bool IsPvPRealm() { return (getConfig(CONFIG_GAME_TYPE) == REALM_TYPE_PVP || getConfig(CONFIG_GAME_TYPE) == REALM_TYPE_RPPVP || getConfig(CONFIG_GAME_TYPE) == REALM_TYPE_FFA_PVP); }
bool IsFFAPvPRealm() { return getConfig(CONFIG_GAME_TYPE) == REALM_TYPE_FFA_PVP; }
@@ -546,6 +566,7 @@ class World
float rate_values[MAX_RATES];
uint32 m_configs[CONFIG_VALUE_COUNT];
+ uint32 auto_question[AUTO_QUESTION_VALUE_COUNT];
int32 m_playerLimit;
LocaleConstant m_defaultDbcLocale; // from config for one from loaded DBC locales
uint32 m_availableDbcLocaleMask; // by loaded DBC
diff --git a/win/VC80/game.vcproj b/win/VC80/game.vcproj
index e457cb7..d2c06aa 100644
--- a/win/VC80/game.vcproj
+++ b/win/VC80/game.vcproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="8,00"
+ Version="8.00"
Name="game"
ProjectGUID="{1DC6C4DA-A028-41F3-877D-D5400C594F88}"
RootNamespace="game"
@@ -1541,6 +1541,14 @@
RelativePath="..\..\src\game\PlayerDump.h"
>
</File>
+ <File
+ RelativePath="..\..\src\game\UTF8Cn.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\game\UTF8Cn.h"
+ >
+ </File>
</Filter>
<Filter
Name="References"
diff --git a/win/VC80/mangosd.vcproj b/win/VC80/mangosd.vcproj
index be3c372..5cd6c49 100644
--- a/win/VC80/mangosd.vcproj
+++ b/win/VC80/mangosd.vcproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="8,00"
+ Version="8.00"
Name="mangosd"
ProjectGUID="{A3A04E47-43A2-4C08-90B3-029CEF558594}"
RootNamespace="mangosd"
复制代码
完整的mangos| trinity魔兽私服服务端的参考代码:
链接:
http://pan.baidu.com/s/1hsbcdq0
密码: 4r5y
作者:
letver
时间:
2021-11-3 14:32
这脚本在哪里啊
作者:
asl123456
时间:
2024-9-14 15:04
有趣的变态魔兽私服服务端的答题系统参考
欢迎光临 吾爱尚玩资源基地 (http://bbs.523play.com/)
Powered by Discuz! X3.4