#=============================================================================== # Register contacts #=============================================================================== def pbPhoneRegisterNPC(ident,name,mapid,showmessage=true) $PokemonGlobal.phoneNumbers = [] if !$PokemonGlobal.phoneNumbers exists = pbFindPhoneTrainer(ident,name) if exists return if exists[0] # Already visible exists[0] = true # Make visible else phonenum = [true,ident,name,mapid] $PokemonGlobal.phoneNumbers.push(phonenum) end pbMessage(_INTL("\\me[Register phone]Registered {1} in the Pokégear.",name)) if showmessage end def pbPhoneRegister(event,trainertype,trainername) $PokemonGlobal.phoneNumbers = [] if !$PokemonGlobal.phoneNumbers return if pbFindPhoneTrainer(trainertype,trainername) phonenum = [] phonenum.push(true) phonenum.push(trainertype) phonenum.push(trainername) phonenum.push(0) # time to next battle phonenum.push(0) # can battle phonenum.push(0) # battle count if event phonenum.push(event.map.map_id) phonenum.push(event.id) end $PokemonGlobal.phoneNumbers.push(phonenum) end def pbPhoneDeleteContact(index) $PokemonGlobal.phoneNumbers[index][0] = false # Remove from contact list if $PokemonGlobal.phoneNumbers[index].length==8 $PokemonGlobal.phoneNumbers[index][3] = 0 # Reset countdown $PokemonGlobal.phoneNumbers[index][4] = 0 # Reset countdown end end def pbPhoneRegisterBattle(message,event,trainertype,trainername,maxbattles) return if !$Trainer.has_pokegear # Can't register without a Pokégear return false if !GameData::TrainerType.exists?(trainertype) trainertype = GameData::TrainerType.get(trainertype).id contact = pbFindPhoneTrainer(trainertype,trainername) return if contact && contact[0] # Existing contact and is visible message = _INTL("Let me register you.") if !message return if !pbConfirmMessage(message) displayname = _INTL("{1} {2}", GameData::TrainerType.get(trainertype).name, pbGetMessageFromHash(MessageTypes::TrainerNames,trainername)) if contact # Previously registered, just make visible contact[0] = true else # Add new contact pbPhoneRegister(event,trainertype,trainername) pbPhoneIncrement(trainertype,trainername,maxbattles) end pbMessage(_INTL("\\me[Register phone]Registered {1} in the Pokégear.",displayname)) end #=============================================================================== # Contact information #=============================================================================== def pbRandomPhoneTrainer $PokemonGlobal.phoneNumbers = [] if !$PokemonGlobal.phoneNumbers temparray = [] this_map_metadata = GameData::MapMetadata.try_get($game_map.map_id) return nil if !this_map_metadata || !this_map_metadata.town_map_position currentRegion = this_map_metadata.town_map_position[0] for num in $PokemonGlobal.phoneNumbers next if !num[0] || num.length != 8 # if not visible or not a trainer next if $game_map.map_id == num[6] # Can't call if on same map caller_map_metadata = GameData::MapMetadata.try_get(num[6]) next if !caller_map_metadata || !caller_map_metadata.town_map_position # Can't call if in different region next if caller_map_metadata.town_map_position[0] != currentRegion temparray.push(num) end return nil if temparray.length==0 return temparray[rand(temparray.length)] end def pbFindPhoneTrainer(tr_type, tr_name) # Ignores whether visible or not return nil if !$PokemonGlobal.phoneNumbers for num in $PokemonGlobal.phoneNumbers return num if num[1] == tr_type && num[2] == tr_name # If a match end return nil end def pbHasPhoneTrainer?(tr_type, tr_name) return pbFindPhoneTrainer(tr_type, tr_name) != nil end def pbPhoneBattleCount(tr_type, tr_name) trainer = pbFindPhoneTrainer(tr_type, tr_name) return (trainer) ? trainer[5] : 0 end def pbPhoneReadyToBattle?(tr_type, tr_name) trainer = pbFindPhoneTrainer(tr_type, tr_name) return (trainer && trainer[4]>=2) end #=============================================================================== # Contact rematch data modifications #=============================================================================== def pbPhoneIncrement(tr_type, tr_name, maxbattles) trainer = pbFindPhoneTrainer(tr_type, tr_name) return if !trainer trainer[5] += 1 if trainer[5]