7. 装备与经济系统
2026/4/15大约 3 分钟
7. 装备与经济系统:打怪赚钱买装备
7.1 经济系统概述
MOBA 游戏的经济循环很简单:打怪/补刀赚金币 → 花金币买装备 → 装备让你更强 → 更容易打怪/杀敌。这个循环就是 MOBA 游戏的核心驱动力。
金币来源
| 来源 | 金币数 | 说明 |
|---|---|---|
| 补刀小兵 | 15-40 | 给小兵最后一击 |
| 击杀英雄 | 200+等级×20 | 击杀敌方英雄 |
| 助攻 | 击杀金币×50% | 协助队友击杀 |
| 推塔 | 150 | 参与推塔 |
| 自然增长 | 2/秒 | 什么不做也在慢慢赚钱 |
| 野怪 | 30-100 | 击杀野区怪物 |
7.2 装备数据定义
C#
// ItemData.cs
using Godot;
[GlobalClass]
public partial class ItemData : Resource
{
[Export] public string ItemId { get; set; } = "";
[Export] public string ItemName { get; set; } = "";
[Export] public string Description { get; set; } = "";
[Export] public int Cost { get; set; } = 300;
[Export] public Texture2D Icon { get; set; }
// 属性加成
[Export] public float BonusHp { get; set; } = 0;
[Export] public float BonusMp { get; set; } = 0;
[Export] public float BonusAd { get; set; } = 0; // 物理攻击
[Export] public float BonusAp { get; set; } = 0; // 法术强度
[Export] public float BonusArmor { get; set; } = 0;
[Export] public float BonusMr { get; set; } = 0; // 魔抗
[Export] public float BonusAttackSpeed { get; set; } = 0;
[Export] public float BonusMoveSpeed { get; set; } = 0;
[Export] public float BonusCritChance { get; set; } = 0;
// 合成配方
[Export] public string[] Components { get; set; } = new string[0]; // 合成所需的子装备ID
}GDScript
# item_data.gd
class_name ItemData
extends Resource
@export var item_id: String = ""
@export var item_name: String = ""
@export var description: String = ""
@export var cost: int = 300
@export var icon: Texture2D
# 属性加成
@export var bonus_hp: float = 0
@export var bonus_mp: float = 0
@export var bonus_ad: float = 0 # 物理攻击
@export var bonus_ap: float = 0 # 法术强度
@export var bonus_armor: float = 0
@export var bonus_mr: float = 0 # 魔抗
@export var bonus_attack_speed: float = 0
@export var bonus_move_speed: float = 0
@export var bonus_crit_chance: float = 0
# 合成配方
@export var components: Array[String] = []7.3 装备商店
商店在基地附近,英雄走到商店区域时可以打开购买界面:
C#
// ItemShop.cs
using Godot;
using System.Collections.Generic;
public partial class ItemShop : Node
{
private Dictionary<string, ItemData> _allItems = new();
private Dictionary<string, ItemData> _availableItems = new(); // 当前可购买的
public override void _Ready()
{
LoadAllItems();
}
private void LoadAllItems()
{
// 加载所有装备数据
var dir = DirAccess.Open("res://resources/items/");
if (dir != null)
{
dir.ListDirBegin();
string fileName = dir.GetNext();
while (fileName != "")
{
if (fileName.EndsWith(".tres"))
{
var item = GD.Load<ItemData>($"res://resources/items/{fileName}");
if (item != null)
_allItems[item.ItemId] = item;
}
fileName = dir.GetNext();
}
}
}
// 购买装备
public bool BuyItem(string itemId, HeroBase hero)
{
if (!_allItems.TryGetValue(itemId, out var item)) return false;
// 检查金币够不够
if (hero.Gold < item.Cost) return false;
// 检查背包是否已满(最多6件装备)
if (hero.GetItemCount() >= 6) return false;
// 扣钱、添加装备
hero.SpendGold(item.Cost);
hero.AddItem(item);
ApplyItemStats(item, hero);
return true;
}
// 卖出装备(返还60%金币)
public bool SellItem(string itemId, HeroBase hero)
{
var item = hero.RemoveItem(itemId);
if (item == null) return false;
RemoveItemStats(item, hero);
hero.GainGold((int)(item.Cost * 0.6f));
return true;
}
// 应用装备属性
private void ApplyItemStats(ItemData item, HeroBase hero)
{
// 将装备属性加成应用到英雄身上
hero.BonusStats.Ad += item.BonusAd;
hero.BonusStats.Ap += item.BonusAp;
hero.BonusStats.Hp += item.BonusHp;
hero.BonusStats.Armor += item.BonusArmor;
hero.BonusStats.Mr += item.BonusMr;
hero.BonusStats.AttackSpeed += item.BonusAttackSpeed;
hero.BonusStats.MoveSpeed += item.BonusMoveSpeed;
}
private void RemoveItemStats(ItemData item, HeroBase hero)
{
hero.BonusStats.Ad -= item.BonusAd;
hero.BonusStats.Ap -= item.BonusAp;
hero.BonusStats.Hp -= item.BonusHp;
hero.BonusStats.Armor -= item.BonusArmor;
hero.BonusStats.Mr -= item.BonusMr;
hero.BonusStats.AttackSpeed -= item.BonusAttackSpeed;
hero.BonusStats.MoveSpeed -= item.BonusMoveSpeed;
}
}GDScript
# item_shop.gd
extends Node
var all_items: Dictionary = {}
func _ready():
load_all_items()
func load_all_items():
var dir = DirAccess.open("res://resources/items/")
if dir:
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if file_name.ends_with(".tres"):
var item = load("res://resources/items/%s" % file_name)
if item:
all_items[item.item_id] = item
file_name = dir.get_next()
func buy_item(item_id: String, hero: Node3D) -> bool:
var item: ItemData = all_items.get(item_id)
if item == null:
return false
if hero.gold < item.cost:
return false
if hero.get_item_count() >= 6:
return false
hero.spend_gold(item.cost)
hero.add_item(item)
apply_item_stats(item, hero)
return true
func sell_item(item_id: String, hero: Node3D) -> bool:
var item = hero.remove_item(item_id)
if item == null:
return false
remove_item_stats(item, hero)
hero.gain_gold(int(item.cost * 0.6))
return true
func apply_item_stats(item: ItemData, hero: Node3D):
hero.bonus_stats.ad += item.bonus_ad
hero.bonus_stats.ap += item.bonus_ap
hero.bonus_stats.hp += item.bonus_hp
hero.bonus_stats.armor += item.bonus_armor
hero.bonus_stats.mr += item.bonus_mr
hero.bonus_stats.attack_speed += item.bonus_attack_speed
hero.bonus_stats.move_speed += item.bonus_move_speed
func remove_item_stats(item: ItemData, hero: Node3D):
hero.bonus_stats.ad -= item.bonus_ad
hero.bonus_stats.ap -= item.bonus_ap
hero.bonus_stats.hp -= item.bonus_hp
hero.bonus_stats.armor -= item.bonus_armor
hero.bonus_stats.mr -= item.bonus_mr
hero.bonus_stats.attack_speed -= item.bonus_attack_speed
hero.bonus_stats.move_speed -= item.bonus_move_speed7.4 示例装备列表
| 装备名称 | 价格 | 属性加成 | 适合英雄 |
|---|---|---|---|
| 长剑 | 350 | +10 攻击力 | 战士、射手 |
| 布甲 | 300 | +20 护甲 | 战士 |
| 法术书 | 400 | +20 法术强度 | 法师 |
| 速度之靴 | 300 | +2 移速 | 所有英雄 |
| 暴烈之甲 | 1200 | +30 攻击力, +30 护甲 | 战士 |
| 破军 | 2400 | +60 攻击力, +20% 暴击 | 射手、战士 |
| 回响之杖 | 2100 | +80 法术强度 | 法师 |
| 不死鸟之眼 | 2000 | +200 生命, +40 魔抗 | 战士 |
| 影刃 | 1800 | +40 攻击力, +30% 攻速 | 射手 |
| 冰霜法杖 | 1500 | +50 法强, 减速效果 | 法师 |
章节导航
| 上一章 | 下一章 |
|---|---|
| ← 6. 小兵与防御塔 | 8. AI队友与敌方 → |
