Created
June 19, 2013 15:52
-
-
Save kl/5815417 to your computer and use it in GitHub Desktop.
Version p1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module BattlePositionsKal | |
| SKILL_ID = 200 | |
| ENEMY_START = 0 | |
| PARTY_START = 10 | |
| ENEMY_INC = 2 | |
| DEFAULT_SKILL_RANGE = 1 | |
| FONT_COLOR = "1ACDE8" | |
| end | |
| class Game_BattlerBase | |
| attr_accessor :battle_pos_listeners_bp_kal | |
| attr_reader :battle_pos_bp_kal | |
| def battle_pos_bp_kal=(pos) | |
| @battle_pos_bp_kal = pos | |
| @battle_pos_listeners_bp_kal.each { |l| l.battle_pos_changed } | |
| end | |
| alias_method :initialize_bp_kal, :initialize | |
| def initialize | |
| initialize_bp_kal | |
| @battle_pos_listeners_bp_kal = [] | |
| post_initialize_bp_kal | |
| end | |
| def post_initialize_bp_kal | |
| # Subclass initialize hook | |
| end | |
| end | |
| class Game_Battler | |
| alias_method :item_test_bp_kal, :item_test | |
| def item_test(user, item) | |
| item_test_bp_kal(user, item) || item.skill == BattlePositionsKal::SKILL_ID | |
| end | |
| alias_method :item_user_effect_bp_kal, :item_user_effect | |
| def item_user_effect(user, item) | |
| item_user_effect_bp_kal(user, item) | |
| if item.id == BattlePositionsKal::SKILL_ID | |
| self.battle_pos_bp_kal += BattlePositionsKal::ENEMY_INC | |
| end | |
| end | |
| end | |
| class Game_Enemy | |
| def post_initialize_bp_kal | |
| @battle_pos_bp_kal = BattlePositionsKal::ENEMY_START | |
| end | |
| alias_method :conditions_met_bp_kal?, :conditions_met? | |
| def conditions_met?(action) | |
| conditions_met_bp_kal?(action) && in_range_bp_kal?(action) | |
| end | |
| # TODO: does not take in to account negative values | |
| def in_range_bp_kal?(action) | |
| party_pos = $game_party.get_party_positions_bp_kal | |
| closest_actor_pos = party_pos.min | |
| battlefield_range = @battle_pos_bp_kal + | |
| get_skill_for_action_bp_kal(action).skill_range_bp_kal | |
| battlefield_range >= closest_actor_pos | |
| end | |
| def get_skill_for_action_bp_kal(action) | |
| $data_skills[action.skill_id] | |
| end | |
| alias_method :make_actions_bp_kal, :make_actions | |
| def make_actions | |
| if make_actions_bp_kal == nil | |
| set_battle_pos_move_action_bp_kal | |
| end | |
| end | |
| def set_battle_pos_move_action_bp_kal | |
| @actions.each do |game_action| | |
| game_action.set_enemy_action(get_battle_pos_move_action_bp_kal) | |
| end | |
| end | |
| def get_battle_pos_move_action_bp_kal | |
| action = RPG::Enemy::Action.new | |
| action.skill_id = BattlePositionsKal::SKILL_ID | |
| action | |
| end | |
| end | |
| class Game_Actor | |
| def post_initialize_bp_kal | |
| @battle_pos_bp_kal = BattlePositionsKal::PARTY_START | |
| end | |
| end | |
| class Game_Party | |
| def get_party_positions_bp_kal | |
| @actors.map { |actor_id| $game_actors[actor_id].battle_pos_bp_kal } | |
| end | |
| end | |
| class RPG::Skill | |
| attr_accessor :skill_range_bp_kal | |
| def skill_range_bp_kal | |
| range = note[/<skill_range\s+(\d+)>/, 1] | |
| @skill_range_bp_kal = range ? range.to_i : | |
| BattlePositionsKal::DEFAULT_SKILL_RANGE | |
| end | |
| end | |
| class Sprite_Battler | |
| alias_method :battler_set_bp_kal, :battler= | |
| def battler=(battler) | |
| battler_set_bp_kal(battler) | |
| check_initialize_battle_pos_sprite | |
| @battle_pos_sprite_bp_kal.battler = battler if @battle_pos_sprite_bp_kal | |
| end | |
| alias_method :initialize_bp_kal, :initialize | |
| def initialize(viewport, battler = nil) | |
| initialize_bp_kal(viewport, battler) | |
| check_initialize_battle_pos_sprite | |
| end | |
| def check_initialize_battle_pos_sprite | |
| if !@battle_pos_sprite_bp_kal && @battler && @battler.is_a?(Game_Enemy) | |
| @battle_pos_sprite_bp_kal = Sprite_BattlePosNumber.new(self) | |
| end | |
| end | |
| alias_method :update_bp_kal, :update | |
| def update | |
| @battle_pos_sprite_bp_kal.update if @battle_pos_sprite_bp_kal | |
| update_bp_kal | |
| end | |
| alias_method :update_position_bp_kal, :update_position | |
| def update_position | |
| if @battle_pos_sprite_bp_kal && screen_pos_changed_bp_kal? | |
| @battle_pos_sprite_bp_kal.screen_pos_changed | |
| end | |
| update_position_bp_kal | |
| end | |
| alias_method :dispose_bp_kal, :dispose | |
| def dispose | |
| @battle_pos_sprite_bp_kal.dispose if @battle_pos_sprite_bp_kal | |
| dispose_bp_kal | |
| end | |
| def screen_pos_changed_bp_kal? | |
| x != @battler.screen_x || | |
| y != @battler.screen_y || | |
| z != @battler.screen_z | |
| end | |
| end | |
| class Sprite_BattlePosNumber < Sprite_Base | |
| attr_accessor :battler | |
| def initialize(sprite_battler) | |
| super(nil) | |
| self.bitmap = Bitmap.new(40, 40) | |
| hex_color = BattlePositionsKal::FONT_COLOR | |
| bitmap.font.color = Color.new(*hex_to_rgb(hex_color)) | |
| @sprite_battler = sprite_battler | |
| @battler = @sprite_battler.battler | |
| @battler.battle_pos_listeners_bp_kal << self | |
| end | |
| def update | |
| super | |
| if @should_draw | |
| draw_battle_pos_text | |
| @should_draw = false | |
| end | |
| self.opacity = @sprite_battler.opacity # for enemy death | |
| end | |
| def dispose | |
| bitmap.dispose if bitmap | |
| super | |
| end | |
| def screen_pos_changed | |
| @should_draw = true | |
| end | |
| def battle_pos_changed | |
| @should_draw = true | |
| end | |
| def draw_battle_pos_text | |
| print "draw\n" | |
| set_coordinates | |
| bitmap.clear | |
| bitmap.draw_text(0, 0, 40, 40, @battler.battle_pos_bp_kal) | |
| end | |
| def set_coordinates | |
| self.x = @sprite_battler.x - @sprite_battler.width / 2 | |
| self.y = @sprite_battler.y - @sprite_battler.height | |
| self.z = @sprite_battler.z | |
| end | |
| def hex_to_rgb(string) | |
| string.scan(/..?/).map do |two_hex| | |
| two_hex.to_i(16) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment