-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.lua
189 lines (172 loc) · 7.27 KB
/
item.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---@meta _
--- The `Item` class is used to create and modify items which can be found in the game.
---
---@class Item
---@field pickupText string The text displayed under the name of the item when it's picked up, usually a short descriptor of the item's functionality
---@field sprite Sprite The sprite of the item. Use items expect a 2 frame sprite, the first one with the `USE` label on it. Other item sprites will only display the first frame
---@field isUseItem boolean Whether the item is a use item or not
---@field useCooldown number *Only applies to use items*: This is the cooldown of the item, in seconds. *default is 45*
---@field displayName string The name of the item as displayed in-game
---@field color Color|ColorText The color of the item's tier in colored text formatting or as a Color object
---@field colour Color alias for `color`
---
---@overload fun(name: string): Item
Item = {}
--[[
---- static functions
--]]
--- Creates a new item.
---
--- # Example
--- Creates a new item called `"Peach"`.
--- ```lua
--- local peach = Item.new("Peach")
--- ```
---
---@param name string The name to give the item within the current namespace
---@return Item
function Item.new(name) end
--- Executes a [namespace search](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html) to find an existing Item.
---
--- See the page on [namespace searching](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html#context-find) for more information.
---
---@param name string
---@param namespace? Namespace
---@return Item
function Item.find(name, namespace) end
--- Executes a [namespace search](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html) to find an existing Item.
---
--- See the page on [namespace searching](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html#context-find-all) for more information.
---
---@param namespace? Namespace
---@return Item[]
function Item.findAll(namespace) end
--- Searches for an item which uses the specified [GMObject](https://saturnyoshi.gitlab.io/RoRML-Docs/class/gmObject.html).
---
---@param object GMObject The object to use to find the item
---@return Item? '' The item if found, otherwise nil
function Item.fromObject(object) end
--[[
---- methods
--]]
--- # Example
--- Creates an instance of the item `exampleItem` at a specific position.
--- ```lua
--- exampleItem:getObject():create(xpos, ypos)
--- ```
---
---@return GMObject '' The [GMObject](https://saturnyoshi.gitlab.io/RoRML-Docs/class/gmObject.html) used to represent the item in the game world.
function Item:getObject() end
--- See the page on [namespace searching](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html#context-origin) for more information.
---
---@return Namespace '' The namespace containing the item
function Item:getOrigin() end
--- See the page on [namespace searching](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html#context-name) for more information.
---
---@return string '' The name of the item
function Item:getName() end
---@alias ItemCallback
---| 'pickup' Fired when a player picks up the item
---| 'use' *Use items only*: Fired when the item is used
---| 'drop' *Use items only*: Fired when the item is dropped as a result of being switched out for another
--- Binds a function to be called when a specific callback is fired.
---
--- The [PlayerInstance](https://saturnyoshi.gitlab.io/RoRML-Docs/class/playerInstance.html) which triggered the callback is always passed to the function.
---
--- # Example
--- Two different ways of achieving the same effect; an item that moves the player 100 pixels upward when picked up.
---
--- 1.
--- ```lua
--- local function itemPickup(player)
--- player.y = player.y - 100
--- end
---
--- customItem:addCallback("pickup", itemPickup)
--- ```
--- 2.
--- ```lua
--- customItem:addCallback("pickup", function(player)
--- player.y = player.y - 100
--- end)
--- ```
---
---@param callback ItemCallback The name of the callback to bind a function to
---@param bind fun(player: PlayerInstance) The function to be run when the callback is fired
function Item:addCallback(callback, bind) end
---@alias LogGroup
---| 'start'
---| 'common'
---| 'common_locked'
---| 'uncommon'
---| 'uncommon_locked'
---| 'rare'
---| 'rare_locked'
---| 'use'
---| 'use_locked'
---| 'boss'
---| 'boss_locked'
---| 'end'
---@class LogArgs
---@field group LogGroup Decides where in the item log your items will appear. Mod items will always appear after base game items of the same rarity
---@field description string A description of the items functionality, usually more detailed than the in-game description. Supports [colored text formatting](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/coloredTextFormatting.html)
---@field priority? string A lore-friendly description of rarity, see the in-game descriptions of items for examples. Not setting this will set it automatically to a default based on what group the Log is set to. Supports [colored text formatting](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/coloredTextFormatting.html)
---@field destination string Shipping destination for the item
---@field date string Estimated delivery date for the item
---@field story string A flavorful story or description relating to the item
--- Creates an entry for the item in the Item Log, alternatively modifies the existing one.
---
--- # Examples
--- Create a fully formed item log for the custom item.
--- Priority has been omitted so that it's set to the default for uncommon items.
--- ```lua
--- customItem:setLog {
--- group = "uncommon",
--- description = "This is what the item does",
--- destination = "City,\nCountry,\nPlanet",
--- date = "mm/DD/YYYY",
--- story = "This is some flavortext for the item."
--- }
--- ```
---
--- Edit a item log description to match the modded changes
--- ```lua
--- Item.find("infusion", "vanilla"):setLog {
--- description = "Killing an enemy increases your &r&health permanently by 0.25.&!&"
--- }
--- ```
---
---@param args LogArgs
function Item:setLog(args) end
--- Sets the `color` of the item (Usually "w", "g", "r", "or", and "p" for common, uncommon, rare, use, and special items respectively)
--- and adds it to the appropriate [ItemPool](https://saturnyoshi.gitlab.io/RoRML-Docs/class/itemPool.html).
--- If the item is already in the common, uncommon, rare, or use pool then it will be removed
---
--- # Examples
--- Both of the below code examples achieve the same effect.
--- However, the example utilizing `setTier` is much more concise.
---
--- 1.
--- ```lua
--- customItem:setTier("common")
--- ```
--- 2.
--- ```lua
--- ItemPool.find("common"):add(customItem)
--- customItem.color = "w"
--- ```
---
---@param tier 'common'|'uncommon'|'rare'|'use'|string
function Item:setTier(tier) end
--- Creates a new instance of the item. Can be used as a shortcut to `item:getObject():create(x, y)`.
---
--- # Example
--- Create an instance of the item `exampleItem` at a specific position.
--- ```lua
--- exampleItem:getObject():create(xpos, ypos)
--- ```
---
---@param x number The horizontal coordinate to create an instance of the item at
---@param y number The vertical coordinate to create an instance of the item at
---@return Instance '' The newly created instance
function Item:create(x, y) end