Advertisement
Kid02

chigre toma xD

Nov 9th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.63 KB | None | 0 0
  1. =begin
  2. ######################### How To Use ###################################
  3. Start of a new game is not required, should integrate into old saves files
  4.  
  5.  
  6.  
  7.  
  8. =end
  9.  
  10.  
  11. #This class holds the information for an individual quest
  12. class Quest
  13.  
  14. attr_reader :id
  15. attr_reader :stage
  16.  
  17. def stage=(value)
  18. if value>$quest_data.getMaxStagesForQuest(@id)
  19. value = $quest_data.getMaxStagesForQuest(@id)
  20. end
  21. @stage = value
  22. end
  23.  
  24. def initialize(id)
  25. @id = id
  26. @stage = 1
  27. end
  28.  
  29.  
  30. end
  31.  
  32. #This class holds all the trainers quests
  33. class Player_Quests
  34.  
  35. attr_accessor :active_quests
  36. attr_accessor :completed_quests
  37. attr_accessor :failed_quests
  38. attr_accessor :selected_quest_id
  39.  
  40. def initialize
  41. @active_quests =[]
  42. @completed_quests = []
  43. @failed_quests = []
  44. @selected_quest_id = 0
  45. end
  46.  
  47.  
  48. #questID can either be the internal ID number, or the quest name
  49. def activateQuest(questID)
  50. if questID.is_a?(String)
  51. questID = $quest_data.getIDFromName(questID)
  52. end
  53. for i in 0...@active_quests.length
  54. if @active_quests[i].id==questID
  55. Kernel.pbMessage("Ya has tomado este encargo.")
  56. return
  57. end
  58. end
  59. for i in 0...@completed_quests.length
  60. if @completed_quests[i].id==questID
  61. Kernel.pbMessage("Ya has tomado este encargo.")
  62. return
  63. end
  64. end
  65. for i in 0...@failed_quests.length
  66. if @failed_quests[i].id==questID
  67. Kernel.pbMessage("Ya has tomado este encargo.")
  68. return
  69. end
  70. end
  71. @active_quests.push(Quest.new(questID))
  72. end
  73.  
  74. def failQuest(questID)
  75. if questID.is_a?(String)
  76. questID = $quest_data.getIDFromName(questID)
  77. end
  78. found = false
  79. for i in 0...@completed_quests.length
  80. if @completed_quests[i].id==questID
  81. Kernel.pbMessage("Ya has tomado este encargo.")
  82. return
  83. end
  84. end
  85. for i in 0...@failed_quests.length
  86. if @failed_quests[i].id==questID
  87. Kernel.pbMessage("Ya has tomado este encargo.")
  88. return
  89. end
  90. end
  91. for i in 0...@active_quests.length
  92. if @active_quests[i].id==questID
  93. @failed_quests.push(@active_quests[i])
  94. @active_quests.delete_at(i)
  95. found=true
  96. break
  97. end
  98. end
  99. if !found
  100. @failed_quests.push(Quest.new(questID))
  101. end
  102. end
  103.  
  104. def completeQuest(questID)
  105. if questID.is_a?(String)
  106. questID = $quest_data.getIDFromName(questID)
  107. end
  108. found = false
  109. for i in 0...@completed_quests.length
  110. if @completed_quests[i].id==questID
  111. Kernel.pbMessage("Has completado este encargo.")
  112. return
  113. end
  114. end
  115. for i in 0...@failed_quests.length
  116. if @failed_quests[i].id==questID
  117. Kernel.pbMessage("Has completado la misión.")
  118. return
  119. end
  120. end
  121. for i in 0...@active_quests.length
  122. if @active_quests[i].id==questID
  123. @completed_quests.push(@active_quests[i])
  124. @active_quests.delete_at(i)
  125. found = true
  126. break
  127. end
  128. end
  129. if !found
  130. @completed_quests.push(Quest.new(questID))
  131. end
  132. rewardString = $quest_data.getQuestReward(questID)
  133. eval(rewardString)
  134. end
  135.  
  136. def advanceQuestToStage(questID,stageNum)
  137. if questID.is_a?(String)
  138. questID = $quest_data.getIDFromName(questID)
  139. end
  140. found = false
  141. for i in 0...@active_quests.length
  142. if @active_quests[i].id==questID
  143. @active_quests[i].stage=stageNum
  144. found = true
  145. end
  146. return if found
  147. end
  148. if !found
  149. quest = Quest.new(questID)
  150. quest.stage = stageNum
  151. @active_quests.push(quest)
  152. end
  153. end
  154.  
  155. end
  156.  
  157. class PokemonGlobalMetadata
  158.  
  159. def quests
  160. @quests = Player_Quests.new if !@quests
  161. return @quests
  162. end
  163.  
  164. alias quest_init initialize
  165. def initialize
  166. quest_init
  167. @quests = Player_Quests.new
  168. end
  169. end
  170.  
  171. def activateQuest(id)
  172. return if !$PokemonGlobal
  173. $PokemonGlobal.quests.activateQuest(id)
  174. end
  175.  
  176. def completeQuest(id)
  177. return if !$PokemonGlobal
  178. $PokemonGlobal.quests.completeQuest(id)
  179. end
  180.  
  181. def failQuest(id)
  182. return if !$PokemonGlobal
  183. $PokemonGlobal.quests.failQuest(id)
  184. end
  185.  
  186. def advanceQuestToStage(questID,stageNum)
  187. return if !$PokemonGlobal
  188. $PokemonGlobal.quests.advanceQuestToStage(questID,stageNum)
  189. end
  190.  
  191. QUEST_FILE_NAME = "quests.txt" #the name of the file to read from
  192.  
  193. #a module use during compilation of the quest file
  194. module QuestsData
  195.  
  196. NeededInfo={
  197. "Name"=>[1,"s"],
  198. "Stage1"=>[2,"s"],
  199. "Stage2"=>[3,"s"],
  200. "Stage3"=>[4,"s"],
  201. "Stage4"=>[5,"s"],
  202. "Stage5"=>[6,"s"],
  203. "Stage6"=>[7,"s"],
  204. "Stage7"=>[8,"s"],
  205. "Stage8"=>[9,"s"],
  206. "Stage9"=>[10,"s"],
  207. "Stage10"=>[11,"s"],
  208. "Reward"=>[12,"s"],
  209. "RewardDescription"=>[13,"s"],
  210. "QuestDescription"=>[14,"s"],
  211. "StageLocation1" => [15,"v|s"],
  212. "StageLocation2" => [16,"v|s"],
  213. "StageLocation3" => [17,"v|s"],
  214. "StageLocation4" => [18,"v|s"],
  215. "StageLocation5" => [19,"v|s"],
  216. "StageLocation6" => [20,"v|s"],
  217. "StageLocation7" => [21,"v|s"],
  218. "StageLocation8" => [22,"v|s"],
  219. "StageLocation9" => [23,"v|s"],
  220. "StageLocation10" => [24,"v|s"],
  221. "CompletedMessage"=>[25,"s"],
  222. "FailedMessage"=>[26,"s"],
  223. }
  224.  
  225. end
  226.  
  227.  
  228. #Psuedo class to read quest info from
  229. class QuestInfo
  230.  
  231. attr_reader :id
  232. attr_reader :name
  233. attr_reader :stages
  234. attr_reader :rewardString
  235. attr_reader :rewardDesc
  236. attr_reader :questDesc
  237. attr_reader :locations
  238. attr_reader :completedMessage
  239. attr_reader :failedMessage
  240.  
  241. def initialize(id,questName,stages,rewardString,rewardDesc,
  242. questDesc,locations,completedMessage,failedMessage)
  243. @id = id
  244. @name = questName
  245. @stages = stages
  246. @rewardString = rewardString
  247. @rewardDesc = rewardDesc
  248. @questDesc = questDesc
  249. @locations = locations
  250. @completedMessage = completedMessage
  251. @failedMessage = failedMessage
  252. end
  253.  
  254. end
  255.  
  256.  
  257. #This class loads/reads all data for all quests. Updates at the start
  258. #of every game session will use this class to determine their values,
  259. #and this is used for deciding updates/rewards, etc
  260. class Game_Quests
  261.  
  262. def initialize
  263. needCompile = false
  264. latestdatatime = 0
  265. latesttexttime = 0
  266. if !safeExists?("Data/Quests.rxdata")
  267. needCompile = true
  268. else
  269. File.open("Data/Quests.rxdata"){|file|
  270. latestdatatime=[latestdatatime,file.mtime.to_i].max
  271. }
  272. File.open("PBS/#{QUEST_FILE_NAME}"){|file|
  273. latesttexttime=[latesttexttime,file.mtime.to_i].max
  274. }
  275. needCompile=true if latesttexttime>=latestdatatime
  276. needCompile=true if Input.press?(Input::CTRL)
  277. end
  278. if $DEBUG && safeExists?("PBS/#{QUEST_FILE_NAME}") && needCompile
  279. compileAllQuests
  280. else
  281. begin
  282. @all_quests = load_data("Data/Quests.rxdata")
  283. rescue
  284. @all_quests = []
  285. Kernel.pbMessage("No quests data found")
  286. end
  287. end
  288. end
  289.  
  290. def compileAllQuests
  291. #names and IDs must be unique
  292. checkQuestIDs=[]
  293. checkQuestNames=[]
  294. @all_quests = []
  295. currentQuest = 0
  296. name = ""
  297. stages = []
  298. rewardString = ""
  299. rewardDesc = ""
  300. questDesc = ""
  301. completedMessage = ""
  302. failedMessage = ""
  303. locations = []
  304. lineCount = 0
  305. #check order of stages
  306. curStage = 0
  307. curLocation = 0
  308. pbCompilerEachCommentedLine("PBS/"+QUEST_FILE_NAME) {|line,lineno|
  309. lineCount+=1
  310. if line[/^\s*\[\s*(\d+)\s*\]\s*$/]
  311. if currentQuest>0
  312. if stages.length==0
  313. raise _INTL("Se espera al menos una etapa para la búsqueda {1}\r\n{2}",currentQuest,FileLineData.linereport)
  314. end
  315. if locations.length!=stages.length
  316. raise _INTL("Se espera al menos una cantidad de ubicaciones {1}\r\n{2}",currentQuest,FileLineData.linereport)
  317. end
  318. if questDesc.nil? || questDesc==""
  319. raise _INTL("Se espera al menos una descripción {1}\r\n{2}",currentQuest,FileLineData.linereport)
  320. end
  321. if rewardString.nil? || rewardString==""
  322. raise _INTL("Expected a reward for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  323. end
  324. if rewardDesc.nil? || rewardDesc==""
  325. raise _INTL("Expected a reward description for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  326. end
  327. if completedMessage.nil? || completedMessage==""
  328. raise _INTL("Expected a completed message for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  329. end
  330. if failedMessage.nil? || failedMessage==""
  331. raise _INTL("Expected a failed message for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  332. end
  333. @all_quests.push(QuestInfo.new(currentQuest,name,stages,rewardString,rewardDesc,
  334. questDesc,locations,completedMessage,failedMessage))
  335. curStage = 0
  336. curLocation = 0
  337. name = ""
  338. stages = []
  339. locations = []
  340. rewardString = ""
  341. rewardDesc = ""
  342. questDesc = ""
  343. completedMessage = ""
  344. failedMessage = ""
  345. end
  346. sectionname=$~[1]
  347. if checkQuestIDs.include?(sectionname.to_i)
  348. raise _INTL("Quest numbers must be unique! {1} already used\r\n{2}",sectionname,FileLineData.linereport)
  349. end
  350. currentQuest=sectionname.to_i
  351. checkQuestIDs.push(currentQuest)
  352. else
  353. if currentQuest==0
  354. raise _INTL("Expected a section at the beginning of the file\r\n{1}",FileLineData.linereport)
  355. end
  356. if !line[/^\s*(\w+)\s*=\s*(.*)$/]
  357. raise _INTL("Bad line syntax (expected syntax like XXX=YYY)\r\n{1}",FileLineData.linereport)
  358. end
  359. matchData=$~
  360. schema=nil
  361. FileLineData.setSection(currentQuest,matchData[1],matchData[2])
  362. schema=QuestsData::NeededInfo[matchData[1]]
  363. schemaValues = schema[1]
  364. if schema
  365. schemaValues = schema[1].split('|')
  366. end
  367. if schema
  368. for i in 0...schemaValues.length
  369. schema[1] = schemaValues[i]
  370. record=pbGetCsvRecord(matchData[2],lineno,schema) rescue next
  371. case schema
  372. when QuestsData::NeededInfo["Name"]
  373. if checkQuestNames.include?(record)
  374. raise _INTL("Quest names must be unique! {1} already used\r\n{2}",record,FileLineData.linereport)
  375. end
  376. name = record
  377. checkQuestNames.push(name)
  378. break
  379. when QuestsData::NeededInfo["Reward"]
  380. rewardString = record
  381. break
  382. when QuestsData::NeededInfo["RewardDescription"]
  383. rewardDesc = record
  384. break
  385. when QuestsData::NeededInfo["QuestDescription"]
  386. questDesc = record
  387. break
  388. when QuestsData::NeededInfo["CompletedMessage"]
  389. completedMessage = record
  390. break
  391. when QuestsData::NeededInfo["FailedMessage"]
  392. failedMessage = record
  393. break
  394. else
  395. if matchData[1].include?("StageLocation")
  396. if ((matchData[1][/\d+/]).to_i)!=curLocation+1
  397. raise _INTL("Locations need to be in order. Expecting location {1}\r\n{2}",curLocation+1,FileLineData.linereport)
  398. end
  399. if record.is_a?(String) && record.downcase=="nil"
  400. curLocation+=1
  401. locations.push(record)
  402. break
  403. elsif record !~ /\D/ #only numbers
  404. mapname = pbGetMessage(MessageTypes::MapNames,record.to_i) rescue nil
  405. if mapname.nil?
  406. raise _INTL("Invalid map id for quest {1}, at stage {2}",sectionname,curLocation)
  407. end
  408. curLocation+=1
  409. locations.push(nil)
  410. break
  411. else
  412. mapid = MessageTypes.getFromMapHashValue(MessageTypes::MapNames,record)
  413. if mapid.nil?
  414. raise _INTL("Invalid map id for quest {1}, at stage {2}",sectionname,curLocation)
  415. end
  416. curLocation+=1
  417. locations.push(mapid)
  418. break
  419. end
  420. elsif matchData[1].include?("Stage")
  421. if ((matchData[1][/\d+/]).to_i)!=curStage+1
  422. raise _INTL("Stages need to be in order. Expecting stage {1}\r\n{2}",curStage+1,FileLineData.linereport)
  423. end
  424. curStage+=1
  425. stages.push(record)
  426. break
  427. else
  428. raise _INTL("Unexpected field {1} for quest {2}",matchData[1],sectionname)
  429. end
  430. end
  431. end
  432. end
  433. end
  434. }
  435. if stages.length==0
  436. raise _INTL("Expected at least one stage for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  437. end
  438. if locations.length!=stages.length
  439. raise _INTL("Expected the number of locations to match the number of stages for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  440. end
  441. if questDesc.nil? || questDesc==""
  442. raise _INTL("Expected a quest description for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  443. end
  444. if rewardString.nil? || rewardString==""
  445. raise _INTL("Expected a reward for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  446. end
  447. if rewardDesc.nil? || rewardDesc==""
  448. raise _INTL("Expected a reward description for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  449. end
  450. if completedMessage.nil? || completedMessage==""
  451. raise _INTL("Expected a completed message for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  452. end
  453. if failedMessage.nil? || failedMessage==""
  454. raise _INTL("Expected a failed message for quest {1}\r\n{2}",currentQuest,FileLineData.linereport)
  455. end
  456. @all_quests.push(QuestInfo.new(currentQuest,name,stages,rewardString,
  457. rewardDesc,questDesc,locations,completedMessage,failedMessage)) if lineCount>0
  458. save_data(@all_quests,"Data/Quests.rxdata")
  459. end
  460.  
  461. def nameAllQuests
  462. for i in 0...@all_quests.length
  463. Kernel.pbMessage("#{@all_quests[i].id}")
  464. Kernel.pbMessage("#{@all_quests[i].name}")
  465. for j in 0...@all_quests[i].stages.length
  466. Kernel.pbMessage("#{@all_quests[i].stages[j]}")
  467. end
  468. Kernel.pbMessage("#{@all_quests[i].rewardString}")
  469. Kernel.pbMessage("#{@all_quests[i].rewardDesc}")
  470. Kernel.pbMessage("#{@all_quests[i].questDesc}")
  471. end
  472. end
  473.  
  474. def getIDFromName(name)
  475. for i in 0...@all_quests.length
  476. return @all_quests[i].id if @all_quests[i].name==name
  477. end
  478. end
  479.  
  480. def getNameFromID(id)
  481. for i in 0...@all_quests.length
  482. return @all_quests[i].name if @all_quests[i].id==id
  483. end
  484. end
  485.  
  486.  
  487. def getQuestStages(questID)
  488. if questID.is_a?(String)
  489. questID = getIDFromName(questID)
  490. end
  491. for i in 0...@all_quests.length
  492. return @all_quests[i].stages if @all_quests[i].id==questID
  493. end
  494. end
  495.  
  496. def getQuestReward(questID)
  497. if questID.is_a?(String)
  498. questID = getIDFromName(questID)
  499. end
  500. for i in 0...@all_quests.length
  501. return @all_quests[i].rewardString if @all_quests[i].id==questID
  502. end
  503. end
  504.  
  505. def getQuestRewardDescription(questID)
  506. if questID.is_a?(String)
  507. questID = getIDFromName(questID)
  508. end
  509. for i in 0...@all_quests.length
  510. return @all_quests[i].rewardDesc if @all_quests[i].id==questID
  511. end
  512. end
  513.  
  514. def getQuestDescription(questID)
  515. if questID.is_a?(String)
  516. questID = getIDFromName(questID)
  517. end
  518. for i in 0...@all_quests.length
  519. return @all_quests[i].questDesc if @all_quests[i].id==questID
  520. end
  521. end
  522.  
  523. def getStageLocation(questID,stage)
  524. if questID.is_a?(String)
  525. questID = getIDFromName(questID)
  526. end
  527. for i in 0...@all_quests.length
  528. return @all_quests[i].locations[stage-1] if @all_quests[i].id==questID
  529. end
  530. end
  531.  
  532. def getMaxStagesForQuest(questID)
  533. if questID.is_a?(String)
  534. questID = getIDFromName(questID)
  535. end
  536. quests = getQuestStages(questID)
  537. return quests.length
  538. end
  539.  
  540. def getCompletedMessage(questID)
  541. if questID.is_a?(String)
  542. questID = getIDFromName(questID)
  543. end
  544. for i in 0...@all_quests.length
  545. return @all_quests[i].completedMessage if @all_quests[i].id==questID
  546. end
  547. end
  548.  
  549. def getFailedMessage(questID)
  550. if questID.is_a?(String)
  551. questID = getIDFromName(questID)
  552. end
  553. for i in 0...@all_quests.length
  554. return @all_quests[i].failedMessage if @all_quests[i].id==questID
  555. end
  556. end
  557. end
  558.  
  559.  
  560. #modify messages to check for a map name among the maps
  561. class Messages
  562.  
  563. def getFromMapHashValue(type,key)
  564. delayedLoad
  565. return nil if !@messages
  566. return nil if !@messages[0]
  567. return nil if !@messages[0][type] && !@messages[0][0]
  568. key.sub!("e^","é")
  569. id=Messages.stringToKey(key)
  570. if @messages[type] && @messages[type].include?(id)
  571. return @messages[type].index(id)
  572. elsif @messages[0] && @messages[0].include?(id)
  573. return @messages[0].index(id)
  574. end
  575. return nil
  576. end
  577.  
  578. end
  579.  
  580. module MessageTypes
  581.  
  582. def self.getFromMapHashValue(type,key)
  583. @@messages.getFromMapHashValue(type,key)
  584. end
  585.  
  586. end
  587.  
  588.  
  589. $quest_data = Game_Quests.new
  590. #$quest_data.nameAllQuests
  591.  
  592. QUEST_GRAPHICS_PATH = "Graphics/Pictures/Quest UI/"
  593.  
  594. class QuestScene
  595. @@viewingActive = 0
  596. @@viewingComplete = 0
  597. @@viewingFailed = 0
  598.  
  599. def update
  600. pbUpdateSpriteHash(@sprites)
  601. end
  602.  
  603. def pbStartScene
  604. @yOffsetInfo=0
  605. @yOffsetList=0
  606. @curNumLines=0
  607. @sprites={}
  608. @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  609. @viewport.z=99999
  610. @viewport_text=Viewport.new(0,0,Graphics.width,Graphics.height)
  611. @viewport_text.z=99999+1
  612. @sprites["background"]=IconSprite.new(0,0,@viewport)
  613. @sprites["background"].setBitmap(QUEST_GRAPHICS_PATH+"quest_bg")
  614. @sprites["background"].zoom_x = Graphics.width/(@sprites["background"].bitmap.width)
  615. @sprites["background"].zoom_y = Graphics.height/(@sprites["background"].bitmap.height)
  616. @sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
  617. @sprites["sections_text_overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport_text)
  618. @sprites["quests_list_overlay"]=BitmapSprite.new(Graphics.width,Graphics.height*4/5,@viewport_text)
  619. @sprites["quests_list_overlay"].x=45
  620. @sprites["quests_list_overlay"].y=36
  621. @sprites["quest_info_overlay"]=BitmapSprite.new(Graphics.width,Graphics.height*4/5,@viewport_text)
  622. @sprites["quest_info_overlay"].y=36
  623. @sprites["quest_info_overlay"].x=290
  624. @sprites["navigation_info_overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport_text)
  625. pbSetSmallFont(@sprites["overlay"].bitmap)
  626. pbSetSmallFont(@sprites["sections_text_overlay"].bitmap)
  627. pbSetSmallFont(@sprites["quests_list_overlay"].bitmap)
  628. pbSetSmallFont(@sprites["quest_info_overlay"].bitmap)
  629. pbSetSmallFont(@sprites["navigation_info_overlay"].bitmap)
  630. pbDrawSections
  631. pbDrawNavigationInfo
  632. end
  633.  
  634. def pbDrawNavigationInfo
  635. overlay=@sprites["navigation_info_overlay"].bitmap
  636. overlay.clear
  637. @sprites["navigation_info_overlay"].bitmap.font.size=20
  638. baseColor=Color.new(238,233,233)
  639. shadowColor=Color.new(72,80,80)
  640. textPositions = [
  641. ["A S - Desplegar info.",20,Graphics.height-20,0,baseColor,shadowColor],
  642. ["Flechas - Desplazarse",Graphics.width-300,Graphics.height-20,0,baseColor,shadowColor],
  643. ["X - Salir",Graphics.width-100,Graphics.height-20,0,baseColor,shadowColor],
  644. ]
  645. pbDrawTextPositions(overlay,textPositions)
  646. end
  647.  
  648. def pbDrawSections
  649. @activeQuests=$PokemonGlobal.quests.active_quests
  650. @completedQuests=$PokemonGlobal.quests.completed_quests
  651. @failedQuests=$PokemonGlobal.quests.failed_quests
  652. @sections=[]
  653. @sections.push([0,_INTL("Activas")]) if @activeQuests.length>0
  654. @sections.push([1,_INTL("Completadas")]) if @completedQuests.length>0
  655. @sections.push([2,_INTL("Principales")]) if @failedQuests.length>0
  656. @@viewingActive = @activeQuests[0].id if @activeQuests!=[] && @@viewingActive<=0
  657. @@viewingComplete = @completedQuests[0].id if @completedQuests!=[] && @@viewingComplete<=0
  658. @@viewingFailed = @failedQuests[0].id if @failedQuests!=[] && @@viewingFailed<=0
  659. baseColor=Color.new(64,64,64)
  660. selectedColor=Color.new(64,64,64)
  661. shadowColor=Color.new(172,172,172)
  662. selectedShadowColor=Color.new(172,172,172)
  663. bitmap = @sprites["sections_text_overlay"].bitmap
  664. bitmap.clear
  665. textPositions=[]
  666. for i in 0...@sections.length
  667. @sprites["section_icon_#{i}"]=IconSprite.new(0,0,@viewport)
  668. @sprites["section_icon_#{i}"].setBitmap(QUEST_GRAPHICS_PATH+"section_bar")
  669. @sprites["section_icon_#{i}"].x=20+(160*i)
  670. @sprites["section_icon_#{i}"].y=5
  671. @sprites["section_icon_#{i}"].zoom_x=2
  672. @sprites["section_icon_#{i}"].zoom_y=2
  673. if @sections[i][0]==$PokemonGlobal.selectedSection
  674. @sprites["section_icon_#{i}"].src_rect.set(@sprites["section_icon_#{i}"].bitmap.width/2,0,@sprites["section_icon_#{i}"].bitmap.width/2,@sprites["section_icon_#{i}"].bitmap.height)
  675. else
  676. @sprites["section_icon_#{i}"].src_rect.set(0,0,@sprites["section_icon_#{i}"].bitmap.width/2,@sprites["section_icon_#{i}"].bitmap.height)
  677. end
  678. if @sections[i][0]==$PokemonGlobal.selectedSection
  679. textPositions.push([@sections[i][1],85+(160*i),3,2,selectedColor,selectedShadowColor])
  680. else
  681. textPositions.push([@sections[i][1],85+(160*i),3,2,baseColor,shadowColor])
  682. end
  683. end
  684. pbDrawTextPositions(bitmap,textPositions)
  685. pbDrawQuestsList
  686. end
  687.  
  688. def getSelectedID
  689. questOptions=[@activeQuests,@completedQuests,@failedQuests]
  690. quests = questOptions[$PokemonGlobal.selectedSection]
  691. selectionOptions=[@@viewingActive,@@viewingComplete,@@viewingFailed]
  692. questFound = false
  693. for i in 0...quests.length
  694. if quests[i].id==selectionOptions[$PokemonGlobal.selectedSection]
  695. questFound = true
  696. break
  697. end
  698. end
  699. if selectionOptions[$PokemonGlobal.selectedSection]<0
  700. questFound = false
  701. end
  702. if !questFound
  703. case $PokemonGlobal.selectedSection
  704. when 0
  705. @@viewingActive = quests[0].id
  706. selectedID = @@viewingActive
  707. when 1
  708. @@viewingComplete = quests[0].id
  709. selectedID = @@viewingComplete
  710. when 2
  711. @@viewingFailed = quests[0].id
  712. selectedID = @@viewingFailed
  713. end
  714. else
  715. selectedID = selectionOptions[$PokemonGlobal.selectedSection]
  716. end
  717. return [quests,selectedID]
  718. end
  719.  
  720. def pbDrawQuestsList
  721. overlay=@sprites["quests_list_overlay"].bitmap
  722. overlay.clear
  723. ret = getSelectedID
  724. quests = ret[0]
  725. selectedID = ret[1]
  726. textPositions = []
  727. baseColor=Color.new(72,72,72)
  728. selectedColor=Color.new(0,0,139)
  729. shadowColor=Color.new(160,160,160)
  730. selectedShadowColor=Color.new(160,160,160)
  731. for i in 0...quests.length
  732. if quests[i].id==selectedID
  733. textPositions.push([$quest_data.getNameFromID(quests[i].id),0,@yOffsetList+2+(i*31),0,selectedColor,selectedShadowColor])
  734. else
  735. textPositions.push([$quest_data.getNameFromID(quests[i].id),0,@yOffsetList+2+(i*31),0,baseColor,shadowColor])
  736. end
  737. end
  738. pbDrawTextPositions(overlay,textPositions)
  739. pbDrawQuestInfo
  740. end
  741.  
  742. def pbDrawQuestInfo
  743. overlay=@sprites["quest_info_overlay"].bitmap
  744. overlay.clear
  745. ret = getSelectedID
  746. quests = ret[0]
  747. selectedID = ret[1]
  748. textPositions = []
  749. baseColor=Color.new(64,64,64)
  750. shadowColor=Color.new(176,176,176)
  751. titleColor = Color.new(99,184,255)
  752. titleShadow = Color.new(72,80,80)
  753. selectedColor=Color.new(255,60,65)
  754. selectedShadow=Color.new(255,145,148)
  755. @curNumLines=1
  756. for i in 0...quests.length
  757. if quests[i].id==selectedID
  758. questDescArr = $quest_data.getQuestDescription(quests[i].id).wordwrap(20)
  759. stages = $quest_data.getQuestStages(quests[i].id)
  760. if stages[quests[i].stage-1]
  761. stageDescArr = (stages[quests[i].stage-1]).wordwrap(20)
  762. else
  763. stageDescArr=[]
  764. end
  765. textPositions.push([$quest_data.getNameFromID(quests[i].id),(Graphics.width-300)/2,@yOffsetInfo,2,titleColor,titleShadow])
  766. @curNumLines+=1
  767. for j in 0...questDescArr.length
  768. textPositions.push([_INTL("{1}",questDescArr[j]),0,@yOffsetInfo+20+20*j,0,baseColor,shadowColor])
  769. @curNumLines+=1
  770. end
  771. #What's draw depends on if completed, failed, or active
  772. if $PokemonGlobal.selectedSection==2
  773. textPositions.push([_INTL("Estado"),0,@yOffsetInfo+20+20*questDescArr.length,0,selectedColor,shadowColor])
  774. textPositions.push([_INTL(" {1}",$quest_data.getFailedMessage(quests[i].id)),0,@yOffsetInfo+40+20*questDescArr.length,0,baseColor,shadowColor])
  775. @curNumLines+=1
  776. break
  777. elsif $PokemonGlobal.selectedSection==1
  778. textPositions.push([_INTL("Estado"),0,@yOffsetInfo+20+20*questDescArr.length,0,selectedColor,shadowColor])
  779. textPositions.push([_INTL(" {1}",$quest_data.getCompletedMessage(quests[i].id)),0,@yOffsetInfo+40+20*questDescArr.length,0,baseColor,shadowColor])
  780. @curNumLines+=1
  781. break
  782. else
  783. textPositions.push([_INTL("Recompensa"),0,@yOffsetInfo+20+20*questDescArr.length,0,selectedColor,shadowColor])
  784. textPositions.push([_INTL("{1}",$quest_data.getQuestRewardDescription(quests[i].id)),0,@yOffsetInfo+40+20*questDescArr.length,0,baseColor,shadowColor])
  785. @curNumLines+=1
  786. textPositions.push([_INTL("Nueva tarea"),0,@yOffsetInfo+40+20*(questDescArr.length+1),0,selectedColor,shadowColor])
  787. @curNumLines+=1
  788. textPositions.push([_INTL(" {1}",stageDescArr[0]),0,@yOffsetInfo+60+20*(questDescArr.length+1),0,baseColor,shadowColor])
  789. @curNumLines+=1
  790. for k in 1...stageDescArr.length
  791. textPositions.push([_INTL("{1}",stageDescArr[k]),0,@yOffsetInfo+60+20*(questDescArr.length+1)+40*k,0,baseColor,shadowColor])
  792. @curNumLines+=1
  793. end
  794. if $quest_data.getStageLocation(quests[i].id,quests[i].stage).to_s=="nil"
  795. locationText = "No hay localización disponible"
  796. else
  797. ret=pbGetMessage(MessageTypes::MapNames,$quest_data.getStageLocation(quests[i].id,quests[i].stage))
  798. if $Trainer
  799. ret.gsub!(/\\PN/,$Trainer.name)
  800. end
  801. locationText = ret
  802. end
  803. textPositions.push([_INTL("Siguiente Localización"),0,@yOffsetInfo+60+20*(questDescArr.length)+20*(stageDescArr.length+1),0,selectedColor,shadowColor])
  804. @curNumLines+=1
  805. textPositions.push([_INTL(" {1}",locationText),0,@yOffsetInfo+80+20*(questDescArr.length)+20*(stageDescArr.length+1),0,baseColor,shadowColor])
  806. @curNumLines+=1
  807. break
  808. end
  809. end
  810. end
  811. pbDrawTextPositions(overlay,textPositions)
  812. end
  813.  
  814. def pbMain
  815. loop do
  816. Graphics.update
  817. Input.update
  818. self.update
  819. if Input.trigger?(Input::B) #exit from scene
  820. break
  821. end
  822. #change selected list
  823. if Input.trigger?(Input::LEFT) #A
  824. @yOffsetInfo=0
  825. @yOffsetList=0
  826. for i in 0...@sections.length
  827. if $PokemonGlobal.selectedSection==@sections[i][0]
  828. pos = i
  829. break
  830. end
  831. end
  832. pos-=1
  833. if pos<0
  834. pos = @sections.length-1
  835. end
  836. $PokemonGlobal.selectedSection = @sections[pos][0]
  837. pbDrawSections
  838. elsif Input.trigger?(Input::RIGHT) #S
  839. @yOffsetInfo=0
  840. @yOffsetList=0
  841. for i in 0...@sections.length
  842. if $PokemonGlobal.selectedSection==@sections[i][0]
  843. pos = i
  844. break
  845. end
  846. end
  847. pos+=1
  848. if pos>=@sections.length
  849. pos = 0
  850. end
  851. $PokemonGlobal.selectedSection = @sections[pos][0]
  852. pbDrawSections
  853. #Scroll quest info up/down
  854. elsif Input.trigger?(Input::R) #up
  855. if (@yOffsetInfo/-20)<(@curNumLines-15)
  856. @yOffsetInfo-=20
  857. pbDrawQuestInfo
  858. end
  859. elsif Input.trigger?(Input::L) #down
  860. if @yOffsetInfo<0
  861. @yOffsetInfo+=20
  862. pbDrawQuestInfo
  863. end
  864. #move up/down list of quests
  865. elsif Input.trigger?(Input::DOWN)
  866. @yOffsetInfo=0
  867. case $PokemonGlobal.selectedSection
  868. when 0
  869. for i in 0...@activeQuests.length
  870. if @activeQuests[i].id==@@viewingActive
  871. nextQuest = i+1
  872. break
  873. end
  874. end
  875. if nextQuest>=@activeQuests.length
  876. @@viewingActive=@activeQuests[0].id
  877. @yOffsetList=0
  878. else
  879. @@viewingActive = @activeQuests[nextQuest].id
  880. if (@yOffsetList/-31)<@activeQuests.length-10
  881. @yOffsetList-=31
  882. end
  883. end
  884. when 1
  885. for i in 0...@completedQuests.length
  886. if @completedQuests[i].id==@@viewingComplete
  887. nextQuest = i+1
  888. break
  889. end
  890. end
  891. if nextQuest>=@completedQuests.length
  892. @@viewingComplete=@completedQuests[0].id
  893. @yOffsetList=0
  894. else
  895. @@viewingComplete = @completedQuests[nextQuest].id
  896. if (@yOffsetList/-31)<@completedQuests.length-6
  897. @yOffsetList-=31
  898. end
  899. end
  900. when 2
  901. for i in 0...@failedQuests.length
  902. if @failedQuests[i].id==@@viewingFailed
  903. nextQuest = i+1
  904. break
  905. end
  906. end
  907. if nextQuest>=@failedQuests.length
  908. @@viewingFailed=@failedQuests[0].id
  909. @yOffsetList=0
  910. else
  911. @@viewingFailed = @failedQuests[nextQuest].id
  912. if (@yOffsetList/-31)<@failedQuests.length-6
  913. @yOffsetList-=31
  914. end
  915. end
  916. end
  917. pbDrawQuestsList
  918. elsif Input.trigger?(Input::UP)
  919. @yOffsetInfo=0
  920. case $PokemonGlobal.selectedSection
  921. when 0
  922. for i in 0...@activeQuests.length
  923. if @activeQuests[i].id==@@viewingActive
  924. nextQuest = i-1
  925. break
  926. end
  927. end
  928. if nextQuest<0
  929. @@viewingActive=@activeQuests[@activeQuests.length-1].id
  930. if @activeQuests.length>10
  931. @yOffsetList=(@activeQuests.length-10)*-31
  932. end
  933. else
  934. @@viewingActive = @activeQuests[nextQuest].id
  935. if @yOffsetList<0
  936. @yOffsetList+=31
  937. end
  938. end
  939. when 1
  940. for i in 0...@completedQuests.length
  941. if @completedQuests[i].id==@@viewingComplete
  942. nextQuest = i+1
  943. break
  944. end
  945. end
  946. if nextQuest<0
  947. @@viewingComplete=@completedQuests[@completedQuests.length-1].id
  948. if @completedQuests.length>10
  949. @yOffsetList=(@completedQuests.length-10)*-31
  950. end
  951. else
  952. @@viewingComplete = @completedQuests[nextQuest].id
  953. if @yOffsetList<0
  954. @yOffsetList+=31
  955. end
  956. end
  957. when 2
  958. for i in 0...@failedQuests.length
  959. if @failedQuests[i].id==@@viewingFailed
  960. nextQuest = i+1
  961. break
  962. end
  963. end
  964. if nextQuest<0
  965. @@viewingFailed=@failedQuests[@failedQuests.length-1].id
  966. if @failedQuests.length>10
  967. @yOffsetList=(@failedQuests.length-10)*-31
  968. end
  969. else
  970. @@viewingFailed = @failedQuests[nextQuest].id
  971. if @yOffsetList<0
  972. @yOffsetList+=31
  973. end
  974. end
  975. end
  976. pbDrawQuestsList
  977. end
  978. end
  979. end
  980.  
  981. def pbEndScene
  982. pbFadeOutAndHide(@sprites) { update }
  983. pbDisposeSpriteHash(@sprites)
  984. @viewport.dispose
  985. end
  986. end
  987.  
  988. class QuestScreen
  989. def initialize(scene)
  990. @scene=scene
  991. end
  992.  
  993. def pbStartScreen
  994. @scene.pbStartScene
  995. @scene.pbMain
  996. @scene.pbEndScene
  997. end
  998. end
  999.  
  1000. def pbViewQuests
  1001. if !hasAnyQuests?
  1002. Kernel.pbMessage(_INTL("No tienes ningún encargo."))
  1003. return false
  1004. end
  1005. scene=QuestScene.new
  1006. screen=QuestScreen.new(scene)
  1007. screen.pbStartScreen()
  1008. end
  1009.  
  1010.  
  1011. #Store currently selected section
  1012. class PokemonGlobalMetadata
  1013. attr_writer :selectedSection
  1014. def selectedSection
  1015. @selectedSection = 0 if !@selectedSection
  1016. return @selectedSection
  1017. end
  1018.  
  1019. alias quest_ui_init initialize
  1020. def initialize
  1021. quest_ui_init
  1022. @selectedSection = 0
  1023. end
  1024. end
  1025.  
  1026. def hasAnyQuests?
  1027. if $PokemonGlobal.quests.active_quests.length >0 ||
  1028. $PokemonGlobal.quests.completed_quests.length>0 ||
  1029. $PokemonGlobal.quests.failed_quests.length>0
  1030. return true
  1031. end
  1032. return false
  1033. end
  1034.  
  1035. #word wrapping (returns an array of sentence fragments, broken by length)
  1036. #words kept together
  1037. #requires monospaced font to work properly
  1038. class String
  1039. def wordwrap(width)
  1040. return self.scan(/\S.{0,#{width-2}}\S(?=\s|$)|\S+/)
  1041. end
  1042. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement