赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 642 |
最后登录 | 2015-3-3 |
在线时间 | 37 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 37 小时
- 注册时间
- 2015-2-13
- 帖子
- 126
|
3楼
楼主 |
发表于 2015-2-23 10:07:38
|
只看该作者
- #==============================================================================
- # ■ Game_Party
- #------------------------------------------------------------------------------
- # 处理同伴的类。包含金钱以及物品的信息。本类的实例请参考 $game_party。
- #==============================================================================
- class Game_Party < Game_Unit
- #--------------------------------------------------------------------------
- # ● 常量
- #--------------------------------------------------------------------------
- MAX_MEMBERS = 4 # 同伴最大数量
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :gold # 金钱数量
- attr_reader :steps # 步数
- attr_accessor :last_item_id # 光标位置记忆:物品
- attr_accessor :last_actor_index # 光标位置记忆:角色
- attr_accessor :last_target_index # 光标位置记忆:目标
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- def initialize
- super
- @gold = 0
- @steps = 0
- @last_item_id = 0
- @last_actor_index = 0
- @last_target_index = 0
- @actors = [] # 队员(角色ID)
- @items = {} # 物品哈希列表(物品ID)
- @weapons = {} # 物品哈希列表(武器ID)
- @armors = {} # 物品哈希列表(防具ID)
- end
- #--------------------------------------------------------------------------
- # ● 获取队员
- #--------------------------------------------------------------------------
- def members
- result = []
- for i in @actors
- result.push($game_actors[i])
- end
- return result
- end
- #--------------------------------------------------------------------------
- # ● 获取物品数组(包括武器和防具)
- #--------------------------------------------------------------------------
- def items
- result = []
- for i in @items.keys.sort
- result.push($data_items[i]) if @items[i] > 0
- end
- for i in @weapons.keys.sort
- result.push($data_weapons[i]) if @weapons[i] > 0
- end
- for i in @armors.keys.sort
- result.push($data_armors[i]) if @armors[i] > 0
- end
- return result
- end
- #--------------------------------------------------------------------------
- # ● 初始队员设置
- #--------------------------------------------------------------------------
- def setup_starting_members
- @actors = []
- for i in $data_system.party_members
- @actors.push(i)
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取队伍名称
- # 只有一人时,返回主角名称。
- # 多人时则返回 "XX的队伍"(按照在Vocab里的设定)。
- #--------------------------------------------------------------------------
- def name
- if @actors.size == 0
- return ''
- elsif @actors.size == 1
- return members[0].name
- else
- return sprintf(Vocab::PartyName, members[0].name)
- end
- end
- #--------------------------------------------------------------------------
- # ● 战斗测试队伍设置
- #--------------------------------------------------------------------------
- def setup_battle_test_members
- @actors = []
- for battler in $data_system.test_battlers
- actor = $game_actors[battler.actor_id]
- actor.change_level(battler.level, false)
- actor.change_equip_by_id(0, battler.weapon_id, true)
- actor.change_equip_by_id(1, battler.armor1_id, true)
- actor.change_equip_by_id(2, battler.armor2_id, true)
- actor.change_equip_by_id(3, battler.armor3_id, true)
- actor.change_equip_by_id(4, battler.armor4_id, true)
- actor.recover_all
- @actors.push(actor.id)
- end
- @items = {}
- for i in 1...$data_items.size
- if $data_items[i].battle_ok?
- @items[i] = 99 unless $data_items[i].name.empty?
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取最高等级
- #--------------------------------------------------------------------------
- def max_level
- level = 0
- for i in @actors
- actor = $game_actors[i]
- level = actor.level if level < actor.level
- end
- return level
- end
- #--------------------------------------------------------------------------
- # ● 队员加入
- # actor_id : 角色ID
- #--------------------------------------------------------------------------
- def add_actor(actor_id)
- if @actors.size < MAX_MEMBERS and not @actors.include?(actor_id)
- @actors.push(actor_id)
- $game_player.refresh
- end
- end
- #--------------------------------------------------------------------------
- # ● 队员离开
- # actor_id : 角色ID
- #--------------------------------------------------------------------------
- def remove_actor(actor_id)
- @actors.delete(actor_id)
- $game_player.refresh
- end
- #--------------------------------------------------------------------------
- # ● 获得/损失金钱
- # n : 金钱数量
- #--------------------------------------------------------------------------
- def gain_gold(n)
- @gold = [[@gold + n, 0].max, 9999999].min
- end
- #--------------------------------------------------------------------------
- # ● 损失金钱
- # n : 金钱数量
- #--------------------------------------------------------------------------
- def lose_gold(n)
- gain_gold(-n)
- end
- #--------------------------------------------------------------------------
- # ● 增加步数
- #--------------------------------------------------------------------------
- def increase_steps
- @steps += 1
- end
- #--------------------------------------------------------------------------
- # ● 获取物品持有数量
- # item : 物品
- #--------------------------------------------------------------------------
- def item_number(item)
- case item
- when RPG::Item
- number = @items[item.id]
- when RPG::Weapon
- number = @weapons[item.id]
- when RPG::Armor
- number = @armors[item.id]
- end
- return number == nil ? 0 : number
- end
- #--------------------------------------------------------------------------
- # ● 判断是否拥有某物品
- # item : 物品
- # include_equip : 包括已装备的物品
- #--------------------------------------------------------------------------
- def has_item?(item, include_equip = false)
- if item_number(item) > 0
- return true
- end
- if include_equip
- for actor in members
- return true if actor.equips.include?(item)
- end
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 获得/损失物品
- # item : 物品
- # n : 数量
- # include_equip : 包括已装备的物品
- #--------------------------------------------------------------------------
- def gain_item(item, n, include_equip = false)
- number = item_number(item)
- case item
- when RPG::Item
- @items[item.id] = [[number + n, 0].max, 99].min
- when RPG::Weapon
- @weapons[item.id] = [[number + n, 0].max, 99].min
- when RPG::Armor
- @armors[item.id] = [[number + n, 0].max, 99].min
- end
- n += number
- if include_equip and n < 0
- for actor in members
- while n < 0 and actor.equips.include?(item)
- actor.discard_equip(item)
- n += 1
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 损失物品
- # item : 物品
- # n : 数量
- # include_equip : 包括已装备的物品
- #--------------------------------------------------------------------------
- def lose_item(item, n, include_equip = false)
- gain_item(item, -n, include_equip)
- end
- #--------------------------------------------------------------------------
- # ● 消耗物品
- # item : 物品
- # 若所使用的物品为消耗品,则减少物品数量减一
- #--------------------------------------------------------------------------
- def consume_item(item)
- if item.is_a?(RPG::Item) and item.consumable
- lose_item(item, 1)
- end
- end
- #--------------------------------------------------------------------------
- # ● 判断物品可以使用
- # item_id : 物品 ID
- #--------------------------------------------------------------------------
- def item_can_use?(item)
- return false unless item.is_a?(RPG::Item)
- return false if item_number(item) == 0
- if $game_temp.in_battle
- return item.battle_ok?
- else
- return item.menu_ok?
- end
- end
- #--------------------------------------------------------------------------
- # ● 可以输入命令的判定
- # 自动战斗则视为可以输入命令
- #--------------------------------------------------------------------------
- def inputable?
- for actor in members
- return true if actor.inputable?
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 判断是否全灭
- #--------------------------------------------------------------------------
- def all_dead?
- if @actors.size == 0 and not $game_temp.in_battle
- return false
- end
- return existing_members.empty?
- end
- #--------------------------------------------------------------------------
- # ● 主角在地图上走一步的效果
- #--------------------------------------------------------------------------
- def on_player_walk
- for actor in members
- if actor.slip_damage?
- actor.hp -= 1 if actor.hp > 1 # 持续伤害
- $game_map.screen.start_flash(Color.new(255,0,0,64), 4)
- end
- if actor.auto_hp_recover and actor.hp > 0
- actor.hp += 1 # 体力自动回复
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 执行自动回复(回合结束时调用)
- #--------------------------------------------------------------------------
- def do_auto_recovery
- for actor in members
- actor.do_auto_recovery
- end
- end
- #--------------------------------------------------------------------------
- # ● 移除战斗状态(战斗结束时调用)
- #--------------------------------------------------------------------------
- def remove_states_battle
- for actor in members
- actor.remove_states_battle
- end
- end
- end
复制代码 |
|