Modding:Weapons: Difference between revisions
imported>Margotbean m Text replacement - "tt>" to "samp>" |
imported>Sunbeam135 No edit summary |
||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
← [[Modding: | ← [[Modding:Items|Items]] | ||
This page explains how the game stores and parses weapon data. | This page explains how the game stores and parses weapon-type item data. For items in general, see [[Modding:Items]]. | ||
== | ==Overview== | ||
[[Weapons]] are tools that can be swung or used by the player to damage monsters. | |||
They have [[Modding:Items#Item types|item type]] <code>(W)</code> (or <code>ItemRegistry.type_weapon</code> in C# code), their data in <samp>Data/Weapons</samp>, their in-game sprites in <samp>TileSheets/weapons</samp> by default, and their code in <samp>StardewValley.Tools.MeleeWeapon</samp> and <samp>StardewValley.Tools.Slingshot</samp>. | |||
</ | |||
== | ==Data format== | ||
The weapon data in <samp>Data/Weapons</samp> consists of a string → model lookup, where... | |||
The weapon data in <samp>Data | * The key is the [[Modding:Common data field types#Item ID|unqualified item ID]]. | ||
* The value is model with the fields listed below. | |||
===Basic weapon info=== | |||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! | ! field | ||
! | ! effect | ||
|- | |- | ||
| | | <samp>Name</samp> | ||
| The internal weapon name. | |||
| name | |||
|- | |- | ||
| | | <samp>DisplayName</samp><br /><samp>Description</samp> | ||
| | | A [[Modding:Tokenizable strings|tokenizable string]] for the translated display name & description. | ||
| description | |||
|- | |- | ||
| 2 | | <samp>Type</samp> | ||
| | | The weapon type. One of <samp>0</samp> (stabbing sword), <samp>1</samp> (dagger), <samp>2</samp> (club or hammer), or <samp>3</samp> (slashing sword). | ||
| | |} | ||
===Appearance=== | |||
{| class="wikitable" | |||
|- | |- | ||
! field | |||
! effect | |||
|- | |- | ||
| | | <samp>Texture</samp> | ||
| ' | | The asset name for the spritesheet containing the weapon's sprite. | ||
|- | |- | ||
| | | <samp>SpriteIndex</samp> | ||
| | | The index within the <samp>Texture</samp> for the weapon sprite, where 0 is the top-left sprite. | ||
| | |} | ||
===Stats=== | |||
{| class="wikitable" | |||
|- | |- | ||
! field | |||
! effect | |||
|- | |- | ||
| | | <samp>MinDamage</samp><br /><samp>MaxDamage</samp> | ||
| | | The minimum and maximum based damage caused when hitting a monster with this weapon. | ||
|- | |- | ||
| | | <samp>Knockback</samp> | ||
| '' | | ''(Optional)'' How far the target is pushed when hit, as a multiplier relative to a base weapon like the [[Rusty Sword]] (e.g. <samp>1.5</samp> for 150% of Rusty Sword's weight). Default 1. | ||
|- | |- | ||
| | | <samp>Speed</samp> | ||
| '' | | ''(Optional)'' How fast the player can swing the weapon. Each point of speed is worth 40ms of swing time relative to 0. This stacks with the [[speed|player's weapon speed]]. Default 0. | ||
|- | |- | ||
| | | <samp>Precision</samp> | ||
| '' | | ''(Optional)'' Reduces the chance that a strike will miss. Default 0. | ||
|- | |- | ||
| | | <samp>Defense</samp> | ||
| '' | | ''(Optional)'' Reduces damage received by the player. Default 0. | ||
|- | |- | ||
| | | <samp>AreaOfEffect</samp> | ||
| '' | | ''(Optional)'' Slightly increases the area of effect. Default 0. | ||
|- | |- | ||
| | | <samp>CritChance</samp> | ||
| '' | | ''(Optional)'' The chance of a critical hit, as a decimal value between 0 (never) and 1 (always). Default 0.02. | ||
|- | |- | ||
| | | <samp>CritMultiplier</samp> | ||
| | | ''(Optional)'' A multiplier applied to the base damage for a critical hit. This can be a decimal value. Default 3. | ||
|} | |} | ||
===Game logic=== | |||
{| class="wikitable" | |||
|- | |||
! field | |||
! effect | |||
|- | |||
| <samp>CanBeLostOnDeath</samp> | |||
| Whether the player can [[Adventurer's Guild#Item Recovery Service|lose this tool when they die]]. Default true. | |||
|- | |||
| <samp>MineBaseLevel</samp><br /><samp>MineMinLevel</samp> | |||
| ''(Optional)'' The base and minimum mine level, which affect [[#Mine container drops|mine container drops]]. Both default to -1, which disables automatic mine drops. | |||
|} | |||
=== | ===Advanced=== | ||
The | {| class="wikitable" | ||
|- | |||
! field | |||
! effect | |||
|- | |||
| <samp>Projectiles</samp> | |||
| ''(Optional)'' The projectiles fired when the weapon is used, which continue along their path until they hit a monster and cause damage. A separate projectile is fired for each entry in this list. | |||
This consists of a list of models with these fields (one projectile will fire for each entry in the list): | |||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! | ! field | ||
! | ! effect | ||
|- | |- | ||
| 0 | | <samp>Id</samp> | ||
| '' | | The [[Modding:Common data field types#Unique string ID|unique string ID]] for the projectile within the current weapon's data. | ||
| | |- | ||
| <samp>Damage</samp> | |||
| ''(Optional)'' The amount of damage caused when the projectile hits a monster. Default 10. | |||
|- | |||
| <samp>Explodes</samp> | |||
| ''(Optional)'' Whether the projectile explodes when it collides with something. Default false. | |||
|- | |||
| <samp>Bounces</samp> | |||
| ''(Optional)'' The number of times the projectile can bounce off walls before being destroyed. Default 0. | |||
|- | |||
| <samp>MaxDistance</samp> | |||
| ''(Optional)'' The maximum tile distance the projectile can travel. Default 4. | |||
|- | |||
| <samp>Velocity</samp> | |||
| ''(Optional)'' The speed at which the projectile moves. Default 10. | |||
|- | |||
| <samp>RotationVelocity</samp> | |||
| ''(Optional)'' The rotation velocity. Default 32. | |||
|- | |||
| <samp>TailLength</samp> | |||
| ''(Optional)'' The length of the tail which trails behind the main projectile. Default 1. | |||
|- | |||
| <samp>FireSound</samp><br /><samp>BounceSound</samp><br /><samp>CollisionSound</samp> | |||
| ''(Optional)'' The sound played when the projectile is fired, bounces off a wall, or collides with something. All three default to none. | |||
|- | |- | ||
| | | <samp>MinAngleOffset</samp><br /><samp>MaxAngleOffset</samp> | ||
| '' | | ''(Optional)'' A random offset applied to the direction of the project each time it's fired. Both fields default to 0, in which case it's always shot at the 90° angle matching the player's facing direction. | ||
|- | |- | ||
| | | <samp>SpriteIndex</samp> | ||
| '' | | ''(Optional)'' The sprite index in the <samp>TileSheets/Projectiles</samp> asset to draw for this projectile. Defaults to 11 (a glowing-yellow-ball sprite). | ||
|- | |- | ||
| | | <samp>Item</samp> | ||
| '' | | ''(Optional)'' The item to shoot. If set, this overrides <samp>SpriteIndex</samp>. | ||
| | |||
This consists of a list of models with these fields: | |||
{| class="wikitable" | |||
|- | |||
! field | |||
! effect | |||
|- | |||
| ''common fields'' | |||
| See [[Modding:Item queries#Item spawn fields|item spawn fields]] for the generic item fields supported for ammo items. | |||
If set to an [[Modding:Item queries|item query]] which returns multiple items, one of them will be selected at random. | |||
|} | |||
|} | |||
Note that these are magic projectiles fired when the weapon is used, they're not aimed directly like [[slingshot]] projectiles. | |||
|- | |- | ||
| | | <samp>CustomFields</samp> | ||
| | | The [[Modding:Common_data_field_types#Custom_fields|custom fields]] for this entry. | ||
| | |||
|} | |} | ||
Weapons have a hardcoded category of -98 (<samp>Object.weaponCategory</samp>). | |||
Slingshot damage is [[Slingshot#Ammunition|calculated dynamically]] regardless of the weapon data. | ==Implementation notes== | ||
===Slingshots=== | |||
* The base [[slingshot]] has <samp>ParentSheetIndex</samp> 32 in the weapon data, which increases by one for each upgrade level (up to 34 in the weapon data, though only 32 and 33 are obtainable without mods). | |||
* Slingshot damage is [[Slingshot#Ammunition|calculated dynamically]] regardless of the weapon data. | |||
==Mine container drops== | ===Mine container drops=== | ||
When the player breaks a container in [[The Mines|the mines]], there's a chance it will drop a weapon. Here's how the weapon to drop is chosen<ref>See <samp>Utility.getUncommonItemForThisMineLevel</samp> in the game code.</ref>: | When the player breaks a container in [[The Mines|the mines]], there's a chance it will drop a weapon. Here's how the weapon to drop is chosen<ref>See <samp>Utility.getUncommonItemForThisMineLevel</samp> in the game code.</ref>: | ||
<ol> | <ol> | ||
<li>Match weapons whose | <li>Match weapons whose [[#Game logic|minimum mine level]] is less than the current mine level.</li> | ||
<li>From that list, match weapons with a probability check based on the gap between the | <li>From that list, match weapons with a probability check based on the gap between the [[#Game logic|base mine level]] and current mine level. The probability is a bell curve centered on the base mine level: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| Line 217: | Line 198: | ||
==References== | ==References== | ||
<references /> | <references /> | ||
==See also== | |||
* [[Modding:Items]] for item data in general | |||
[[Category:Modding]] | [[Category:Modding]] | ||
[[ru:Модификации:Оружие]] | [[ru:Модификации:Оружие]] | ||
[[zh:模组:武器]] | |||
Latest revision as of 22:23, 12 January 2026
← Items
This page explains how the game stores and parses weapon-type item data. For items in general, see Modding:Items.
Overview
Weapons are tools that can be swung or used by the player to damage monsters.
They have item type (W) (or ItemRegistry.type_weapon in C# code), their data in Data/Weapons, their in-game sprites in TileSheets/weapons by default, and their code in StardewValley.Tools.MeleeWeapon and StardewValley.Tools.Slingshot.
Data format
The weapon data in Data/Weapons consists of a string → model lookup, where...
- The key is the unqualified item ID.
- The value is model with the fields listed below.
Basic weapon info
| field | effect |
|---|---|
| Name | The internal weapon name. |
| DisplayName Description |
A tokenizable string for the translated display name & description. |
| Type | The weapon type. One of 0 (stabbing sword), 1 (dagger), 2 (club or hammer), or 3 (slashing sword). |
Appearance
| field | effect |
|---|---|
| Texture | The asset name for the spritesheet containing the weapon's sprite. |
| SpriteIndex | The index within the Texture for the weapon sprite, where 0 is the top-left sprite. |
Stats
| field | effect |
|---|---|
| MinDamage MaxDamage |
The minimum and maximum based damage caused when hitting a monster with this weapon. |
| Knockback | (Optional) How far the target is pushed when hit, as a multiplier relative to a base weapon like the Rusty Sword (e.g. 1.5 for 150% of Rusty Sword's weight). Default 1. |
| Speed | (Optional) How fast the player can swing the weapon. Each point of speed is worth 40ms of swing time relative to 0. This stacks with the player's weapon speed. Default 0. |
| Precision | (Optional) Reduces the chance that a strike will miss. Default 0. |
| Defense | (Optional) Reduces damage received by the player. Default 0. |
| AreaOfEffect | (Optional) Slightly increases the area of effect. Default 0. |
| CritChance | (Optional) The chance of a critical hit, as a decimal value between 0 (never) and 1 (always). Default 0.02. |
| CritMultiplier | (Optional) A multiplier applied to the base damage for a critical hit. This can be a decimal value. Default 3. |
Game logic
| field | effect |
|---|---|
| CanBeLostOnDeath | Whether the player can lose this tool when they die. Default true. |
| MineBaseLevel MineMinLevel |
(Optional) The base and minimum mine level, which affect mine container drops. Both default to -1, which disables automatic mine drops. |
Advanced
| field | effect | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Projectiles | (Optional) The projectiles fired when the weapon is used, which continue along their path until they hit a monster and cause damage. A separate projectile is fired for each entry in this list.
This consists of a list of models with these fields (one projectile will fire for each entry in the list):
Note that these are magic projectiles fired when the weapon is used, they're not aimed directly like slingshot projectiles. | ||||||||||||||||||||||||||||||
| CustomFields | The custom fields for this entry. |
Weapons have a hardcoded category of -98 (Object.weaponCategory).
Implementation notes
Slingshots
- The base slingshot has ParentSheetIndex 32 in the weapon data, which increases by one for each upgrade level (up to 34 in the weapon data, though only 32 and 33 are obtainable without mods).
- Slingshot damage is calculated dynamically regardless of the weapon data.
Mine container drops
When the player breaks a container in the mines, there's a chance it will drop a weapon. Here's how the weapon to drop is chosen[1]:
- Match weapons whose minimum mine level is less than the current mine level.
- From that list, match weapons with a probability check based on the gap between the base mine level and current mine level. The probability is a bell curve centered on the base mine level:
The difference applies in both directions; for example, two weapons whose base levels are 5 below and 5 above the current level both have a 92% chance. (The probability is calculated with a Gaussian functionlevel difference probability 0 100% 5 92% 10 71% 15 46% 20 25% 25 4% e-(current mine level - base mine level)2 / (2 * 122).) - Find the weapon with the smallest gap between the current and base mine levels, and add it to the list. (If the item was also selected in step 2, it has two chances to drop.)
- From the remaining list of weapons, randomly choose one to drop.
References
- ↑ See Utility.getUncommonItemForThisMineLevel in the game code.
See also
- Modding:Items for item data in general