Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Revscriptsys] RevNpcSys version 1.0 (lua npcs / NpcType / new npc system) #4671

Merged
merged 52 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
5539c3f
lua Npc's
EvilHero90 Apr 30, 2024
1c181d5
tree handling talkstate
EvilHero90 Apr 30, 2024
860580e
Merge branch 'master' into npc-system
EvilHero90 May 1, 2024
7814076
Merge branch 'master' into npc-system
EvilHero90 May 1, 2024
ad194ec
added callback
EvilHero90 May 1, 2024
30ea721
requirements
EvilHero90 May 1, 2024
e2aa611
documentation and splitting in files
EvilHero90 May 2, 2024
cb5d1da
optimizations & better documentation
EvilHero90 May 2, 2024
226419c
requirements, modules & documentation
EvilHero90 May 3, 2024
d004a07
remove unused function & other improvements
EvilHero90 May 3, 2024
d788476
annotations
EvilHero90 May 4, 2024
eac6ea2
Merge branch 'master' into npc-system
EvilHero90 May 5, 2024
683b96b
annotation fixes
EvilHero90 May 5, 2024
81fc9f3
NpcType class
EvilHero90 May 6, 2024
7b15f62
improvements
EvilHero90 May 7, 2024
fe9fb0f
~NpcEventsHandler()
EvilHero90 May 7, 2024
d45354c
clang
EvilHero90 May 7, 2024
29a4605
removing not necessary check
EvilHero90 May 7, 2024
ea11545
improvements on keywords & responses
EvilHero90 May 7, 2024
5acc33f
Merge branch 'master' into npc-system
EvilHero90 May 7, 2024
ffa54e8
added the missing events & callbacks
EvilHero90 May 7, 2024
df23ff9
shop works with item name aswell
EvilHero90 May 8, 2024
4467f40
error handling for shop items
EvilHero90 May 8, 2024
477731a
more functionality and slight fixes
EvilHero90 May 11, 2024
4824668
spelling mistake
EvilHero90 May 11, 2024
3b85b28
changing pointers from shared_ptr to unique_ptr
EvilHero90 May 11, 2024
bf967d4
added NpcVoices & few other things
EvilHero90 May 12, 2024
b580581
sub-keywords
EvilHero90 May 12, 2024
69cd124
re work on requirements
EvilHero90 May 13, 2024
de5c7bc
greeting re work
EvilHero90 May 13, 2024
c74fb12
code cleanup & keyword fix
EvilHero90 May 15, 2024
b629df4
adding onAnswer() & money transfer dupe
EvilHero90 May 15, 2024
2b71c28
check for answer
EvilHero90 May 15, 2024
8dae802
renamed get/add/reset answers into data
EvilHero90 May 16, 2024
eba30a3
code cleanup
EvilHero90 May 16, 2024
17d11e0
clang
EvilHero90 May 16, 2024
37be7c5
Update modules.lua
EvilHero90 May 19, 2024
331e15e
idle rework
EvilHero90 May 19, 2024
42b6302
slight optimizations
EvilHero90 May 19, 2024
f82770e
adding resetData where needed
EvilHero90 May 21, 2024
cbfe62c
reworked NpcType class
EvilHero90 May 23, 2024
75d3c85
improvement on voices
EvilHero90 May 23, 2024
53dbb16
syncing players money on transfer
EvilHero90 May 24, 2024
e6a1c43
renaming folder
EvilHero90 May 26, 2024
4a409f6
Merge branch 'master' into npc-system
EvilHero90 May 27, 2024
ab9c994
merging conflicts
EvilHero90 May 27, 2024
a3a3e66
another merging conflict
EvilHero90 May 27, 2024
21ad5bf
add NpcType to cpplinter.lua
EvilHero90 May 27, 2024
80a793c
correcting parameters in onMove
EvilHero90 May 27, 2024
ff98732
NpcFocus fix
EvilHero90 May 27, 2024
0e4362b
adding vocation requirements
EvilHero90 May 28, 2024
cc3b704
final version 1.0 commit
EvilHero90 May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 78 additions & 18 deletions data/cpplinter.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---@alias os.mtime fun(): number
---@class os
---@field mtime fun(): number
os = {}

EPuncker marked this conversation as resolved.
Show resolved Hide resolved
---@alias table.create fun(arrayLength: number, keyLength: number): table
---@alias table.pack fun(...): table
---@class table
---@field create fun(arrayLength: number, keyLength: number): table
---@field pack fun(...): table
table = {}

---@class rawgetmetatable
---@field __index fun(self: table, key: any): any
Expand Down Expand Up @@ -92,6 +96,7 @@ configManager = {}
---@field createNpc fun(name: string, position: Position, extended?: boolean, force?: boolean, magicEffect?: MagicEffect_t): Npc
---@field createTile fun(position: Position): Tile
---@field createMonsterType fun(name: string): MonsterType
---@field createNpcType fun(name: string): NpcType
---@field startEvent fun(eventName: string): boolean
---@field getClientVersion fun(): string
---@field reload fun(reloadType: number): boolean
Expand Down Expand Up @@ -389,7 +394,7 @@ Creature = {}
---@field addOfflineTrainingTries fun(self: Player, skill: number, amount: number)
---@field getOfflineTrainingSkill fun(self: Player): number
---@field setOfflineTrainingSkill fun(self: Player, skill: number)
---@field getItemCount fun(self: Player, itemId: number): number
---@field getItemCount fun(self: Player, itemId: number, subType?: number, ignoreEquipped?: boolean): number
---@field getItemById fun(self: Player, itemId: number, subType?: number): Item
---@field getVocation fun(self: Player): Vocation
---@field setVocation fun(self: Player, vocationId: number)
Expand All @@ -414,7 +419,7 @@ Creature = {}
---@field setBankBalance fun(self: Player, balance: number)
---@field addItem fun(self: Player, itemId: number, count?: number): Item
---@field addItemEx fun(self: Player, item: Item, copyItem?: boolean): boolean
---@field removeItem fun(self: Player, itemId: number, count?: number, subtype?: number): boolean
---@field removeItem fun(self: Player, itemId: number, count?: number, subtype?: number, ignoreEquipped?: boolean): boolean
---@field sendSupplyUsed fun(self: Player, item: Item)
---@field getMoney fun(self: Player): number
---@field addMoney fun(self: Player, amount: number)
Expand Down Expand Up @@ -521,6 +526,62 @@ Monster = {}
---@field getSpectators fun(self: Npc, centerPos: Position, rangeX: number, rangeY: number, multifloor: boolean): table
Npc = {}

---@class NpcType
---@field create fun(): NpcType
---@field name fun(self: NpcType, name?: string): any
---@field setName fun(self: NpcType, name: string): boolean
---@field getName fun(self: NpcType): string
---@field eventType fun(self: NpcType, eventType?: string): any
---@field setEventType fun(self: NpcType, type: string): boolean
---@field getEventType fun(self: NpcType): string
---@field speechBubble fun(self: NpcType, speechBubble?: number): any
---@field setSpeechBubble fun(self: NpcType, bubble: number): boolean
---@field getSpeechBubble fun(self: NpcType): number
---@field walkInterval fun(self: NpcType, interval?: number): any
---@field setWalkInterval fun(self: NpcType, interval: number): boolean
---@field getWalkInterval fun(self: NpcType): number
---@field walkSpeed fun(self: NpcType, speed?: number): any
---@field setWalkSpeed fun(self: NpcType, speed: number): boolean
---@field getWalkSpeed fun(self: NpcType): number
---@field spawnRadius fun(self: NpcType, radius?: number): any
---@field setSpawnRadius fun(self: NpcType, radius: number): boolean
---@field getSpawnRadius fun(self: NpcType): number
---@field floorChange fun(self: NpcType, floorChange?: boolean): any
---@field setFloorChange fun(self: NpcType, floorChange: boolean): boolean
---@field getFloorChange fun(self: NpcType): boolean
---@field attackable fun(self: NpcType, attackable?: boolean): any
---@field setAttackable fun(self: NpcType, attackable: boolean): boolean
---@field getAttackable fun(self: NpcType): boolean
---@field ignoreHeight fun(self: NpcType, ignoreHeight?: boolean): any
---@field setIgnoreHeight fun(self: NpcType, ignoreHeight: boolean): boolean
---@field getIgnoreHeight fun(self: NpcType): boolean
---@field isIdle fun(self: NpcType, isIdle?: boolean): any
---@field setIsIdle fun(self: NpcType, isIdle: boolean): boolean
---@field getIsIdle fun(self: NpcType): boolean
---@field pushable fun(self: NpcType, pushable?: boolean): any
---@field setPushable fun(self: NpcType, pushable: boolean): boolean
---@field getPushable fun(self: NpcType): boolean
---@field outfit fun(self: NpcType, outfit?: Outfit|table): any
---@field setOutfit fun(self: NpcType, outfit: Outfit): boolean
---@field getOutfit fun(self: NpcType): Outfit
---@field parameters fun(self: NpcType, key?: any, value?: any): any
---@field setParameters fun(self: NpcType, key: any, value: any): boolean
---@field getParameters fun(self: NpcType, key: any): table
---@field health fun(self: NpcType, health?: number): any
---@field setHealth fun(self: NpcType, health: number): boolean
---@field getHealth fun(self: NpcType): number
---@field maxHealth fun(self: NpcType, maxHealth?: number): any
---@field setMaxHealth fun(self: NpcType, maxHealth: number): boolean
---@field getMaxHealth fun(self: NpcType): number
---@field onSay fun(self: NpcType, callback: function): boolean
---@field onDisappear fun(self: NpcType, callback: function): boolean
---@field onAppear fun(self: NpcType, callback: function): boolean
---@field onMove fun(self: NpcType, callback: function): boolean
---@field onPlayerCloseChannel fun(self: NpcType, callback: function): boolean
---@field onPlayerEndTrade fun(self: NpcType, callback: function): boolean
---@field onThink fun(self: NpcType, callback: function): boolean
NpcType = {}

---@class Guild
---@field create fun(): Guild
---@field __eq fun(self: Guild, other: Guild): boolean
Expand Down Expand Up @@ -718,19 +779,18 @@ Combat = {}
Condition = {}

---@class Outfit
---@field create fun(): Outfit
---@field lookType number
---@field lookHead number
---@field lookBody number
---@field lookLegs number
---@field lookFeet number
---@field lookAddons number
---@field lookMount number
---@field lookMountHead number
---@field lookMountBody number
---@field lookMountLegs number
---@field lookMountFeet number
---@field lookTypeEx number
---@field lookType number|nil
---@field lookHead number|nil
---@field lookBody number|nil
---@field lookLegs number|nil
---@field lookFeet number|nil
---@field lookAddons number|nil
---@field lookMount number|nil
---@field lookMountHead number|nil
---@field lookMountBody number|nil
---@field lookMountLegs number|nil
---@field lookMountFeet number|nil
---@field lookTypeEx number|nil
Outfit = {}

---@class MonsterType
Expand Down
38 changes: 36 additions & 2 deletions data/lib/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,42 @@ do
rawgetmetatable("Action").__newindex = ActionNewIndex
end

do
local function NpcTypeNewIndex(self, key, value)
if key == "onSay" then
self:eventType("say")
self:onSay(value)
return
elseif key == "onDisappear" then
self:eventType("disappear")
self:onDisappear(value)
return
elseif key == "onAppear" then
self:eventType("appear")
self:onAppear(value)
return
elseif key == "onMove" then
self:eventType("move")
self:onMove(value)
return
elseif key == "onPlayerCloseChannel" then
self:eventType("closechannel")
self:onPlayerCloseChannel(value)
return
elseif key == "onPlayerEndTrade" then
self:eventType("endtrade")
self:onPlayerEndTrade(value)
return
elseif key == "onThink" then
self:eventType("think")
self:onThink(value)
return
end
ranisalt marked this conversation as resolved.
Show resolved Hide resolved
rawset(self, key, value)
end
rawgetmetatable("NpcType").__newindex = NpcTypeNewIndex
end

do
local function TalkActionNewIndex(self, key, value)
if key == "onSay" then
Expand Down Expand Up @@ -588,8 +624,6 @@ function isPremium(cid) local p = Player(cid) return p and p:isPremium() or fals

STORAGEVALUE_EMPTY = -1
function Player:getStorageValue(key)
print("[Warning - " .. debug.getinfo(2).source:match("@?(.*)") .. "] Invoking Creature:getStorageValue will return nil to indicate absence in the future. Please update your scripts accordingly.")
ranisalt marked this conversation as resolved.
Show resolved Hide resolved

local v = Creature.getStorageValue(self, key)
return v or STORAGEVALUE_EMPTY
end
Expand Down
12 changes: 12 additions & 0 deletions data/lib/core/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ function Player.transferMoneyTo(self, target, amount)
local targetPlayer = Player(target.guid)
if targetPlayer then
targetPlayer:setBankBalance(targetPlayer:getBankBalance() + amount)
db.query("UPDATE `players` SET `balance` = " .. targetPlayer:getBankBalance() .. " WHERE `id` = '" .. targetPlayer:getGuid() .. "'")
else
db.query("UPDATE `players` SET `balance` = `balance` + " .. amount .. " WHERE `id` = '" .. target.guid .. "'")
end

self:setBankBalance(self:getBankBalance() - amount)
-- incase server crashes that we do not duplicate money
self:save()
return true
end

Expand Down Expand Up @@ -737,3 +740,12 @@ function Player.disableLoginMusic(self)
msg:delete()
return true
end

function Player.sendInboxItems(self, items, containerId)
local inbox = self:getInbox()
local container = Game.createItem(containerId, 1)
for _, item in pairs(items) do
container:addItem(item.item, item.count)
end
container:moveTo(inbox)
end
1 change: 1 addition & 0 deletions data/npc/lib/npc.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- Including the Advanced NPC System
dofile('data/npc/lib/npcsystem/npcsystem.lua')
dofile("data/npc/lib/revnpcsys/npc.lua")

function msgcontains(message, keyword)
local message, keyword = message:lower(), keyword:lower()
Expand Down
123 changes: 123 additions & 0 deletions data/npc/lib/revnpcsys/constants.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
--[[
>> Constants <<

Description:
- This file contains all the constants used in the NPC System.
]]

-- MESSAGE_TAGS
---@class MESSAGE_TAGS
---@type table<string, table<string, string|number|function>>
MESSAGE_TAGS = {
playerName = { tag = "|PLAYERNAME|", func = function(params) return params.playerName or "" end },
playerLevel = { tag = "|PLAYERLEVEL|", func = function(params) return params.playerLevel or "" end },
playerLevel2 = { tag = "|PLAYERLEVEL2|", func = function(params) return params.playerLevel2 or "" end },
itemCount = { tag = "|ITEMCOUNT|", func = function(params) return params.amount or "" end },
totalCost = { tag = "|TOTALCOST|", func = function(params) return params.total or "" end },
itemName = { tag = "|ITEMNAME|", func = function(params) return params.itemName or "" end },
storageKey = { tag = "|STORAGEKEY|", func = function(params) return params.storage and params.storage.key or "" end },
storageValue = { tag = "|STORAGEVALUE|", func = function(params) return params.storage and params.storage.value or "" end },
vocationName = { tag = "|VOCATIONNAME|", func = function(params) return params.vocation or "" end }
}

-- MESSAGE_LIST
---@class MESSAGE_LIST
---@type table<string, string>
MESSAGE_LIST = {
-- shop messages
needMoney = "You need more money",
needSpace = "You do not have enough capacity.",
needMoreSpace = "You do not have enough capacity for all items.",
bought = "You bought |ITEMCOUNT| |ITEMNAME|(s) for |TOTALCOST| gold.",
sold = "You sold |ITEMCOUNT| |ITEMNAME|(s) for |TOTALCOST| gold.",
-- requirement cancel messages
storage = "You do not meet the storage requirement.",
-- bla
storageRange = "You do not meet the storage requirement.",
storageNotEqual = "You do not meet the storage requirement.",
storageToLow = "You do not meet the storage requirement.",
storageToHigh = "You do not meet the storage requirement.",
level = "You need to be exactly level |PLAYERLEVEL|.",
levelRange1 = "You need to be higher then level |PLAYERLEVEL| and below |PLAYERLEVEL2|.", -- > <
levelRange2 = "You need to be level |PLAYERLEVEL| or higher and below |PLAYERLEVEL2|.", -- >= <
levelRange3 = "You need to be higher then level |PLAYERLEVEL| and below or equal |PLAYERLEVEL2|.", -- > <=
levelRange4 = "You need to be between level |PLAYERLEVEL| and |PLAYERLEVEL2|.", -- >= <=
levelNotEqual = "You can't be exactly level |PLAYERLEVEL|.",
levelToLow = "You need to be atleast level |PLAYERLEVEL|.",
levelToHigh = "You need to be below level |PLAYERLEVEL|.",
premium = "You need to be premium to do this.",
vocation = "You need to be a |VOCATIONNAME| to do this.",
money = "You do not have enough money, it costs |TOTALCOST| gold.",
item = "You do not have atleast |ITEMCOUNT| |ITEMNAME|(s).",
infight = "You need to be in fight.",
notInfight = "You have to be out of fight.",
pzLocked = "You need to be pz locked",
notPzLocked = "You are not allowed to be pz locked"
}

-- KEYWORDS_GREET
---@type string[]
KEYWORDS_GREET = {
"hi",
"hello",
"hey",
"greetings"
}

-- MESSAGES_GREET
---@type string[]
MESSAGES_GREET = {
"Hello |PLAYERNAME| how can I help you?",
"Greetings |PLAYERNAME|, what can I do for you?",
"Hi |PLAYERNAME|, what's your desire today?"
}

-- KEYWORDS_FAREWELL
---@type string[]
KEYWORDS_FAREWELL = {
"bye",
"goodbye",
"farewell",
"cya",
"ciao"
}

-- MESSAGES_FAREWELL
---@type string[]
MESSAGES_FAREWELL = {
"Goodbye |PLAYERNAME|, have a nice day!",
"Farewell |PLAYERNAME|, see you soon!",
"See you later |PLAYERNAME|, take care!"
}

-- FOCUS
---@class FOCUS
---@type table<string, any>
FOCUS = {
-- how long the npc will focus the player in seconds
time = 60,
-- how far the player can step away until the npc loses focus
distance = 5,
-- how near the player has to be to greet the npc
greetDistance = 3
}

-- TALK
---@class TALK
---@type table<string, any>
TALK = {
-- how long in ms the npc will wait before responding
defaultDelay = 1000
}

REQUIREMENTS = {
storage = 1,
level = 2,
premium = 3,
vocation = 4,
money = 5,
item = 6,
inFight = 7,
pzLocked = 8,
removeItem = 9
}
Loading
Loading