Skip to content

Commit

Permalink
Merge pull request #1 from Tomm0017/master
Browse files Browse the repository at this point in the history
Update from origin repo
  • Loading branch information
tristonplummer authored Mar 24, 2019
2 parents fdba80e + 3de5530 commit 92621fc
Show file tree
Hide file tree
Showing 64 changed files with 672 additions and 179 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ a message stating that your key was created. **Do not close the terminal/command
- In the next window you want to select the following and unselect anything else:
* Select ``Create separate module per source set``
* Select ``Use default gradle wrapper (recommended)``
* You can skip the ``Global Gradle settings`` section
* In the ``Global Gradle settings`` section:
* If ``Offline work`` is selected, unselect it
- Give the project a bit of time to create and index its files

#### 3) Install RSMod
Expand Down Expand Up @@ -106,8 +107,10 @@ there should be a green ``run`` button, click on that and let the installation b
- Find the revision of your **client** (*not cache*)
- Open ``${rsmod-project}/game.yml``
- Edit the value for ``revision: 178`` to match your client's revision
- *I receive a* ``error_game_js5connect`` *error on the client console*
- You need to launch the server first and *then* the client
- *When following ``2) Open the project in IntelliJ`` my IntelliJ throws the error ``Build model 'org.jetbrains.plugins.gradle.model.ExternalProject' for root project 'gg.rsmod'``*
- This appears to be an issue that can be solved by upgrading your IntelliJ
- This appears to be an issue that can be solved by upgrading your IntelliJ

## FAQ

Expand Down
4 changes: 2 additions & 2 deletions data/packets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ in-packets:
sign: UNSIGNED
type: SHORT
trans: ADD
- name: src_item
- name: dst_item
sign: UNSIGNED
type: SHORT
trans: ADD
Expand All @@ -448,7 +448,7 @@ in-packets:
- name: dst_component_hash
order: MIDDLE
type: INT
- name: dst_item
- name: src_item
sign: UNSIGNED
type: SHORT

Expand Down
4 changes: 4 additions & 0 deletions game/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ tasks.register("install") {

copy {
into "${rootProject.projectDir}/"

from "${rootProject.projectDir}/game.example.yml"
rename 'game.example.yml', 'game.yml'

from "${rootProject.projectDir}/first-launch-template"
rename 'first-launch-template', 'first-launch'
}

javaexec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import gg.rsmod.plugins.service.marketvalue.ItemMarketValueService
fun ItemContainer.getNetworth(world: World): Long {
val service = world.getService(ItemMarketValueService::class.java)
var networth = 0L
getRaw().forEach { item ->
rawItems.forEach { item ->
if (item != null) {
val cost = service?.get(item.id) ?: world.definitions.getNullable(ItemDef::class.java, item.id)?.cost ?: 0
networth += cost * item.amount
Expand All @@ -27,9 +27,9 @@ fun ItemContainer.getNetworth(world: World): Long {
* Transfer [item] from [this] container to [to] container.
*
* @return
* The amount of items that were transferred.
* The removal [ItemTransaction].
*/
fun ItemContainer.transfer(to: ItemContainer, item: Item, beginSlot: Int = -1, note: Boolean = false, unnote: Boolean = false): Int {
fun ItemContainer.transfer(to: ItemContainer, item: Item, beginSlot: Int = -1, note: Boolean = false, unnote: Boolean = false): ItemTransaction? {
check(item.amount > 0)

/**
Expand Down Expand Up @@ -57,13 +57,13 @@ fun ItemContainer.transfer(to: ItemContainer, item: Item, beginSlot: Int = -1, n

val add = to.add(finalItem.id, finalItem.amount, assureFullInsertion = false)
if (add.completed == 0) {
return 0
return null
}

val remove = remove(item.id, add.completed, assureFullRemoval = true, beginSlot = beginSlot)
if (remove.completed == 0) {
add.revert(to)
return 0
return null
}

/**
Expand All @@ -72,7 +72,7 @@ fun ItemContainer.transfer(to: ItemContainer, item: Item, beginSlot: Int = -1, n
*/
add.first().item.copyAttr(copy)

return remove.completed
return remove
}

fun ItemTransaction.revert(from: ItemContainer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gg.rsmod.plugins.api.ext

import gg.rsmod.game.fs.DefinitionSet
import gg.rsmod.game.model.World
import gg.rsmod.game.model.item.Item
import gg.rsmod.plugins.service.marketvalue.ItemMarketValueService
Expand All @@ -12,6 +11,4 @@ import gg.rsmod.plugins.service.marketvalue.ItemMarketValueService
fun Item.getMarketValue(world: World): Int {
val service = world.getService(ItemMarketValueService::class.java)
return service?.get(id) ?: getDef(world.definitions).cost
}

fun Item.getName(definitions: DefinitionSet): String = getDef(definitions).name
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gg.rsmod.plugins.api.ext

import gg.rsmod.game.model.World
import java.text.DecimalFormat
import java.text.Format

Expand All @@ -18,4 +19,10 @@ fun String.parseAmount(): Long = when {
endsWith("m") -> substring(0, length - 1).toLong() * 1_000_000
endsWith("b") -> substring(0, length - 1).toLong() * 1_000_000_000
else -> substring(0, length).toLong()
}
}

fun interpolate(minChance: Int, maxChance: Int, minLvl: Int, maxLvl: Int, playerLvl: Int): Int =
minChance + (maxChance - minChance) * (playerLvl - minLvl) / (maxLvl - minLvl)

fun World.interpolate(minChance: Int, maxChance: Int, minLvl: Int, maxLvl: Int, playerLvl: Int, cap: Int): Boolean =
random(cap) <= interpolate(minChance, maxChance, minLvl, maxLvl, playerLvl)
28 changes: 26 additions & 2 deletions game/plugins/src/main/kotlin/gg/rsmod/plugins/api/ext/PawnExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import gg.rsmod.game.model.attr.*
import gg.rsmod.game.model.entity.GameObject
import gg.rsmod.game.model.entity.Npc
import gg.rsmod.game.model.entity.Pawn
import gg.rsmod.game.model.entity.Player
import gg.rsmod.game.model.item.Item
import gg.rsmod.game.model.timer.FROZEN_TIMER
import gg.rsmod.game.model.timer.STUN_TIMER
import gg.rsmod.plugins.api.BonusSlot
import gg.rsmod.plugins.api.HitType
import gg.rsmod.plugins.api.HitbarType
Expand Down Expand Up @@ -64,11 +66,33 @@ fun Pawn.showHitbar(percentage: Int, type: HitbarType) {
pendingHits.add(Hit.Builder().onlyShowHitbar().setHitbarType(type.id).setHitbarPercentage(percentage).setHitbarMaxPercentage(type.pixelsWide).build())
}

fun Pawn.freeze(cycles: Int, onFreeze: () -> Unit) {
fun Pawn.freeze(cycles: Int, onFreeze: () -> Unit): Boolean {
if (timers.has(FROZEN_TIMER)) {
return
return false
}
stopMovement()
timers[FROZEN_TIMER] = cycles
onFreeze()
return true
}

fun Pawn.stun(cycles: Int, onStun: () -> Unit): Boolean {
if (timers.has(STUN_TIMER)) {
return false
}
stopMovement()
timers[STUN_TIMER] = cycles
onStun()
return true
}

fun Pawn.stun(cycles: Int) {
stun(cycles) {
if (this is Player) {
graphic(245, 124)
resetInteractions()
interruptQueues()
message("You have been stunned!")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,20 @@ fun Player.openOverlayInterface(displayMode: DisplayMode) {
}

fun Player.sendItemContainer(key: Int, container: ItemContainer) {
write(UpdateInvFullMessage(containerKey = key, items = container.getRaw()))
write(UpdateInvFullMessage(containerKey = key, items = container.rawItems))
}

fun Player.sendItemContainer(parent: Int, child: Int, container: ItemContainer) {
write(UpdateInvFullMessage(parent = parent, child = child, items = container.getRaw()))
write(UpdateInvFullMessage(parent = parent, child = child, items = container.rawItems))
}

fun Player.sendItemContainer(parent: Int, child: Int, key: Int, container: ItemContainer) {
write(UpdateInvFullMessage(parent = parent, child = child, containerKey = key, items = container.getRaw()))
write(UpdateInvFullMessage(parent = parent, child = child, containerKey = key, items = container.rawItems))
}

fun Player.updateItemContainer(key: Int, container: ItemContainer) {
// TODO: UpdateInvPartialMessage
write(UpdateInvFullMessage(containerKey = key, items = container.getRaw()))
write(UpdateInvFullMessage(containerKey = key, items = container.rawItems))
}

fun Player.sendRunEnergy(energy: Int) {
Expand Down Expand Up @@ -411,7 +411,7 @@ fun Player.calculateDeathContainers(): DeathContainers {
val keptContainer = ItemContainer(world.definitions, keepAmount, ContainerStackType.NO_STACK)
val lostContainer = ItemContainer(world.definitions, inventory.capacity + equipment.capacity, ContainerStackType.NORMAL)

var totalItems = inventory.getRaw().filterNotNull() + equipment.getRaw().filterNotNull()
var totalItems = inventory.rawItems.filterNotNull() + equipment.rawItems.filterNotNull()
val valueService = world.getService(ItemMarketValueService::class.java)

if (valueService != null) {
Expand All @@ -421,7 +421,7 @@ fun Player.calculateDeathContainers(): DeathContainers {
}

totalItems.forEach { item ->
if (keepAmount > 0 && !keptContainer.isFull()) {
if (keepAmount > 0 && !keptContainer.isFull) {
val add = keptContainer.add(item, assureFullInsertion = false)
keepAmount -= add.completed
if (add.getLeftOver() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ on_command("item", Privilege.ADMIN_POWER) {
on_command("food", Privilege.ADMIN_POWER) {
val p = player

p.inventory.add(item = Items.MANTA_RAY, amount = p.inventory.getFreeSlotCount())
p.inventory.add(item = Items.MANTA_RAY, amount = p.inventory.freeSlotCount)
}

on_command("varp", Privilege.ADMIN_POWER) {
Expand Down Expand Up @@ -219,6 +219,15 @@ on_command("varbit", Privilege.ADMIN_POWER) {
}
}

on_command("getvarbit", Privilege.ADMIN_POWER) {
val args = player.getCommandArgs()
tryWithUsage(player, args, "Invalid format! Example of proper command <col=801700>::getvarbit 5451</col>") { values ->
val varbit = values[0].toInt()
val state = player.getVarbit(varbit)
player.message("Get varbit (<col=801700>$varbit</col>): <col=801700>$state</col>")
}
}

on_command("getvarbits", Privilege.ADMIN_POWER) {
val p = player

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package gg.rsmod.plugins.content.combat

import gg.rsmod.game.action.PawnPathAction
import gg.rsmod.game.model.attr.COMBAT_TARGET_FOCUS_ATTR
import gg.rsmod.game.model.attr.FACING_PAWN_ATTR
import gg.rsmod.game.model.timer.FROZEN_TIMER
import gg.rsmod.game.model.timer.STUN_TIMER
import gg.rsmod.plugins.content.combat.strategy.magic.CombatSpell

set_combat_logic {
Expand All @@ -21,7 +23,7 @@ suspend fun cycle(it: QueueTask): Boolean {
val target = pawn.attr[COMBAT_TARGET_FOCUS_ATTR]?.get()

if (target == null) {
pawn.facePawn(null)
pawn.resetFacePawn()
return false
}

Expand Down Expand Up @@ -51,6 +53,10 @@ suspend fun cycle(it: QueueTask): Boolean {

val pathFound = PawnPathAction.walkTo(it, pawn, target, interactionRange = attackRange, lineOfSight = false)

if (target != pawn.attr[FACING_PAWN_ATTR]?.get()) {
return false
}

if (!pathFound) {
pawn.stopMovement()
if (pawn.getType().isNpc()) {
Expand All @@ -60,14 +66,14 @@ suspend fun cycle(it: QueueTask): Boolean {
return true
}
if (pawn is Player) {
if (!pawn.timers.has(FROZEN_TIMER)) {
if (!pawn.timers.has(FROZEN_TIMER) || pawn.timers.has(STUN_TIMER)) {
pawn.message(Entity.YOU_CANT_REACH_THAT)
} else {
pawn.message(Entity.MAGIC_STOPS_YOU_FROM_MOVING)
}
pawn.clearMapFlag()
}
pawn.facePawn(null)
pawn.resetFacePawn()
Combat.reset(pawn)
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,24 @@ object MagicCombatStrategy : CombatStrategy {
}

private fun addCombatXp(player: Player, target: Pawn, damage: Int) {
val modDamage = if (target.getType().isNpc()) Math.min(target.getCurrentHp(), damage) else damage
val mode = CombatConfigs.getXpMode(player)
val multiplier = if (target is Npc) Combat.getNpcXpMultiplier(target) else 1.0

if (mode == XpMode.MAGIC) {
val defensive = player.getVarbit(Combat.SELECTED_AUTOCAST_VARBIT) != 0 && player.getVarbit(Combat.DEFENSIVE_MAGIC_CAST_VARBIT) != 0
if (!defensive) {
player.addXp(Skills.MAGIC, damage * 2.0 * multiplier)
player.addXp(Skills.HITPOINTS, damage * 1.33 * multiplier)
player.addXp(Skills.MAGIC, modDamage * 2.0 * multiplier)
player.addXp(Skills.HITPOINTS, modDamage * 1.33 * multiplier)
} else {
player.addXp(Skills.MAGIC, damage * 1.33 * multiplier)
player.addXp(Skills.DEFENCE, damage * multiplier)
player.addXp(Skills.HITPOINTS, damage * 1.33 * multiplier)
player.addXp(Skills.MAGIC, modDamage * 1.33 * multiplier)
player.addXp(Skills.DEFENCE, modDamage * multiplier)
player.addXp(Skills.HITPOINTS, modDamage * 1.33 * multiplier)
}
} else if (mode == XpMode.SHARED) {
player.addXp(Skills.MAGIC, damage * 1.33 * multiplier)
player.addXp(Skills.DEFENCE, damage * multiplier)
player.addXp(Skills.HITPOINTS, damage * 1.33 * multiplier)
player.addXp(Skills.MAGIC, modDamage * 1.33 * multiplier)
player.addXp(Skills.DEFENCE, modDamage * multiplier)
player.addXp(Skills.HITPOINTS, modDamage * 1.33 * multiplier)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,28 @@ object MeleeCombatStrategy : CombatStrategy {
}

private fun addCombatXp(player: Player, target: Pawn, damage: Int) {
val modDamage = if (target.getType().isNpc()) Math.min(target.getCurrentHp(), damage) else damage
val mode = CombatConfigs.getXpMode(player)
val multiplier = if (target is Npc) Combat.getNpcXpMultiplier(target) else 1.0

when (mode) {
XpMode.ATTACK -> {
player.addXp(Skills.ATTACK, damage * 4.0 * multiplier)
player.addXp(Skills.HITPOINTS, damage * 1.33 * multiplier)
player.addXp(Skills.ATTACK, modDamage * 4.0 * multiplier)
player.addXp(Skills.HITPOINTS, modDamage * 1.33 * multiplier)
}
XpMode.STRENGTH -> {
player.addXp(Skills.STRENGTH, damage * 4.0 * multiplier)
player.addXp(Skills.HITPOINTS, damage * 1.33 * multiplier)
player.addXp(Skills.STRENGTH, modDamage * 4.0 * multiplier)
player.addXp(Skills.HITPOINTS, modDamage * 1.33 * multiplier)
}
XpMode.DEFENCE -> {
player.addXp(Skills.DEFENCE, damage * 4.0 * multiplier)
player.addXp(Skills.HITPOINTS, damage * 1.33 * multiplier)
player.addXp(Skills.DEFENCE, modDamage * 4.0 * multiplier)
player.addXp(Skills.HITPOINTS, modDamage * 1.33 * multiplier)
}
XpMode.SHARED -> {
player.addXp(Skills.ATTACK, damage * 1.33 * multiplier)
player.addXp(Skills.STRENGTH, damage * 1.33 * multiplier)
player.addXp(Skills.DEFENCE, damage * 1.33 * multiplier)
player.addXp(Skills.HITPOINTS, damage * 1.33 * multiplier)
player.addXp(Skills.ATTACK, modDamage * 1.33 * multiplier)
player.addXp(Skills.STRENGTH, modDamage * 1.33 * multiplier)
player.addXp(Skills.DEFENCE, modDamage * 1.33 * multiplier)
player.addXp(Skills.HITPOINTS, modDamage * 1.33 * multiplier)
}
}
}
Expand Down
Loading

0 comments on commit 92621fc

Please sign in to comment.