Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # LM² - Email
- # v1.0
- # configurações gerais
- module Vocab
- EmailList = "Lista de Emails"
- WriteEmail = "Escrever Email"
- Send = "Enviar"
- Body = "Corpo do Email"
- MailName = "Nome do Email"
- ReceiverName = "Nome do Jogador"
- Claim = "Resgatar"
- Email = "Emails"
- Sender = "De:"
- SendDate = "Data:"
- ExpireDate = "Expira:"
- AddItem = "Add Item"
- end
- module Configs
- UNREAD_MAIL = 235
- READ_MAIL = 236
- WRITE_MAIL = 286
- COLLECTED_MAIL = 539
- EMAIL_ICON = 234
- EMAIL_KEY = :LETTER_E
- EMAILDATE = "%H:%M %d/%m/%y"
- end
- # struct do email
- Email = Struct.new(:sender_name, :name, :body, :gold,
- :items, :state, :send_date, :expire_date)
- ItemMail = Struct.new(:type, :id, :amount)
- #recebimento de pacotes do servidor
- module Handle_Data
- def handle_player_email(buffer)
- sender_name = buffer.read_string
- name = buffer.read_string
- body = buffer.read_string
- state = buffer.read_byte
- gold = buffer.read_int
- size = buffer.read_byte
- items = []
- size.times {
- items << ItemMail.new(
- buffer.read_byte,
- buffer.read_short,
- buffer.read_short
- )
- }
- send_date = Time.now - buffer.read_long
- expire_date = Time.now + buffer.read_long
- email = Email.new(sender_name, name, body, gold,
- items, state, send_date, expire_date)
- $game_player.emails << email
- $windows[:email_list].refresh if $windows[:email_list] && $windows[:email_list].visible
- #$windows[:email_list]&.visible ruby 2.3 >
- end
- def handle_email_delete(buffer)
- mail_id = buffer.read_short
- $game_player.emails.delete_at(mail_id)
- $windows[:email_list].refresh if $windows[:email_list] && $windows[:email_list].visible
- end
- end
- # envio de pacotes para o servidor
- module Send_Data
- def send_player_email(mail_id, delete)
- return unless @socket
- buffer = Buffer_Writer.new
- buffer.write_byte(Enums::Packet::EMAIL)
- buffer.write_short(mail_id)
- buffer.write_boolean(delete)
- @socket.send(buffer.to_s)
- end
- def send_player_write_email(receiver, name, body, gold, items, admin = false)
- return unless @socket
- buffer = Buffer_Writer.new
- buffer.write_byte(Enums::Packet::EMAIL_WRITE)
- buffer.write_boolean(admin)
- buffer.write_string(receiver)
- buffer.write_string(name)
- buffer.write_string(body)
- buffer.write_int(gold)
- buffer.write_byte(items.size)
- items.each{|item|
- buffer.write_byte(item.type)
- buffer.write_short(item.id)
- buffer.write_short(item.amount)
- }
- @socket.send(buffer.to_s)
- end
- end
- # janela de lista de emails
- class Window_EmailList < Window_Selectable
- def initialize
- super(173, 170, 236, 212)
- self.visible = false
- self.closable = true
- self.title = Vocab::EmailList
- Icon.new(self, width - 46, height - 36, Configs::WRITE_MAIL, Vocab::WriteEmail) { write_email}
- end
- def line_height
- 22
- end
- def make_list
- @data = $game_player.emails
- end
- def draw_item(index)
- rect = item_rect_for_text(index)
- icon_index = @data[index].state == 1 ? Configs::READ_MAIL : Configs::UNREAD_MAIL
- rect2 = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- bitmap = Cache.system('Iconset')
- contents.blt(3, rect.y, bitmap, rect2)
- rect.x += 27
- draw_text(rect, @data[index].name)
- end
- def refresh
- super
- end
- def update
- super
- if Mouse.click?(:L) && index >= 0
- $windows[:email_info].show(@data[index], index)
- $windows[:email_write].hide
- Sound.play_ok
- end
- end
- def write_email
- $windows[:email_write].show
- $windows[:email_info].hide
- $windows[:equip].show
- end
- end
- # janela de leitura de email
- class Window_EmailInfo < Window_Base
- def initialize
- super(adjust_x, 151, 246, 300)
- self.visible = false
- self.closable = true
- self.title = "Teste"
- @claim_button = Button.new(self, 12 , height - 34, Vocab::Claim, 80) { claim }
- @delete_button = Button.new(self, width - 92 , height - 34, Vocab::Delete, 80) { delete }
- create_desc
- @email = nil
- end
- def line_height
- 20
- end
- def adjust_x
- $windows[:email_list].x + $windows[:email_list].width + 2
- end
- def claim
- $network.send_player_email(@id, false)
- $game_player.emails[@id].state = 1
- $windows[:email_list].refresh
- refresh
- end
- def delete
- $network.send_player_email(@id, true)
- $game_player.emails.delete_at(@id)
- $windows[:email_list].refresh
- hide
- end
- def show(email, id)
- @email = email
- @id = id
- self.title = @email.name
- super()
- end
- def refresh
- contents.clear
- return unless @email
- @claim_button.enable = @email.state == 0
- @delete_button.enable = @email.state == 1
- contents.font.size = 16
- change_color(system_color)
- draw_text(0, -2, contents_width, line_height, "#{Vocab::Name}:", 0)
- draw_text(0, 20, contents_width, line_height, Vocab::Sender, 0)
- draw_text(0, 42, contents_width, line_height, Vocab::SendDate, 0)
- draw_text(0, 64, contents_width, line_height, Vocab::ExpireDate, 0)
- change_color(normal_color)
- x = text_size("#{Vocab::Name}:").width + 8
- draw_text(x, -2, contents_width, line_height, @email.name, 0)
- x = text_size(Vocab::Sender).width + 8
- draw_text(x, 20, contents_width, line_height, @email.sender_name, 0)
- x = text_size(Vocab::SendDate).width + 8
- time = @email.send_date.strftime(Configs::EMAILDATE)
- draw_text(x, 42, contents_width, line_height, time, 0)
- x = text_size(Vocab::ExpireDate).width + 8
- time = @email.expire_date.strftime(Configs::EMAILDATE)
- draw_text(x, 64, contents_width, line_height, time, 0)
- word_wrap(@email.body).each_with_index do |text, i|
- draw_text(0, line_height * i + 86, contents_width, line_height, text, 1)
- end
- draw_text(0, 230, contents_width, line_height, "#{Vocab.currency_unit}: #{format_number(@email.gold)}", 1)
- if @email.items.size > 0
- bitmap = Cache.system("EmailItems")
- contents.blt(29, 180, bitmap, bitmap.rect)
- contents.font.size = 14
- @email.items.each_with_index{|item, index|
- x = 32 + (index * 34)
- nitem = $game_party.item_object(item[0], item[1])
- draw_icon(nitem.icon_index, x, 183)
- draw_text(x, 210, 30, line_height, "x#{item[2]}", 1)
- draw_icon(Configs::COLLECTED_MAIL, x, 183) if @email.state == 1
- }
- end
- end
- def update
- super
- hiding = true
- if @email
- @email.items.each_with_index { |item, index|
- if in_area?(40 + (index * 34), 192, 30, 30)
- show_desc($game_party.item_object(item[0], item[1]))
- hiding = false
- break
- end
- }
- end
- hide_desc if hiding
- end
- end
- # janela de escrever email jogadores
- class Window_EmailWrite < Window_Base
- def initialize
- super(adjust_x, 151, 246, 178)
- self.visible = false
- self.closable = true
- self.title = Vocab::WriteEmail
- @send = Button.new(self, 20, 144, Vocab::Send, 80) { send }
- Button.new(self, 146, 144, Vocab::Cancel, 80) { hide }
- @mail_name = Text_Box.new(self, 12, 18, 110, 20, false, Vocab::MailName) { enable_send_button(0)}
- @receiver_name = Text_Box.new(self, 124, 18, 110, Configs::MAX_CHARACTERS, false, Vocab::ReceiverName) { enable_send_button(1)}
- @mail_body = Text_Box.new(self, 12, 42, 222, 100, false, Vocab::Body) { enable_send_button(2)}
- @gold_box = Number_Box.new(self, 116, 66, 80, 6) { enable_send_button(3) }
- @gold_box.value = 0
- @items = []
- @spam = Time.now
- @cursor = 0
- create_desc
- end
- def line_height
- 20
- end
- def adjust_x
- $windows[:email_list].x + $windows[:email_list].width + 2
- end
- def send
- receiver = @receiver_name.text
- name = @mail_name.text
- body = @mail_body.text
- gold = @gold_box.value
- items = []
- @items.each{|item|
- type = $game_party.kind_item(item[0])
- id = item[0].id
- amount = item[1]
- items << ItemMail.new(type, id, amount)
- }
- $network.send_player_write_email(receiver, name, body, gold, items)
- hide
- end
- def hide
- @receiver_name.text = ""
- @mail_name.text = ""
- @mail_body.text = ""
- @gold_box.value = 0
- @items = []
- super
- end
- def show
- super
- @mail_name.active = true
- end
- def refresh
- contents.clear
- bitmap = Cache.system("EmailItems")
- contents.blt(28, 78, bitmap, bitmap.rect)
- contents.font.size = 16
- draw_text(40, 54, contents_width, line_height, "#{Vocab.currency_unit}:")
- contents.font.size = 14
- @items.each_with_index{|item, index|
- x = 32 + (index * 34)
- draw_icon(item[0].icon_index, x, 81)
- draw_text(x, 108, 30, line_height, "x#{item[1]}", 1)
- }
- end
- def enable_send_button(cursor)
- @send.enable = (@receiver_name.text.strip.size >= Configs::MIN_CHARACTERS &&
- @mail_name.text.strip.size >= Configs::MIN_CHARACTERS &&
- @mail_body.text.strip.size >= Configs::MIN_CHARACTERS )
- @cursor = cursor
- end
- def update
- super
- update_drop
- double_click
- update_cursor
- update_desc
- end
- def double_click
- return unless @items.size > 0
- return unless Mouse.dbl_clk?(:L)
- return unless Time.now > @spam
- @items.each_index{|index|
- next unless in_area?(40 + (index * 34), 123, 30, 30)
- @items.delete_at(index)
- @spam = Time.now + 0.2
- refresh
- return
- }
- end
- def update_drop
- return if Mouse.press?(:L)
- return unless $cursor.object
- return unless $cursor.type == Enums::Mouse::ITEM
- return unless in_area?
- $windows[:amount].show(Enums::Amount::EMAIL_ITEM, $cursor.object)
- end
- def add_item(item, amount)
- return if @items.size >= 5
- existing = @items.find_index{ |obj| obj[0].id == item.id}
- if existing
- amount = [@items[existing][1] + amount, $game_party.item_number(item)].min
- @items[existing][1] = amount
- else
- amount = [amount, $game_party.item_number(item)].min
- @items << [item, amount]
- end
- refresh
- end
- def update_cursor
- return unless Input.trigger?(:TAB)
- @cursor = @cursor >= 4 ? 0 : @cursor + 1
- @mail_name.active = @cursor == 0
- @receiver_name.active = @cursor == 1
- @mail_body.active = @cursor == 2
- @gold_box.active = @cursor == 3
- end
- def update_desc
- hiding = true
- if @items.size > 0
- @items.each_with_index { |item, index|
- if in_area?(40 + (index * 34), 90, 30, 30)
- show_desc(item[0])
- hiding = false
- break
- end
- }
- end
- hide_desc if hiding
- end
- end
- # método para a janela de quantidade
- class Window_Amount < Window_Base
- def email_item
- return unless $windows[:email_write].visible
- amount = [@amount_box.value, Configs::MAX_ITEMS].min
- return if $game_party.item_number(@item) < amount
- if @item.soulbound?
- $error_msg = Vocab::SoulboundItem
- return
- end
- $windows[:email_write].add_item(@item, amount)
- end
- end
- #classe do $game_player
- class Game_Player < Game_Character
- attr_accessor :emails
- end
- #janela de escrever emails de administradores
- class Window_AdminEmailWrite < Window_Base
- def initialize
- super(adjust_x, 151, 246, 226)
- self.visible = false
- self.closable = true
- create_desc
- self.title = Vocab::WriteEmail
- @send = Button.new(self, 20, 192, Vocab::Send, 80) { send }
- Button.new(self, 146, 192, Vocab::Cancel, 80) { hide }
- @mail_name = Text_Box.new(self, 12, 18, 110, 20, false, Vocab::MailName) { enable_send_button(0)}
- @receiver_name = Text_Box.new(self, 124, 18, 110, Configs::MAX_CHARACTERS, false, Vocab::ReceiverName) { enable_send_button(1)}
- @mail_body = Text_Box.new(self, 12, 42, 222, 100, false, Vocab::Body) { enable_send_button(2)}
- @gold_box = Number_Box.new(self, 116, 66, 80, 6) { enable_send_button(3) }
- @prev_button = Image_Button.new(self, 134, 90, 'Left') { prev_item_type }
- @next_button = Image_Button.new(self, 214, 90, 'Right') { next_item_type }
- @amount_box = Number_Box.new(self, 74, 113, 56, 5) { enable_send_button(5)}
- @item_box = Number_Box.new(self, 14, 113, 56, 5) { enable_send_button(4)}
- @item_button = Button.new(self, 134, 112, Vocab::AddItem, 98) { add_item }
- @gold_box.value = 0
- @items = []
- @spam = Time.now
- @cursor = 0
- @item_type = 1
- end
- def adjust_x
- $windows[:panel].x + $windows[:panel].width + 2
- end
- def line_height
- 20
- end
- def send
- receiver = @receiver_name.text
- name = @mail_name.text
- body = @mail_body.text
- gold = @gold_box.value
- items = []
- @items.each{|item|
- type = $game_party.kind_item(item[0])
- id = item[0].id
- amount = item[1]
- items << ItemMail.new(type, id, amount)
- }
- $network.send_player_write_email(receiver, name, body, gold, items, true)
- hide
- end
- def hide
- @receiver_name.text = ""
- @mail_name.text = ""
- @mail_body.text = ""
- @gold_box.value = 0
- @items = []
- @cursor = 0
- @item_type = 1
- super
- end
- def show
- super
- @mail_name.active = true
- enable_send_button(0)
- end
- def refresh
- contents.clear
- bitmap = Cache.system("EmailItems")
- contents.blt(28, 126, bitmap, bitmap.rect)
- contents.font.size = 16
- draw_text(40, 54, contents_width, line_height, "#{Vocab.currency_unit}:")
- case @item_type
- when 1
- item_type = Vocab::Item
- when 2
- item_type = Vocab.weapon
- when 3
- item_type = Vocab.armor
- end
- draw_text(122, 76, 98, line_height, item_type, 1)
- contents.font.size = 14
- draw_text(2, 78, 136, line_height, Vocab::ID)
- draw_text(62, 78, 136, line_height, "#{Vocab::Amount}:")
- @items.each_with_index{|item, index|
- x = 28 + (index * 34)
- draw_icon(item[0].icon_index, x+3, 129)
- draw_text(x, 156, 30, line_height, "x#{item[1]}", 1)
- }
- end
- def enable_send_button(cursor)
- @send.enable = (@mail_name.text.strip.size >= Configs::MIN_CHARACTERS &&
- @mail_body.text.strip.size >= Configs::MIN_CHARACTERS )
- @item_button.enable = (@amount_box.value > 0 && @item_box.value > 0)
- @cursor = cursor
- end
- def update
- super
- update_desc
- double_click
- update_cursor
- end
- def double_click
- return unless @items.size > 0
- return unless Mouse.dbl_clk?(:L)
- return unless Time.now > @spam
- @items.each_index{|index|
- next unless in_area?(40 + (index * 34), 138, 30, 30)
- @items.delete_at(index)
- @spam = Time.now + 0.2
- refresh
- return
- }
- end
- def add_item
- return if @items.size >= 5 || @item_box.value == 0 || @amount_box.value == 0
- item = $game_party.item_object(@item_type, @item_box.value)
- return unless item
- amount = @amount_box.value
- existing = @items.find_index{ |obj| obj[0].id == item.id}
- if existing
- @items[existing][1] += amount
- else
- @items << [item, amount]
- end
- refresh
- @amount_box.value = 0
- @item_box.value = 0
- end
- def update_cursor
- return unless Input.trigger?(:TAB)
- @cursor = @cursor >= 4 ? 0 : @cursor + 1
- @mail_name.active = @cursor == 0
- @receiver_name.active = @cursor == 1
- @mail_body.active = @cursor == 2
- @gold_box.active = @cursor == 3
- @item_box.active = @cursor == 4
- @amount_box.active = @cursor == 5
- end
- def prev_item_type
- @item_type = @item_type > 1 ? @item_type - 1 : 3
- refresh
- end
- def next_item_type
- @item_type = @item_type < 3 ? @item_type + 1 : 1
- refresh
- end
- def update_desc
- hiding = true
- if @items.size > 0
- @items.each_with_index { |item, index|
- if in_area?(40 + (index * 34), 138, 29, 29)
- show_desc(item[0])
- hiding = false
- break
- end
- }
- end
- hide_desc if hiding
- end
- end
Add Comment
Please, Sign In to add comment