re-added barbarian fishing

This commit is contained in:
Ceikry 2021-03-12 00:31:00 -06:00
parent dd73be1b70
commit 42a4e99f78
5 changed files with 280 additions and 0 deletions

View file

@ -0,0 +1,30 @@
package rs09.game.node.entity.skill.fishing.barbfishing
import core.game.node.item.Item
import rs09.game.interaction.OptionListener
class BarbFishOptionListeners : OptionListener() {
override fun defineListeners() {
on(25268,OBJECT,"search"){player,_ ->
if(player.getAttribute("barbtraining:fishing",false) == true){
if(!player.inventory.containsItem(Item(11323))){
player.inventory.add(Item(11323))
player.sendMessage("Under the bed you find a fishing rod.")
} else {
player.sendMessage("You find nothing under the bed")
}
} else {
player.sendMessage("Maybe I should speak to Otto before looking under his bed.")
}
return@on true
}
on(1176,NPC,"fish"){player,_ ->
player.pulseManager.run(BarbFishingPulse(player))
player.sendMessage("You attempt to catch a fish...")
return@on true
}
}
}

View file

@ -0,0 +1,98 @@
package rs09.game.node.entity.skill.fishing.barbfishing
import core.game.node.entity.npc.NPC
import core.game.node.entity.player.Player
import core.game.node.entity.skill.SkillPulse
import core.game.node.entity.skill.Skills
import core.game.node.item.Item
import core.game.world.update.flag.context.Animation
import core.tools.RandomFunction
import rs09.tools.Items
import rs09.tools.stringtools.colorize
/**
* Pulse used for barbarian fishing
* @author Ceikry
*/
class BarbFishingPulse(player: Player) : SkillPulse<NPC>(player,NPC(1176)) {
override fun checkRequirements(): Boolean {
/*if(player.getAttribute("barbtraining:fishing:completed",false) == false){
player.sendMessage(colorize("%RYou need to complete barbarian fishing training to fish here."))
return false
}*/
if(player.skills.getLevel(Skills.FISHING) < 48){
player.sendMessage(colorize("%RYou need a fishing level of at least 48 to fish here."))
return false
}
if(player.skills.getLevel(Skills.AGILITY) < 15 || player.skills.getLevel(Skills.STRENGTH) < 15){
player.sendMessage(colorize("%RYou need a strength and agility level of at least 15 to fish here."))
return false
}
if(!player.inventory.containsItem(Item(11323))){
player.sendMessage(colorize("%RYou need a barbarian fishing rod to fish here."))
return false
}
if(player.inventory.isFull){
player.sendMessage("You don't have enough space in your inventory.")
return false
}
if(!(player.inventory.containsItem(Item(Items.FEATHER_314)) || player.inventory.containsItem(Item(Items.FISH_OFFCUTS_11334)))){
player.sendMessage("You don't have any bait with which to fish.")
return false
}
return true
}
override fun animate() {
player.animator.animate(Animation(622))
}
override fun reward(): Boolean {
val stragiXP = arrayOf(5,6,7)
val fishXP = arrayOf(50,70,80)
val reward = getRandomFish()
val success = rollSuccess(when(reward){
Item(11328) -> 48
Item(11330) -> 58
Item(11332) -> 70
else -> 99
})
val index = (when(reward){
Item(11328) -> 0
Item(11330) -> 1
Item(11332) -> 2
else -> 0
})
if(success){
if(!player.inventory.remove(Item(Items.FISH_OFFCUTS_11334))) {
player.inventory.remove(Item(Items.FEATHER_314))
}
player.inventory.add(reward)
player.skills.addExperience(Skills.FISHING,fishXP[index].toDouble())
player.skills.addExperience(Skills.AGILITY,stragiXP[index].toDouble())
player.skills.addExperience(Skills.STRENGTH,stragiXP[index].toDouble())
player.sendMessage("You manage to catch a ${reward.name.toLowerCase()}.")
}
super.setDelay(5)
return player.inventory.freeSlots() == 0
}
fun rollSuccess(fish: Int): Boolean{
val level = 1 + player.skills.getLevel(Skills.FISHING) + player.familiarManager.getBoost(Skills.FISHING)
val hostRatio: Double = Math.random() * fish
val clientRatio: Double = Math.random() * (level * 3.0 - fish)
return hostRatio < clientRatio
}
fun getRandomFish(): Item{
val fish = arrayOf(11328,11330,11332)
val fishing = player.skills.getLevel(Skills.FISHING)
val strength = player.skills.getLevel(Skills.STRENGTH)
val agility = player.skills.getLevel(Skills.AGILITY)
var possibleIndex = 0
if(fishing >= 58 && (strength >= 30 && agility >= 30)) possibleIndex++
if(fishing >= 70 && (strength >= 45 && agility >= 45)) possibleIndex++
return Item(fish[RandomFunction.random(possibleIndex + 1)])
}
}

View file

@ -0,0 +1,45 @@
package rs09.game.node.entity.skill.fishing.barbfishing
import core.game.node.entity.player.Player
import core.game.node.entity.skill.Skills
import core.game.node.item.Item
import core.game.system.task.Pulse
import core.game.world.update.flag.context.Animation
import rs09.tools.Items
/**
* Pulse used for cutting fish into fish offcuts
* @param player the player running the pulse
* @param fish the fish being cut
* @author Ceikry
*/
class FishCuttingPulse(val player: Player, val fish: Int) : Pulse(0){
fun checkRequirements(): Boolean {
if(!(player.inventory.freeSlots() >= 2 || (player.inventory.freeSlots() >= 1 && player.inventory.containsItem(Item(Items.FISH_OFFCUTS_11334))))){
player.sendMessage("You do not have enough space to do that.")
return false
}
return true
}
override fun pulse(): Boolean {
player.animator.animate(Animation(1248))
player.inventory.remove(Item(fish))
player.inventory.add(Item(Items.FISH_OFFCUTS_11334))
player.inventory.add(Item(when(fish){
11328, 11330 -> Items.ROE_11324
11332 -> Items.CAVIAR_11326
else -> 0
}))
player.skills.addExperience(Skills.COOKING,when(fish){
11328,11330 -> 10.0
11332 -> 15.0
else -> 0.0
})
return true
}
}

View file

@ -0,0 +1,26 @@
package rs09.game.node.entity.skill.fishing.barbfishing
import core.game.interaction.NodeUsageEvent
import core.game.interaction.UseWithHandler
import core.plugin.Initializable
import core.plugin.Plugin
import rs09.tools.Items
@Initializable
/**
* Handles using a knife with barbarian fishing fish
* @author Ceikry
*/
class KnifeWithFish : UseWithHandler(11328,11330,11332){
override fun handle(event: NodeUsageEvent?): Boolean {
event?.player ?: return false
event.player.pulseManager.run(FishCuttingPulse(event.player,event.usedItem.id))
return true
}
override fun newInstance(arg: Any?): Plugin<Any> {
addHandler(Items.KNIFE_946, ITEM_TYPE,this)
return this
}
}

View file

@ -0,0 +1,81 @@
package rs09.game.node.entity.skill.fishing.barbfishing
import core.game.node.entity.npc.NPC
import core.game.world.map.Location
import core.plugin.CorePluginTypes.ManagerPlugin
import core.plugin.CorePluginTypes.Managers
import core.plugin.Initializable
import core.plugin.Plugin
import core.tools.RandomFunction
import rs09.game.node.entity.skill.fishing.barbfishing.SpotManager.Companion.locations
import rs09.game.node.entity.skill.fishing.barbfishing.SpotManager.Companion.usedLocations
@Initializable
/**
* Manages fishing spot spawning and relocation
* @author Ceikry
*/
class SpotManager : ManagerPlugin() {
var ticks = 0
val spots = ArrayList<BarbFishingSpot>()
companion object{
val usedLocations = arrayListOf<Location>()
val locations = listOf(
Location.create(2506, 3494, 0),
Location.create(2504, 3497, 0),
Location.create(2504, 3497, 0),
Location.create(2500, 3506, 0),
Location.create(2500, 3509, 0),
Location.create(2500, 3512, 0),
Location.create(2504, 3516, 0)
)
}
override fun tick() {
if(ticks % 50 == 0){
usedLocations.clear()
for(spot in spots) usedLocations.add(spot.loc ?: Location(0,0,0))
}
}
override fun newInstance(arg: Any?): Plugin<Any> {
for(i in 0 until 5){
spots.add(BarbFishingSpot(getNewLoc(), getNewTTL()).also { it.init() })
}
Managers.register(this)
return this
}
}
fun getNewTTL(): Int{
return RandomFunction.random(400,2000)
}
fun getNewLoc(): Location {
var loc = locations.random()
while(usedLocations.contains(loc)) loc = locations.random()
usedLocations.add(loc)
return loc
}
class BarbFishingSpot(var loc: Location? = null, var ttl: Int) : NPC(1176){
init {
location = loc
}
val locations = listOf(
Location.create(2506, 3494, 0),
Location.create(2504, 3497, 0),
Location.create(2504, 3497, 0),
Location.create(2500, 3506, 0),
Location.create(2500, 3509, 0),
Location.create(2500, 3512, 0),
Location.create(2504, 3516, 0)
)
override fun handleTickActions() {
if(location != loc) properties.teleportLocation = loc.also { ttl = getNewTTL() }
if(ttl-- <= 0){
loc = getNewLoc()
}
}
}