mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-09 14:14:59 +00:00
Quest symbols (WIP)
This commit is contained in:
67
Data/Scripts/052_AddOns/quest_icons.rb
Normal file
67
Data/Scripts/052_AddOns/quest_icons.rb
Normal file
@@ -0,0 +1,67 @@
|
||||
class Sprite_Character
|
||||
QUEST_NPC_TRIGGER = "questNPC"
|
||||
|
||||
QUEST_ICON_FOLDER = "Graphics/Pictures/Quests/"
|
||||
QUEST_ICON_NAME = "Graphics/Pictures/Quests/questIcon"
|
||||
|
||||
attr_accessor :questIcon
|
||||
|
||||
alias questIcon_init initialize
|
||||
def initialize(viewport, character = nil)
|
||||
questIcon_init(viewport,character)
|
||||
@quest_switch = detectQuestSwitch(character)
|
||||
if @quest_switch
|
||||
echoln "balablbi #{@quest_switch}"
|
||||
addQuestMarkerToSprite
|
||||
end
|
||||
end
|
||||
|
||||
alias questIcon_update update
|
||||
def update
|
||||
questIcon_update
|
||||
positionQuestIndicator if @questIcon
|
||||
removeQuestIcon if @questIcon && isQuestAlreadyAccepted?(@quest_switch)
|
||||
end
|
||||
|
||||
# Event name must contain questNPC(x) for a quest icon to be displayed
|
||||
# Where x is the quest ID
|
||||
# if the quest has not already been accepted, the quest marker will be shown
|
||||
def detectQuestSwitch(event)
|
||||
return nil if event.is_a?(Game_Player)
|
||||
name = event.name.clone
|
||||
match = name.match(/#{Regexp.escape(QUEST_NPC_TRIGGER)}\(([^)]+)\)/) # Capture anything inside parentheses
|
||||
return nil unless match
|
||||
quest_id = match[1]
|
||||
quest_id = quest_id.gsub(/^['"]|['"]$/, '') # Remove quotes if they exist
|
||||
return nil if isQuestAlreadyAccepted?(quest_id)
|
||||
return quest_id
|
||||
end
|
||||
|
||||
|
||||
def addQuestMarkerToSprite()
|
||||
removeQuestIcon if @questIcon
|
||||
@questIcon = Sprite.new(@viewport)
|
||||
@questIcon.bmp(QUEST_ICON_NAME)
|
||||
positionQuestIndicator
|
||||
end
|
||||
|
||||
def positionQuestIndicator()
|
||||
y_offset =-70
|
||||
|
||||
@questIcon.ox = @questIcon.bitmap.width / 2.0
|
||||
@questIcon.oy = @questIcon.bitmap.height / 2.0
|
||||
|
||||
x_position = @character.screen_x
|
||||
y_position = @character.screen_y + y_offset
|
||||
@questIcon.x = x_position
|
||||
@questIcon.y = y_position
|
||||
@questIcon.z = 999
|
||||
end
|
||||
|
||||
def removeQuestIcon()
|
||||
echoln "REMOVAL for #{self}"
|
||||
@questIcon.dispose
|
||||
@questIcon = nil
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user