Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/elsongabriel/canary into fe…
Browse files Browse the repository at this point in the history
…ature/cyclopedia

# Conflicts:
#	src/creatures/players/player.cpp
#	src/creatures/players/player.hpp
  • Loading branch information
elsongabriel committed May 24, 2024
2 parents 647445c + 5f88c6d commit 7c0a3ab
Show file tree
Hide file tree
Showing 40 changed files with 1,108 additions and 548 deletions.
3 changes: 3 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ partyListMaxDistance = 30
toggleMapCustom = true

-- Market
-- NOTE: marketRefreshPricesInterval (in minutes, minimum is 1 minute)
-- NOTE: set it to 0 for disable, is the time in which the task will run updating the prices of the items that will be sent to the client
marketOfferDuration = 30 * 24 * 60 * 60
marketRefreshPricesInterval = 30
premiumToCreateMarketOffer = true
checkExpiredMarketOffersEachMinutes = 60
maxMarketOffersAtATimePerPlayer = 100
Expand Down
55 changes: 54 additions & 1 deletion data-otservbr-global/migrations/45.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
function onUpdateDatabase()
return false -- true = There are others migrations file | false = this is the last migration file
logger.info("Updating database to version 46 (feat: vip groups)")

db.query([[
CREATE TABLE IF NOT EXISTS `account_vipgroups` (
`id` tinyint(3) UNSIGNED NOT NULL,
`account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose vip group entry it is',
`name` varchar(128) NOT NULL,
`customizable` BOOLEAN NOT NULL DEFAULT '1',
CONSTRAINT `account_vipgroups_pk` PRIMARY KEY (`id`, `account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
]])

db.query([[
CREATE TRIGGER `oncreate_accounts` AFTER INSERT ON `accounts` FOR EACH ROW BEGIN
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (1, NEW.`id`, 'Enemies', 0);
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (2, NEW.`id`, 'Friends', 0);
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (3, NEW.`id`, 'Trading Partner', 0);
END;
]])

db.query([[
CREATE TABLE IF NOT EXISTS `account_vipgrouplist` (
`account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose viplist entry it is',
`player_id` int(11) NOT NULL COMMENT 'id of target player of viplist entry',
`vipgroup_id` tinyint(3) UNSIGNED NOT NULL COMMENT 'id of vip group that player belongs',
INDEX `account_id` (`account_id`),
INDEX `player_id` (`player_id`),
INDEX `vipgroup_id` (`vipgroup_id`),
CONSTRAINT `account_vipgrouplist_unique` UNIQUE (`account_id`, `player_id`, `vipgroup_id`),
CONSTRAINT `account_vipgrouplist_player_fk`
FOREIGN KEY (`player_id`) REFERENCES `players` (`id`)
ON DELETE CASCADE,
CONSTRAINT `account_vipgrouplist_vipgroup_fk`
FOREIGN KEY (`vipgroup_id`, `account_id`) REFERENCES `account_vipgroups` (`id`, `account_id`)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
]])

db.query([[
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`)
SELECT 1, id, 'Friends', 0 FROM `accounts`;
]])

db.query([[
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`)
SELECT 2, id, 'Enemies', 0 FROM `accounts`;
]])

db.query([[
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`)
SELECT 3, id, 'Trading Partners', 0 FROM `accounts`;
]])

return true
end
3 changes: 3 additions & 0 deletions data-otservbr-global/migrations/46.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function onUpdateDatabase()
return false -- true = There are others migrations file | false = this is the last migration file
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local promotionScrolls = {
{ oldScroll = "wheel.scroll.abridged", newScroll = "abridged" },
{ oldScroll = "wheel.scroll.basic", newScroll = "basic" },
{ oldScroll = "wheel.scroll.revised", newScroll = "revised" },
{ oldScroll = "wheel.scroll.extended", newScroll = "extended" },
{ oldScroll = "wheel.scroll.advanced", newScroll = "advanced" },
}

local function migrate(player)
for _, scrollTable in ipairs(promotionScrolls) do
local oldStorage = player:getStorageValueByName(scrollTable.oldScroll)
if oldStorage > 0 then
player:kv():scoped("wheel-of-destiny"):scoped("scrolls"):set(scrollTable.newScroll, true)
end
end
end

local migration = Migration("20241715984279_move_wheel_scrolls_from_storagename_to_kv")

function migration:onExecute()
self:forEachPlayer(migrate)
end

migration:register()
17 changes: 9 additions & 8 deletions data/scripts/actions/items/wheel_scrolls.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local promotionScrolls = {
[43946] = { storageName = "wheel.scroll.abridged", points = 3, name = "abridged promotion scroll" },
[43947] = { storageName = "wheel.scroll.basic", points = 5, name = "basic promotion scroll" },
[43948] = { storageName = "wheel.scroll.revised", points = 9, name = "revised promotion scroll" },
[43949] = { storageName = "wheel.scroll.extended", points = 13, name = "extended promotion scroll" },
[43950] = { storageName = "wheel.scroll.advanced", points = 20, name = "advanced promotion scroll" },
[43946] = { name = "abridged", points = 3, itemName = "abridged promotion scroll" },
[43947] = { name = "basic", points = 5, itemName = "basic promotion scroll" },
[43948] = { name = "revised", points = 9, itemName = "revised promotion scroll" },
[43949] = { name = "extended", points = 13, itemName = "extended promotion scroll" },
[43950] = { name = "advanced", points = 20, itemName = "advanced promotion scroll" },
}

local scroll = Action()
Expand All @@ -15,13 +15,14 @@ function scroll.onUse(player, item, fromPosition, target, toPosition, isHotkey)
end

local scrollData = promotionScrolls[item:getId()]
if player:getStorageValueByName(scrollData.storageName) == 1 then
local scrollKV = player:kv():scoped("wheel-of-destiny"):scoped("scrolls")
if scrollKV:get(scrollData.name) then
player:sendTextMessage(MESSAGE_LOOK, "You have already deciphered this scroll.")
return true
end

player:setStorageValueByName(scrollData.storageName, 1)
player:sendTextMessage(MESSAGE_LOOK, "You have gained " .. scrollData.points .. " promotion points for the Wheel of Destiny by deciphering the " .. scrollData.name .. ".")
scrollKV:set(scrollData.name, true)
player:sendTextMessage(MESSAGE_LOOK, "You have gained " .. scrollData.points .. " promotion points for the Wheel of Destiny by deciphering the " .. scrollData.itemName .. ".")
item:remove(1)
return true
end
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/lib/register_migrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Migration:register()
return
end
if not self:_validateName() then
error("Invalid migration name: " .. self.name .. ". Migration names must be in the format: <timestamp>_<description>. Example: 20231128213149_add_new_monsters")
logger.error("Invalid migration name: " .. self.name .. ". Migration names must be in the format: <timestamp>_<description>. Example: 20231128213149_add_new_monsters")
end

table.insert(Migration.registry, self)
Expand Down
57 changes: 50 additions & 7 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS `server_config` (
CONSTRAINT `server_config_pk` PRIMARY KEY (`config`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '45'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0');
INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '46'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0');

-- Table structure `accounts`
CREATE TABLE IF NOT EXISTS `accounts` (
Expand Down Expand Up @@ -215,6 +215,44 @@ CREATE TABLE IF NOT EXISTS `account_viplist` (
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Table structure `account_vipgroup`
CREATE TABLE IF NOT EXISTS `account_vipgroups` (
`id` tinyint(3) UNSIGNED NOT NULL,
`account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose vip group entry it is',
`name` varchar(128) NOT NULL,
`customizable` BOOLEAN NOT NULL DEFAULT '1',
CONSTRAINT `account_vipgroups_pk` PRIMARY KEY (`id`, `account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Trigger
--
DELIMITER //
CREATE TRIGGER `oncreate_accounts` AFTER INSERT ON `accounts` FOR EACH ROW BEGIN
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (1, NEW.`id`, 'Enemies', 0);
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (2, NEW.`id`, 'Friends', 0);
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (3, NEW.`id`, 'Trading Partner', 0);
END
//
DELIMITER ;

-- Table structure `account_vipgrouplist`
CREATE TABLE IF NOT EXISTS `account_vipgrouplist` (
`account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose viplist entry it is',
`player_id` int(11) NOT NULL COMMENT 'id of target player of viplist entry',
`vipgroup_id` tinyint(3) UNSIGNED NOT NULL COMMENT 'id of vip group that player belongs',
INDEX `account_id` (`account_id`),
INDEX `player_id` (`player_id`),
INDEX `vipgroup_id` (`vipgroup_id`),
CONSTRAINT `account_vipgrouplist_unique` UNIQUE (`account_id`, `player_id`, `vipgroup_id`),
CONSTRAINT `account_vipgrouplist_player_fk`
FOREIGN KEY (`player_id`) REFERENCES `players` (`id`)
ON DELETE CASCADE,
CONSTRAINT `account_vipgrouplist_vipgroup_fk`
FOREIGN KEY (`vipgroup_id`, `account_id`) REFERENCES `account_vipgroups` (`id`, `account_id`)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Table structure `boosted_boss`
CREATE TABLE IF NOT EXISTS `boosted_boss` (
`boostname` TEXT,
Expand Down Expand Up @@ -372,9 +410,9 @@ CREATE TABLE IF NOT EXISTS `guild_ranks` (
--
DELIMITER //
CREATE TRIGGER `oncreate_guilds` AFTER INSERT ON `guilds` FOR EACH ROW BEGIN
INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('The Leader', 3, NEW.`id`);
INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('Vice-Leader', 2, NEW.`id`);
INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('Member', 1, NEW.`id`);
INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('The Leader', 3, NEW.`id`);
INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('Vice-Leader', 2, NEW.`id`);
INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('Member', 1, NEW.`id`);
END
//
DELIMITER ;
Expand Down Expand Up @@ -428,9 +466,8 @@ CREATE TABLE IF NOT EXISTS `houses` (
-- trigger
--
DELIMITER //
CREATE TRIGGER `ondelete_players` BEFORE DELETE ON `players`
FOR EACH ROW BEGIN
UPDATE `houses` SET `owner` = 0 WHERE `owner` = OLD.`id`;
CREATE TRIGGER `ondelete_players` BEFORE DELETE ON `players` FOR EACH ROW BEGIN
UPDATE `houses` SET `owner` = 0 WHERE `owner` = OLD.`id`;
END
//
DELIMITER ;
Expand Down Expand Up @@ -815,3 +852,9 @@ INSERT INTO `players`
(4, 'Paladin Sample', 1, 1, 8, 3, 185, 185, 4200, 113, 115, 95, 39, 129, 0, 90, 90, 0, 8, '', 470, 1, 10, 0, 10, 0, 10, 0, 10, 0),
(5, 'Knight Sample', 1, 1, 8, 4, 185, 185, 4200, 113, 115, 95, 39, 129, 0, 90, 90, 0, 8, '', 470, 1, 10, 0, 10, 0, 10, 0, 10, 0),
(6, 'GOD', 6, 1, 2, 0, 155, 155, 100, 113, 115, 95, 39, 75, 0, 60, 60, 0, 8, '', 410, 1, 10, 0, 10, 0, 10, 0, 10, 0);

-- Create vip groups for GOD account
INSERT INTO `account_vipgroups` (`id`, `name`, `account_id`. `customizable`) VALUES
(1, 'Friends', 1, 0),
(2, 'Enemies', 1, 0),
(3, 'Trading Partners', 1, 0);
1 change: 1 addition & 0 deletions src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ enum ConfigKey_t : uint16_t {
MAP_DOWNLOAD_URL,
MAP_NAME,
MARKET_OFFER_DURATION,
MARKET_REFRESH_PRICES,
MARKET_PREMIUM,
MAX_ALLOWED_ON_A_DUMMY,
MAX_CONTAINER_ITEM,
Expand Down
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ bool ConfigManager::load() {
loadIntConfig(L, GAME_PORT, "gameProtocolPort", 7172);
loadIntConfig(L, LOGIN_PORT, "loginProtocolPort", 7171);
loadIntConfig(L, MARKET_OFFER_DURATION, "marketOfferDuration", 30 * 24 * 60 * 60);
loadIntConfig(L, MARKET_REFRESH_PRICES, "marketRefreshPricesInterval", 30);
loadIntConfig(L, PREMIUM_DEPOT_LIMIT, "premiumDepotLimit", 8000);
loadIntConfig(L, SQL_PORT, "mysqlPort", 3306);
loadIntConfig(L, STASH_ITEMS, "stashItemCount", 5000);
Expand Down
1 change: 1 addition & 0 deletions src/creatures/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ target_sources(${PROJECT_NAME}_lib PRIVATE
players/wheel/player_wheel.cpp
players/wheel/wheel_gems.cpp
players/vocations/vocation.cpp
players/vip/player_vip.cpp
)
33 changes: 22 additions & 11 deletions src/creatures/creatures_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,11 @@ enum ChannelEvent_t : uint8_t {
CHANNELEVENT_EXCLUDE = 3,
};

enum VipStatus_t : uint8_t {
VIPSTATUS_OFFLINE = 0,
VIPSTATUS_ONLINE = 1,
VIPSTATUS_PENDING = 2,
VIPSTATUS_TRAINING = 3
enum class VipStatus_t : uint8_t {
Offline = 0,
Online = 1,
Pending = 2,
Training = 3
};

enum Vocation_t : uint16_t {
Expand Down Expand Up @@ -1395,18 +1395,29 @@ struct CreatureIcon {
struct Position;

struct VIPEntry {
VIPEntry(uint32_t initGuid, std::string initName, std::string initDescription, uint32_t initIcon, bool initNotify) :
VIPEntry(uint32_t initGuid, const std::string &initName, const std::string &initDescription, uint32_t initIcon, bool initNotify) :
guid(initGuid),
name(std::move(initName)),
description(std::move(initDescription)),
icon(initIcon),
notify(initNotify) { }

uint32_t guid;
std::string name;
std::string description;
uint32_t icon;
bool notify;
uint32_t guid = 0;
std::string name = "";
std::string description = "";
uint32_t icon = 0;
bool notify = false;
};

struct VIPGroupEntry {
VIPGroupEntry(uint8_t initId, const std::string &initName, bool initCustomizable) :
id(initId),
name(std::move(initName)),
customizable(initCustomizable) { }

uint8_t id = 0;
std::string name = "";
bool customizable = false;
};

struct Skill {
Expand Down
Loading

0 comments on commit 7c0a3ab

Please sign in to comment.