Module_items.py trong phát triển MOD Mount & Blade: Warband

Trong trò chơi, vật phẩm (Item) tồn tại ở hai dạng chính: trên bản đồ chiến dịch và trong cảnh trận đánh. Mỗi loại có cách xử lý và lưu trữ khác nhau.

Cấu trúc kho đồ của nhân vật

Mỗi đơn vị (Troop) sở hữu một kho đồ (Inventory) với các ô trang bị cố định:

ek_slot_0
ek_slot_1
ek_slot_2
ek_slot_3
ek_headgear
ek_chestplate
ek_footwear
ek_handgear
ek_mount
ek_provisions

Các hàm thao tác với kho đồ bao gồm:

equip_troop_items
get_inventory_size
fetch_inventory_item
update_inventory_slot
get_free_space
add_item_to_troop
remove_item_from_troop
count_item_instances

Vật phẩm trong trận chiến

Khi vào trận, vật phẩm được khởi tạo thành SceneItem và gắn vào Agent thông qua hệ thống xương:

primary_weapon
secondary_weapon
tertiary_weapon
quaternary_weapon
helmet
armor
boots
gauntlets

Các hành động liên quan đến trang bị trong trận:

get_current_weapon
switch_to_weapon
get_equipment_at_slot
equip_agent_item
unequip_agent_item

# Sự kiện tương tác
on_item_pickup
on_item_drop
on_weapon_equip
on_weapon_unequip

Vũ khí cận chiến

Phân loại theo kiểu cầm nắm:

itp_melee_onehand   = 0x00000002
itp_melee_twohand   = 0x00000003
itp_melee_polearm   = 0x00000004

Hành vi tấn công được xác định bởi capability flags:

# Polearms
itcf_polearm_thrust
itcf_polearm_overhead
itcf_polearm_right_slash
itcf_polearm_left_slash

# One-handed
itcf_onehand_thrust
itcf_onehand_overhead
itcf_onehand_right_slash
itcf_onehand_left_slash

# Two-handed
itcf_twohand_thrust
itcf_twohand_overhead
itcf_twohand_right_slash
itcf_twohand_left_slash

Tính toán đặc tính vũ khí:

def attack_speed(val):
    return ((val & 0x3FF) << 8)

def reach_distance(val):
    return ((val & 0x3FF) << 16)

Vũ khí tầm xa

Loại vũ khí:

itp_ranged_bow      = 0x00000008
itp_ranged_crossbow = 0x00000009
itp_ranged_thrown   = 0x0000000A
itp_ranged_pistol   = 0x00000010
itp_ranged_musket   = 0x00000011

Đạn dược tương ứng:

itp_ammo_arrows     = 0x00000005
itp_ammo_bolts      = 0x00000006
itp_ammo_bullets    = 0x00000012

Hành vi bắn:

itcf_fire_bow
itcf_fire_crossbow
itcf_fire_pistol
itcf_fire_musket
itcf_throw_stone
itcf_throw_axe

Thuộc tính đạn đạo:

def projectile_speed(val):
    return ((val & 0x3FF) << 24)

def firing_range(val):
    return ((val & 0x3FF) << 16)

Quản lý đạn dược:

get_max_ammo_capacity
get_agent_ammo_count
get_current_ammo_in_slot
refill_agent_ammo
set_agent_ammo_amount

Khiên và ngựa

Xử lý va chạm khi khiên bị đánh trúng:

on_shield_impact (trigger)
# Param 1: agent bị đánh
# Param 2: agent tấn công
# Param 3: sát thương gây ra
# Param 4: loại vũ khí
# Param 5: loại đạn (nếu có)

Thuộc tính ngựa:

def mount_scale(val):
    return ((val & 0x3FF) << 16)

def mount_speed(val):
    return projectile_speed(val)

def mount_handling(val):
    return attack_speed(val)

def mount_charge_power(val):
    return thrust_damage(val, 0)

Vật phẩm thương mại

Các vật phẩm có cờ itp_merchandise sẽ xuất hiện trong cửa hàng. Hệ thống sử dụng các lệnh sau để quản lý giá cả và xác suất xuất hiện:

reset_commodity_prices
set_price_modifier_for_item
set_price_modifier_by_type
adjust_merchant_quality
set_max_merchant_value
reset_stock_probabilities
set_item_stock_probability
restock_merchant_inventory
restock_merchant_by_faction

Thẻ: Mount&Blade Warband MOD python module_items

Đăng vào ngày 16 tháng 7 lúc 22:55