关灯
开启左侧

M端私服模拟器公会房间代码C++(TBC)

  [复制链接]
admin实名认证 发表于 2016-4-20 22:57:04 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
 
diff -Nuar oregoncore-current/sql/CMakeLists.txt oregoncore-pq/sql/CMakeLists.txt--- oregoncore-current/sql/CMakeLists.txt        2011-01-01 10:03:07.000000000 -0500
+++ oregoncore-pq/sql/CMakeLists.txt        2011-01-01 10:13:14.000000000 -0500
@@ -1,6 +1,7 @@
add_subdirectory(updates)
add_subdirectory(tools)
add_subdirectory(scripts)
+add_subdirectory(oc-patch)


########### install files ###############
diff -Nuar oregoncore-current/sql/oc-patch/CMakeLists.txt oregoncore-pq/sql/oc-patch/CMakeLists.txt
--- oregoncore-current/sql/oc-patch/CMakeLists.txt        1969-12-31 19:00:00.000000000 -0500
+++ oregoncore-pq/sql/oc-patch/CMakeLists.txt        2011-01-01 10:13:14.000000000 -0500
@@ -0,0 +1,6 @@
+
+########### install files ###############
+
+FILE(GLOB _SQL *.sql)
+
+install(FILES ${_SQL} DESTINATION share/oregon/sql/oc-patch)
diff -Nuar oregoncore-current/sql/oc-patch/world-guildhouse.sql oregoncore-pq/sql/oc-patch/world-guildhouse.sql
--- oregoncore-current/sql/oc-patch/world-guildhouse.sql        1969-12-31 19:00:00.000000000 -0500
+++ oregoncore-pq/sql/oc-patch/world-guildhouse.sql        2011-01-01 10:13:14.000000000 -0500
@@ -0,0 +1,28 @@
+--
+-- Table structure for table `guild_houses`
+--
+
+CREATE TABLE IF NOT EXISTS `guild_houses` (
+  `id` int(8) unsigned NOT NULL auto_increment,
+  `guildId` bigint(20) NOT NULL default '0',
+  `x` double NOT NULL,
+  `y` double NOT NULL,
+  `z` double NOT NULL,
+  `map` int(11) NOT NULL,
+  `comment` varchar(255) NOT NULL default '',
+  PRIMARY KEY  (`id`)
+) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=22 ;
+
+--
+-- Dumping data for table `guild_houses`
+--
+
+INSERT INTO `guild_houses` (`id`, `guildId`, `x`, `y`, `z`, `map`, `comment`) VALUES
+(1, 1, 16222, 16266, 14.2, 1, 'GM Island'),
+(2, 0, -10711, 2483, 8, 1, 'Village on the Veiled Sea (Silithus)'),
+(3, 0, -8323, -343, 146, 0, 'Elwynn Falls Camp (Elwynn Forest)'),
+(4, 0, -1840, -4233, 2.14, 0, 'Arathi Village (Arathi Highlands, Forbidding Sea)'),
+(5, 0, -6374, 1262, 7, 0, 'Harbor House (Elwynn Forest)'),
+(6, 0, 4303, -2760, 16.8, 0, 'Quel''Thalas Tower');
+
+
diff -Nuar oregoncore-current/src/game/ScriptLoader.cpp oregoncore-pq/src/game/ScriptLoader.cpp
--- oregoncore-current/src/game/ScriptLoader.cpp        2011-01-01 10:03:08.000000000 -0500
+++ oregoncore-pq/src/game/ScriptLoader.cpp        2011-01-01 10:13:14.000000000 -0500
@@ -11,6 +11,9 @@

#ifdef SCRIPTS

+//custom
+void AddSC_npc_guildmaster();
+
//examples
//void AddSC_custom_example();
//void AddSC_custom_gossip_codebox();
@@ -379,6 +382,10 @@
void AddScripts()
{
#ifdef SCRIPTS
+
+    //Custom
+    AddSC_npc_guildmaster();
+
//    AddSC_custom_example();
//    AddSC_custom_gossip_codebox();
//    AddSC_test();
diff -Nuar oregoncore-current/src/oregoncore/oregoncore.conf.dist oregoncore-pq/src/oregoncore/oregoncore.conf.dist
--- oregoncore-current/src/oregoncore/oregoncore.conf.dist        2011-01-01 10:03:08.000000000 -0500
+++ oregoncore-pq/src/oregoncore/oregoncore.conf.dist        2011-01-01 10:13:14.000000000 -0500
@@ -1891,6 +1891,32 @@
###############################################################################
# CUSTOM SERVER OPTIONS
#
+#    GuildMasterNPC.BuyEnabled
+#        Allow players to buy Guild Houses.
+#        Default: 1 (Yes)
+#                 0 (No)
+#
+#    GuildMasterNPC.BuyGossip
+#        Text for buy menu option (good idea to include price)
+#        Default: "Buy a Guild House for 500 Gold"
+#
+#    GuildMasterNPC.BuyPriceInGold
+#        Amount in gold needed to purchase a guild house.
+#        Default: 500 (Gold)
+#
+#    GuildMasterNPC.SellEnabled
+#        Allow players to sell Guild Houses.
+#        Default: 1 (Yes)
+#                 0 (No)
+#
+#    GuildMasterNPC.SellGossip
+#        Text for sell menu option (good idea to include price)
+#        Default: "Sell your Guild House for 400 Gold"
+#
+#    GuildMasterNPC.SellPriceInGold
+#        Amount of gold given to player when selling guild house.
+#        Default: 400 (Gold)
+#
#    PlayerStart.AllReputation
#        Players will start with most of the high level reputations that are
#         needed for items, mounts etc.
@@ -1983,6 +2009,12 @@
#
###############################################################################

+GuildMasterNPC.BuyEnabled = 1
+GuildMasterNPC.BuyGossip = "Buy a Guild House for 500 Gold"
+GuildMasterNPC.BuyPriceInGold = 500
+GuildMasterNPC.SellEnabled = 1
+GuildMasterNPC.SellGossip = "Sell your GuildHouse for 400 Gold"
+GuildMasterNPC.SellPriceInGold = 400
PlayerStart.AllReputation = 0
PlayerStart.AllSpells = 0
PlayerStart.MapsExplored = 0
diff -Nuar oregoncore-current/src/scripts/Custom/npc_guildmaster.cpp oregoncore-pq/src/scripts/Custom/npc_guildmaster.cpp
--- oregoncore-current/src/scripts/Custom/npc_guildmaster.cpp        1969-12-31 19:00:00.000000000 -0500
+++ oregoncore-pq/src/scripts/Custom/npc_guildmaster.cpp        2011-01-01 10:13:14.000000000 -0500
@@ -0,0 +1,338 @@
+/* ScriptData
+SDName: GuildMaster
+SD%Complete: 95
+SDComment: Guild House Master
+SDCategory: NPC
+EndScriptData */
+
+#include "ScriptPCH.h"
+#include "Config/Config.h"
+
+extern DatabaseType WorldDatabase;
+
+#define MSG_GOSSIP_TELE          "Teleport to Guild House"
+#define MSG_GOSSIP_NEXTPAGE      "Next -->"
+#define MSG_INCOMBAT             "You are in battle!"
+#define MSG_NOGUILDHOUSE         "Your guild does not have a Guild House."
+#define MSG_NOFREEGH             "Unfortunately, all the Guild Houses have been sold."
+#define MSG_ALREADYHAVEGH        "Sorry, but you already have a Guild House (%s)."
+#define MSG_NOTENOUGHMONEY       "You must have %u gold to buy a Guild House."
+#define MSG_GHOCCUPIED           "Unfortunately, this Guild House is already in use."
+#define MSG_CONGRATULATIONS      "Congratulations! You now own a Guild House."
+#define MSG_SOLD                 "You sold your Guild House. Here is %u in gold."
+#define MSG_NOTINGUILD           "You are not in a guild!"
+
+#define CODE_SELL                "SELL"
+#define MSG_CODEBOX_SELL         "Enter \"" CODE_SELL "\" to sell your Guild House."
+
+#define OFFSET_GH_ID_TO_ACTION   1500
+#define OFFSET_SHOWBUY_FROM      10000
+
+#define ACTION_TELE              1001
+#define ACTION_SHOW_BUYLIST      1002  //deprecated. Use (OFFSET_SHOWBUY_FROM + 0) instead
+#define ACTION_SELL_GUILDHOUSE   1003
+
+#define ICON_GOSSIP_BALOON       0
+#define ICON_GOSSIP_WING         2
+#define ICON_GOSSIP_BOOK         3
+#define ICON_GOSSIP_WHEEL1       4
+#define ICON_GOSSIP_WHEEL2       5
+#define ICON_GOSSIP_GOLD         6
+#define ICON_GOSSIP_BALOONDOTS   7
+#define ICON_GOSSIP_TABARD       8
+#define ICON_GOSSIP_XSWORDS      9
+
+#define GOSSIP_COUNT_MAX         10
+
+bool isPlayerGuildLeader(Player *player)
+{
+    return (player->GetRank() == 0) && (player->GetGuildId() != 0);
+}
+
+bool getGuildHouseCoords(uint32 guildId, float &x, float &y, float &z, uint32 &map)
+{
+    if (guildId == 0)
+    {
+        //if player has no guild
+        return false;
+    }
+
+    QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT `x`, `y`, `z`, `map` FROM `guild_houses` WHERE `guildId` = %u", guildId);
+    if(result)
+    {
+        Field *fields = result->Fetch();
+        x = fields[0].GetFloat();
+        y = fields[1].GetFloat();
+        z = fields[2].GetFloat();
+        map = fields[3].GetUInt32();
+        return true;
+    }
+    return false;
+}
+
+void teleportPlayerToGuildHouse(Player *player, Creature *_creature)
+{
+    if (player->GetGuildId() == 0)
+    {
+        //if player has no guild
+        _creature->MonsterWhisper(MSG_NOTINGUILD, player->GetGUID());
+        return;
+    }
+
+    if (!player->getAttackers().empty())
+    {
+        //if player in combat
+        _creature->MonsterSay(MSG_INCOMBAT, LANG_UNIVERSAL, player->GetGUID());
+        return;
+    }
+
+    float x, y, z;
+    uint32 map;
+
+    if (getGuildHouseCoords(player->GetGuildId(), x, y, z, map))
+    {
+        //teleport player to the specified location
+        player->TeleportTo(map, x, y, z, 0.0f);
+    }
+    else
+        _creature->MonsterWhisper(MSG_NOGUILDHOUSE, player->GetGUID());
+
+}
+
+bool showBuyList(Player *player, Creature *_creature, uint32 showFromId = 0)
+{
+    //show not occupied guildhouses
+
+    QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT `id`, `comment` FROM `guild_houses` WHERE `guildId` = 0 AND `id` > %u ORDER BY `id` ASC LIMIT %u",
+        showFromId, GOSSIP_COUNT_MAX);
+
+    if (result)
+    {
+        uint32 guildhouseId = 0;
+        std::string comment = "";
+        do
+        {
+
+            Field *fields = result->Fetch();
+
+            guildhouseId = fields[0].GetInt32();
+            comment = fields[1].GetString();
+            
+            //send comment as a gossip item
+            //transmit guildhouseId in Action variable
+            player->ADD_GOSSIP_ITEM(ICON_GOSSIP_TABARD, comment, GOSSIP_SENDER_MAIN,
+                guildhouseId + OFFSET_GH_ID_TO_ACTION);
+
+        } while (result->NextRow());
+
+        if (result->GetRowCount() == GOSSIP_COUNT_MAX)
+        {
+            //assume that we have additional page
+            //add link to next GOSSIP_COUNT_MAX items
+            player->ADD_GOSSIP_ITEM(ICON_GOSSIP_BALOONDOTS, MSG_GOSSIP_NEXTPAGE, GOSSIP_SENDER_MAIN,
+                guildhouseId + OFFSET_SHOWBUY_FROM);
+        }
+
+        player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, _creature->GetGUID());
+
+        return true;
+    } else
+    {
+        if (showFromId == 0)
+        {
+            //all guildhouses are occupied
+            _creature->MonsterWhisper(MSG_NOFREEGH, player->GetGUID());
+            player->CLOSE_GOSSIP_MENU();
+        } else
+        {
+            //this condition occurs when COUNT(guildhouses) % GOSSIP_COUNT_MAX == 0
+            //just show GHs from beginning
+            showBuyList(player, _creature, 0);
+        }
+    }
+
+    return false;
+}
+
+bool isPlayerHasGuildhouse(Player *player, Creature *_creature, bool whisper = false)
+{
+
+    QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT `comment` FROM `guild_houses` WHERE `guildId` = %u",
+        player->GetGuildId());
+
+    if (result)
+    {
+        if (whisper)
+        {
+            //whisper to player "already have etc..."
+            Field *fields = result->Fetch();
+            char msg[100];
+            sprintf(msg, MSG_ALREADYHAVEGH, fields[0].GetString());
+            _creature->MonsterWhisper(msg, player->GetGUID());
+        }
+
+        return true;
+    }
+    return false;
+
+}
+
+void buyGuildhouse(Player *player, Creature *_creature, uint32 guildhouseId)
+{
+    uint32 buyprice = (sConfig.GetIntDefault("GuildMasterNPC.BuyPriceInGold",500)*10000);
+    if (player->GetMoney() < buyprice)
+    {
+        //show how much money player need to buy GH (in gold)
+        char msg[100];
+        sprintf(msg, MSG_NOTENOUGHMONEY, buyprice / 10000);
+        _creature->MonsterWhisper(msg, player->GetGUID());
+        return;
+    }
+
+    if (isPlayerHasGuildhouse(player, _creature, true))
+    {
+        //player already have GH
+        return;
+    }
+
+    //check if somebody already occupied this GH
+    QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT `id` FROM `guild_houses` WHERE `id` = %u AND `guildId` <> 0",
+        guildhouseId);
+
+    if (result)
+    {
+        _creature->MonsterWhisper(MSG_GHOCCUPIED, player->GetGUID());
+        return;
+    }
+
+    //update DB
+    QueryResult_AutoPtr result_updt = WorldDatabase.PQuery("UPDATE `guild_houses` SET `guildId` = %u WHERE `id` = %u",
+        player->GetGuildId(), guildhouseId);
+   
+    player->ModifyMoney(-buyprice);
+    _creature->MonsterSay(MSG_CONGRATULATIONS, LANG_UNIVERSAL, player->GetGUID());
+   
+}
+
+void sellGuildhouse(Player *player, Creature *_creature)
+{
+    uint32 sellprice = (sConfig.GetIntDefault("GuildMasterNPC.SellPriceInGold",400)*10000);
+    if (isPlayerHasGuildhouse(player, _creature))
+    {
+        QueryResult_AutoPtr result = WorldDatabase.PQuery("UPDATE `guild_houses` SET `guildId` = 0 WHERE `guildId` = %u",
+        player->GetGuildId());
+        
+        player->ModifyMoney(sellprice);
+
+        //display message e.g. "here your money etc."
+        char msg[100];
+        sprintf(msg, MSG_SOLD, (sellprice/10000));
+        _creature->MonsterWhisper(msg, player->GetGUID());
+    }
+}
+
+bool GossipHello_npc_guildmaster(Player *player, Creature *_creature)
+{
+    player->ADD_GOSSIP_ITEM(ICON_GOSSIP_BALOON, MSG_GOSSIP_TELE,
+        GOSSIP_SENDER_MAIN, ACTION_TELE);
+
+    if (isPlayerGuildLeader(player))
+    {
+        uint8 buyEnabled = sConfig.GetIntDefault("GuildMasterNPC.BuyEnabled", 1);
+        if ( buyEnabled == 1 )
+        {
+            //show additional menu for guild leader
+            std::string buyGHGossip = sConfig.GetStringDefault("GuildMasterNPC.BuyGossip", "Buy a Guild House for 500 Gold");
+            player->ADD_GOSSIP_ITEM(ICON_GOSSIP_GOLD, buyGHGossip,
+                GOSSIP_SENDER_MAIN, ACTION_SHOW_BUYLIST);
+        }
+        if (isPlayerHasGuildhouse(player, _creature))
+        {
+            uint8 sellEnabled = sConfig.GetIntDefault("GuildMasterNPC.SellEnabled", 1);
+            if ( sellEnabled == 1 )
+            {
+                //and additional for guildhouse owner
+                std::string sellGHGossip = sConfig.GetStringDefault("GuildMasterNPC.SellGossip", "Sell your Guild House for 400 Gold");
+                player->PlayerTalkClass->GetGossipMenu().AddMenuItem(ICON_GOSSIP_GOLD, sellGHGossip, GOSSIP_SENDER_MAIN, ACTION_SELL_GUILDHOUSE, MSG_CODEBOX_SELL, 0, true);
+            }
+        }
+    }
+    player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, _creature->GetGUID());
+    return true;
+}
+
+
+bool GossipSelect_npc_guildmaster(Player *player, Creature *_creature, uint32 sender, uint32 action )
+{
+    if (sender != GOSSIP_SENDER_MAIN)
+        return false;
+
+    switch (action)
+    {
+        case ACTION_TELE:
+            //teleport player to GH
+            player->CLOSE_GOSSIP_MENU();
+            teleportPlayerToGuildHouse(player, _creature);
+            break;
+        case ACTION_SHOW_BUYLIST:
+            //show list of GHs which currently not occupied
+            showBuyList(player, _creature);
+            break;
+        default:
+            if (action > OFFSET_SHOWBUY_FROM)
+            {
+                showBuyList(player, _creature, action - OFFSET_SHOWBUY_FROM);
+            } else if (action > OFFSET_GH_ID_TO_ACTION)
+            {
+                //player clicked on buy list
+                player->CLOSE_GOSSIP_MENU();
+                //get guildhouseId from action
+                //guildhouseId = action - OFFSET_GH_ID_TO_ACTION
+                buyGuildhouse(player, _creature, action - OFFSET_GH_ID_TO_ACTION);
+            }
+            break;
+    }
+   
+    return true;
+}
+
+bool GossipSelectWithCode_npc_guildmaster( Player *player, Creature *_creature,
+                                      uint32 sender, uint32 action, const char* sCode )
+{
+    if(sender == GOSSIP_SENDER_MAIN)
+    {
+        if(action == ACTION_SELL_GUILDHOUSE)
+        {
+            int i = -1;
+            try
+            {
+                //compare code
+                if (strlen(sCode) + 1 == sizeof CODE_SELL)
+                    i = strcmp(CODE_SELL, sCode);
+
+            } catch(char *str) {error_db_log(str);}
+
+            if (i == 0)
+            {
+                //right code
+                sellGuildhouse(player, _creature);
+            }
+            player->CLOSE_GOSSIP_MENU();
+            return true;
+        }
+    }
+    return false;
+}
+
+
+void AddSC_npc_guildmaster()
+{
+    Script *newscript;
+    newscript = new Script;
+    newscript->Name = "npc_guildmaster";
+    newscript->pGossipHello = &GossipHello_npc_guildmaster;
+    newscript->pGossipSelect = &GossipSelect_npc_guildmaster;
+    newscript->pGossipSelectWithCode =  &GossipSelectWithCode_npc_guildmaster;
+    newscript->RegisterSelf();
+}
+


回复下载完整代码


游客,如果您要查看本帖隐藏内容请回复


标签:模拟器
 

精彩评论1

倒序浏览
无毒 发表于 2019-8-5 12:32:41 | 显示全部楼层
 
回复下载完整代码
 
VIP介绍
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 最佳新人

    注册账号后积极发帖的会员
  • 活跃会员

    经常参与各类话题的讨论,发帖内容较有主见
  • 热心会员

    经常帮助其他会员答疑
  • 推广达人

    积极宣传本站,为本站带来更多注册会员
  • 宣传达人

    积极宣传本站,为本站带来更多的用户访问量
  • 灌水之王

    经常在论坛发帖,且发帖量较大
  • 突出贡献

    长期对论坛的繁荣而不断努力,或多次提出建设性意见
  • 优秀版主

    活跃且尽责职守的版主
  • 荣誉管理

    曾经为论坛做出突出贡献目前已离职的版主
  • 论坛元老

    为论坛做出突出贡献的会员

0关注

5粉丝

3421帖子

排行榜
作者专栏

QQ交流群&&微信订阅号

QQ交流群

微信订阅号

吾爱尚玩资源基地永久域名:

Www.523Play.Com

在线管理员QQ:1589479632

邮箱:Email@523play.com

QQ交流群:558936238

Copyright   ©2015-2116  吾爱尚玩资源基地|523play.comPowered by©523Pplay.Com技术支持:吾爱尚玩资源基地