How the Item Mixing System Works in itemmix.func.php: Weapon Modification Explained

The PHPDTS game engine implements a three-tier item mixing system in include/game/itemmix.func.php that validates player inventories, matches selections against normal, synchro, and overlay recipe tables, and executes weapon modifications by consuming source items and creating enhanced equipment with updated durability and attack statistics.

The PHPDTS open-source game repository (amarillonmc/phpdts) contains a sophisticated crafting mechanism that allows players to combine items into new weapons and tools. Located in include/game/itemmix.func.php, this system processes mixing requests through distinct validation and execution phases, supporting everything from simple material combinations to complex weapon upgrades using tuner items and star-count matching.

Architecture of the Three-Tier Mixing Engine

The mixing engine operates through a sequential pipeline that validates inputs, discovers applicable recipes, and executes the transformation. Each stage is handled by specific functions within the core mixing file.

Entry Point and Validation (itemmix_rev and itemmix_place_check)

The process begins at itemmix_rev() (lines 12-54), which serves as the primary entry point for all mixing requests. This function accepts an array of inventory slot indices selected by the player and immediately delegates to itemmix_place_check() (lines 15-48) to validate the request. The validation routine ensures the selected slots exist, contain distinct items, and that the player is permitted to mix—specifically checking for club 20 restrictions which completely bans item mixing for those players.

Recipe Discovery (itemmix_get_result)

Once validated, itemmix_get_result() (lines 55-96) aggregates all possible crafting outcomes by querying three sub-checkers in parallel. This function returns an array of matching mix definitions that the engine will later present to the player or execute directly if only one result exists.

Normal Recipe Matching (itemmix_recipe_check)

For standard crafting combinations, itemmix_recipe_check() (lines 50-68) handles the logic by loading the static recipe table via get_mixinfo(). It sorts the input item names alphabetically and compares this sorted list against each recipe's required "stuff" array, looking for exact name matches to determine valid normal mixes.

Synchro Processing (itemmix_sync_check)

The itemmix_sync_check() function (lines 73-148) manages synchro (同调) mixes, which are essential for weapon modification. This routine calculates the total star value of all input items, identifies a single "tuner" item marked with the s flag, and queries get_syncmixinfo() to find a matching result based on the combined star count and tuner presence.

Overlay Processing (itemmix_overlay_check)

For overlay (超量) combinations, itemmix_overlay_check() (lines 73-108) requires all materials to share an identical star count and validates them as overlay-eligible through check_valid_overlay_material(). Valid materials carry either the J flag or a "★N" naming pattern without the "‑仮" suffix. The function then matches the star-count and material-count pair against the overlay table retrieved from get_overlaymixinfo().

Execution Phase (itemmix_proc)

Finally, itemmix_proc() (lines 46-94) executes the chosen recipe. This function consumes the source items using itemreduce(), populates the result variables ($itm0, $itmk0, $itme0, $itms0, $itmsk0) with the new item's properties, logs the mixing event, triggers additional effects through itemmix_events(), and adds the finished item to the player's inventory via itemget().

Understanding Normal, Synchro, and Overlay Mix Types

The engine categorizes all possible combinations into three distinct paradigms, each with specific rules for identifying valid inputs and producing outputs.

Normal (type = 'normal') mixes represent straightforward recipes where an exact list of item names produces a specific result. The engine matches sorted input names against the static recipe table without additional flags or calculations.

Synchro (type = 'sync') mixes enable weapon modification by requiring exactly one tuner item (identified by the s flag) combined with base weapons or materials. The total star value of all inputs determines the resulting upgraded weapon, often granting enhanced attack values or elemental attributes.

Overlay (type = 'overlay') mixes create higher-tier weapons by combining multiple items of the same star value. These require overlay-eligible materials and produce weapons with increased durability and special flags based on the specific star-count and material-count combination matched in the overlay table.

Weapon Modification Mechanics

Weapon modification in PHPDTS primarily occurs through the synchro and overlay systems, allowing players to upgrade base weapons into more powerful variants with modified statistics.

Synchro Upgrades with Tuner Items

In a synchro modification, the player combines a base weapon with a tuner item such as "星尘" or "调律器" (items bearing the s flag). When the star total matches an entry in the synchro recipe table, itemmix_proc() creates a new weapon instance that typically inherits the base weapon's core properties while gaining improved attack power ($itme0), enhanced durability ($itms0), or additional special flags ($itmsk0). The original base weapon and the consumed tuner are permanently removed via itemreduce().

Overlay Weapon Creation

Overlay modification requires multiple weapons or cards of identical star ratings. For example, combining three ★4 weapons marked as overlay materials produces a single ★5 weapon with boosted statistics. The check_valid_overlay_material() function validates that each input carries the J flag or follows the proper naming convention. The resulting weapon from itemmix_proc() often features significantly enhanced durability and attack values compared to the individual source items.

Post-Mix Durability Tracking

While mixing creates weapons with initial durability values defined in the recipe tables, subsequent combat affects these values through the weapon_loss() function located in include/game/itemmain.func.php (lines 21-90). This function reduces either the weapon's attack power (wepe) or durability (weps) based on the weapon type ($pa['wep_kind']) and damage received. When durability reaches zero, the system marks the weapon as broken and removes it from equipment slots.

Code Implementation Examples

Performing a Normal Mix

// Player selects inventory slots 1 and 3 for a standard recipe
$mlist = [1, 3];
itemmix_rev($mlist);

This triggers the validation chain, matches the item names against get_mixinfo(), and executes itemmix_proc() to deliver the resulting item directly to the player's inventory.

Executing a Synchro Weapon Upgrade

// Slot 2 contains a ★5 "雷霆剑", slot 5 contains a tuner "星尘" with 's' flag
$mlist = [2, 5];
itemmix_rev($mlist);

If the star total (5 + tuner value) matches a synchro recipe, the system replaces both items with an enhanced "雷霆剑·星辉" featuring upgraded statistics.

Creating an Overlay Weapon

// Three ★4 weapons, all valid overlay materials (flag J or "★4" naming)
$mlist = [1, 2, 3];
itemmix_rev($mlist);

Matching the star=4 and count=3 criteria against get_overlaymixinfo() yields a new ★5 weapon with combined durability and attack bonuses.

Simulating Weapon Durability Loss

// During combat resolution, applying damage to a player's weapon
$damage = 15;
weapon_loss($pa, $damage);

This reduces the weapon's durability or attack power based on $pa['wep_kind'], potentially destroying the item if the value drops to zero.

Summary

  • The item mixing system resides in include/game/itemmix.func.php and processes requests through itemmix_rev(), validating selections via itemmix_place_check().
  • Three distinct mix types exist: normal (exact name matching), synchro (tuner + star calculation), and overlay (uniform star count materials).
  • Weapon modification primarily occurs through synchro and overlay mixes, creating enhanced weapons with improved durability ($itms0) and attack ($itme0).
  • The execution phase in itemmix_proc() consumes source items with itemreduce() and adds results via itemget().
  • Post-crafting weapon durability is managed by weapon_loss() in itemmain.func.php, which applies wear-and-tear during combat.
  • Special club restrictions (club 20 bans mixing) and bonuses (club 12 doubles supplies, club 5 increases bomb durability) are handled during validation and event phases.

Frequently Asked Questions

What is the entry point function for item mixing in PHPDTS?

itemmix_rev() serves as the primary entry point located at lines 12-54 of include/game/itemmix.func.php. This function accepts an array of inventory slot indices, validates the selection through itemmix_place_check(), and either presents multiple recipe options to the player or automatically executes the mix via itemmix_proc() if only one valid result exists.

How does the synchro mixing system modify weapons?

Synchro mixing modifies weapons by combining a base weapon with a tuner item (marked with the s flag) and calculating the total star value of all inputs. The itemmix_sync_check() function queries get_syncmixinfo() to find a matching result, then itemmix_proc() creates a new weapon instance with enhanced statistics, consuming both the base weapon and the tuner while logging the upgrade as a "同调" mix type.

What validation prevents invalid item combinations?

The itemmix_place_check() function (lines 15-48) enforces validation by confirming that selected slots exist, contain distinct items, and that the player is not restricted by club 20 (which bans mixing entirely). Additional type-specific validation occurs in sub-checkers: normal mixes require exact name lists, synchro mixes require exactly one tuner item, and overlay mixes require uniform star counts with valid overlay material flags.

How does weapon durability decrease after mixing?

While itemmix_proc() sets the initial durability ($itms0) based on the recipe definition, subsequent durability loss occurs during combat through the weapon_loss() function in include/game/itemmain.func.php (lines 21-90). This function reduces the weapon's weps (durability) or wepe (attack) properties based on damage received and weapon type, potentially destroying the item when values reach zero.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →