#=============================================================================== # 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.pokegear # Can't register without a Pokégear if trainertype.is_a?(String) || trainertype.is_a?(Symbol) return false if !hasConst?(PBTrainers,trainertype) trainertype = PBTrainers.const_get(trainertype) end 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}",PBTrainers.getName(trainertype), 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 = [] currentRegion = pbGetMetadata($game_map.map_id,MapMetadata::MAP_POSITION) 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 callerRegion = pbGetMetadata(num[6],MapMetadata::MAP_POSITION) # Can't call if in different region next if callerRegion && currentRegion && callerRegion[0]!=currentRegion[0] temparray.push(num) end return nil if temparray.length==0 return temparray[rand(temparray.length)] end def pbFindPhoneTrainer(trtype,trname) # Ignores whether visible or not return nil if !$PokemonGlobal.phoneNumbers trtype = getID(PBTrainers,trtype) return nil if !trtype || trtype<=0 for num in $PokemonGlobal.phoneNumbers return num if num[1]==trtype && num[2]==trname # If a match end return nil end def pbHasPhoneTrainer?(trtype,trname) return pbFindPhoneTrainer(trtype,trname)!=nil end def pbPhoneBattleCount(trtype,trname) trainer = pbFindPhoneTrainer(trtype,trname) return trainer[5] if trainer return 0 end def pbPhoneReadyToBattle?(trtype,trname) trainer = pbFindPhoneTrainer(trtype,trname) return (trainer && trainer[4]>=2) end #=============================================================================== # Contact rematch data modifications #=============================================================================== def pbPhoneIncrement(trtype,trname,maxbattles) trainer = pbFindPhoneTrainer(trtype,trname) return if !trainer trainer[5] += 1 if trainer[5]