修复所有item文件中$nosta变量传递问题
时间：2025年1月19日

## 问题描述
在修复∞耐久物品被错误消耗的问题时，发现item_fireworks()函数中缺少`global $nosta;`声明，
导致$nosta变量在函数内部无法访问，从而使∞耐久度检查失效。

经过全面检查，发现多个item文件中都存在类似的问题。

## 检查范围
遍历了include/game/目录下所有item开头的文件：
- item.weapon.php ✓ 无$nosta使用
- item.recovery.php ✓ 无$nosta使用  
- item.poison.php ✓ 无$nosta使用
- item.trap.php ✓ 无$nosta使用
- item.ammo.php ✓ 无$nosta使用
- item.radar.php ✓ 无$nosta使用
- item.cure.php ✓ 无$nosta使用
- item.skillbook.php ✓ 无$nosta使用
- item.enhance.php ✓ 无$nosta使用
- item.weather.php ❌ 使用$nosta但缺少global声明
- item.electronic.php ✓ 无$nosta使用
- item.giftbox.php ❌ 多个函数使用$nosta但缺少global声明
- item.dice.php ✓ 无$nosta使用
- item.platform.php ❌ 使用$nosta但缺少global声明
- item.tool.php ✓ 已正确声明global $nosta
- item.other.php ❌ item_fireworks函数缺少global声明（已知问题）

## 修复内容

### 1. include/game/item.weather.php
**问题**：item_weather函数使用$nosta但没有声明为global
**修复前**：
```php
function item_weather($itmn, &$data) {
    global $log;
```
**修复后**：
```php
function item_weather($itmn, &$data) {
    global $log, $nosta;
```

### 2. include/game/item.giftbox.php
**问题**：4个函数都使用$nosta但没有声明为global，且destory_single_item调用缺少$nosta检查

#### 2.1 item_giftbox函数
**修复前**：
```php
function item_giftbox($itmn, &$data) {
    global $log, $db, $tablepre, $now, $gamecfg;
```
**修复后**：
```php
function item_giftbox($itmn, &$data) {
    global $log, $db, $tablepre, $now, $gamecfg, $nosta;
```

#### 2.2 item_ygo_box函数
**修复前**：
```php
function item_ygo_box($itmn, &$data) {
    global $log, $now, $gamecfg;
```
**修复后**：
```php
function item_ygo_box($itmn, &$data) {
    global $log, $now, $gamecfg, $nosta;
```

#### 2.3 item_fy_box函数
**修复前**：
```php
function item_fy_box($itmn, &$data) {
    global $log, $now, $gamecfg;
```
**修复后**：
```php
function item_fy_box($itmn, &$data) {
    global $log, $now, $gamecfg, $nosta;
```

#### 2.4 item_debug_box函数
**修复前**：
```php
function item_debug_box($itmn, &$data) {
    global $log, $now, $gamecfg;
```
**修复后**：
```php
function item_debug_box($itmn, &$data) {
    global $log, $now, $gamecfg, $nosta;
```

#### 2.5 destory_single_item调用修复
**修复前**（4处）：
```php
if($itms <= 0) destory_single_item($data,$itmn,1);
```
**修复后**：
```php
if($itms <= 0 && $itms != $nosta) destory_single_item($data,$itmn,1);
```

### 3. include/game/item.platform.php
**问题**：item_platform函数使用$nosta但没有声明为global
**修复前**：
```php
function item_platform($itmn, &$data) {
    global $log, $db, $tablepre;
```
**修复后**：
```php
function item_platform($itmn, &$data) {
    global $log, $db, $tablepre, $nosta;
```

### 4. include/game/item.other.php
**问题**：item_fireworks函数使用$nosta但没有声明为global（已在远端修复）

## 修复原理
$nosta变量在gamedata/resources_1.php中定义为'∞'，用于标识无限耐久度。
在item.main.php中已声明为global变量，但各个item处理函数是独立的函数作用域，
需要在每个使用$nosta的函数中单独声明global。

## 影响的物品类型
此修复影响以下物品类型：
1. 天气控制类物品（item.weather.php）
2. 各种礼品盒类物品（item.giftbox.php）
3. NPC平台类物品（item.platform.php）
4. 烟花类物品（item.other.php中的item_fireworks函数）

## 测试建议
1. 创建耐久度为∞的天气控制物品，使用后确认不会被消耗
2. 创建耐久度为∞的各种礼品盒，使用后确认不会被消耗
3. 创建耐久度为∞的NPC平台物品，使用后确认不会被消耗
4. 创建耐久度为∞的烟花类物品，使用后确认不会被消耗

## 注意事项
1. 此修复确保了所有item处理函数都能正确访问$nosta变量
2. 同时修复了destory_single_item调用中缺少$nosta检查的问题
3. 保持了与旧版本item.func.old的一致性
4. 不影响正常耐久度物品的使用

## 修复完成状态
✓ 所有item文件中的$nosta变量传递问题已修复
✓ 所有destory_single_item调用都已添加$nosta检查
✓ 代码与旧版本逻辑保持一致
✓ 不影响正常耐久度物品的使用

## 技术细节
PHP函数作用域规则要求在函数内部使用全局变量时必须显式声明global。
即使在调用函数的上下文中已经声明了global变量，被调用的函数仍然需要单独声明。
这是PHP语言的基本特性，确保了变量作用域的明确性和安全性。

## 额外发现的问题

### 7. include/game/item.trap.php 第67行
**问题**：item_trap_detector函数直接使用$itms--而没有检查$nosta
**修复前**：
```php
$trapresult = $db->query("SELECT * FROM {$tablepre}maptrap WHERE pls = '$pls' AND itme>='$itme'");
$trpnum = $db->num_rows($trapresult);
$itms--;
if ($itms <= 0) {
    $log .= "<span class=\"red\">$itm</span>用光了。<br>";
    $itm = $itmk = $itmsk = '';
    $itme = $itms = 0;
}
```
**修复后**：
```php
$trapresult = $db->query("SELECT * FROM {$tablepre}maptrap WHERE pls = '$pls' AND itme>='$itme'");
$trpnum = $db->num_rows($trapresult);
if ($itms != $nosta) {
    $itms--;
    if ($itms <= 0) {
        $log .= "<span class=\"red\">$itm</span>用光了。<br>";
        $itm = $itmk = $itmsk = '';
        $itme = $itms = 0;
    }
}
```

### 8. include/game/item.ammo.php 第81行
**问题**：item_ammo_bullets函数直接使用$itms -= $bullet而没有检查$nosta
**修复前**：
```php
} elseif ($bullet >= $itms) {
    $bullet = $itms;
}
$itms -= $bullet;
$weps += $bullet;
$log .= "为<span class=\"red\">$wep</span>装填了<span class=\"red\">$itm</span>，<span class=\"red\">$wep</span>残弹数增加<span class=\"yellow\">$bullet</span>。<br>";
if ($itms <= 0) {
    $log .= "<span class=\"red\">$itm</span>用光了。<br>";
    $itm = $itmk = $itmsk = '';
    $itme = $itms = 0;
}
```
**修复后**：
```php
} elseif ($bullet >= $itms) {
    $bullet = $itms;
}
if ($itms != $nosta) {
    $itms -= $bullet;
    $weps += $bullet;
    $log .= "为<span class=\"red\">$wep</span>装填了<span class=\"red\">$itm</span>，<span class=\"red\">$wep</span>残弹数增加<span class=\"yellow\">$bullet</span>。<br>";
    if ($itms <= 0) {
        $log .= "<span class=\"red\">$itm</span>用光了。<br>";
        $itm = $itmk = $itmsk = '';
        $itme = $itms = 0;
    }
} else {
    $weps += $bullet;
    $log .= "为<span class=\"red\">$wep</span>装填了<span class=\"red\">$itm</span>，<span class=\"red\">$wep</span>残弹数增加<span class=\"yellow\">$bullet</span>。<br>";
}
```

### 9. include/game/item.cure.php 第53行
**问题**：item_cure函数缺少global $nosta声明，且直接使用$itms--
**修复前**：
```php
function item_cure($itmn, &$data) {
    global $log, $exdmginf, $ex_inf;
...
$itms --;
```
**修复后**：
```php
function item_cure($itmn, &$data) {
    global $log, $exdmginf, $ex_inf, $nosta;
...
if ($itms != $nosta) {
    $itms --;
}
```

## 检查结果总结

### ✅ 正确的文件（已有适当的global声明和$nosta检查）：
- item.weapon.php（已正确声明global $nosta）
- item.recovery.php（已正确声明global $nosta）
- item.poison.php（已正确声明global $nosta）
- item.enhance.php（已正确声明global $nosta并正确检查）
- item.skillbook.php（已正确声明global $nosta并正确检查）
- item.tool.php（已正确声明global $nosta）
- item.electronic.php（不使用$nosta）
- item.radar.php（不使用$nosta）
- item.dice.php（不使用$nosta）
- item.ending.php（不使用$nosta）
- item.special_effect.php（不使用$nosta）
- item.npc.php（不使用$nosta）
- item.synthesis.php（不使用$nosta）
- item.club_card.php（不使用$nosta）
- item.nachster_booster.php（不使用$nosta）
- item.nouveau_booster1.php（不使用$nosta）
- item.test.php（不使用$nosta）

### ❌ 已修复的文件：
- item.weather.php（添加global $nosta）
- item.giftbox.php（4个函数添加global $nosta，4处destory_single_item调用添加$nosta检查）
- item.platform.php（添加global $nosta）
- item.other.php（item_fireworks函数添加global $nosta，已在远端修复）
- item.trap.php（修复耐久度减少逻辑）
- item.ammo.php（修复子弹消耗逻辑）
- item.cure.php（添加global $nosta并修复耐久度减少逻辑）

## 相关文件修改列表
- include/game/item.weather.php（添加global $nosta）
- include/game/item.giftbox.php（4个函数添加global $nosta，4处destory_single_item调用添加$nosta检查）
- include/game/item.platform.php（添加global $nosta）
- include/game/item.other.php（item_fireworks函数添加global $nosta，已在远端修复）
- include/game/item.trap.php（修复耐久度减少逻辑）
- include/game/item.ammo.php（修复子弹消耗逻辑）
- include/game/item.cure.php（添加global $nosta并修复耐久度减少逻辑）
