Skip to content

Commit

Permalink
Merge pull request #176 from Promises/woodcutting
Browse files Browse the repository at this point in the history
Better formula for woodcutting and mining
  • Loading branch information
TheBlackParade authored Jun 13, 2020
2 parents ab72d0e + 579815f commit f55245e
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 288 deletions.
13 changes: 13 additions & 0 deletions src/plugins/commands/bank-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ActionType, RunePlugin } from '@server/plugins/plugin';
import { commandAction } from '@server/world/actor/player/action/input-command-action';
import { openBankInterface } from '@server/plugins/objects/bank/bank-plugin';

const action: commandAction = (details) => {
openBankInterface(details as any);
};

export default new RunePlugin({
type: ActionType.COMMAND,
commands: [ 'bank' ],
action
});
95 changes: 49 additions & 46 deletions src/world/actor/skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ export interface SkillDetail {
}

export const skillDetails: SkillDetail[] = [
{ name: 'Attack', advancementWidgetId: 158 },
{ name: 'Defence', advancementWidgetId: 161 },
{ name: 'Strength', advancementWidgetId: 175 },
{ name: 'Hitpoints', advancementWidgetId: 167 },
{ name: 'Ranged', advancementWidgetId: 171 },
{ name: 'Prayer', advancementWidgetId: 170 },
{ name: 'Magic', advancementWidgetId: 168 },
{ name: 'Cooking', advancementWidgetId: 159 },
{ name: 'Woodcutting', advancementWidgetId: 177 },
{ name: 'Fletching', advancementWidgetId: 165 },
{ name: 'Fishing', advancementWidgetId: 164 },
{ name: 'Firemaking', advancementWidgetId: 163 },
{ name: 'Crafting', advancementWidgetId: 160 },
{ name: 'Smithing', advancementWidgetId: 174 },
{ name: 'Mining', advancementWidgetId: 169 },
{ name: 'Herblore', advancementWidgetId: 166 },
{ name: 'Agility', advancementWidgetId: 157 },
{ name: 'Thieving', advancementWidgetId: 176 },
{ name: 'Slayer', advancementWidgetId: 173 },
{ name: 'Farming', advancementWidgetId: 162 },
{ name: 'Runecrafting', advancementWidgetId: 172 },
{name: 'Attack', advancementWidgetId: 158},
{name: 'Defence', advancementWidgetId: 161},
{name: 'Strength', advancementWidgetId: 175},
{name: 'Hitpoints', advancementWidgetId: 167},
{name: 'Ranged', advancementWidgetId: 171},
{name: 'Prayer', advancementWidgetId: 170},
{name: 'Magic', advancementWidgetId: 168},
{name: 'Cooking', advancementWidgetId: 159},
{name: 'Woodcutting', advancementWidgetId: 177},
{name: 'Fletching', advancementWidgetId: 165},
{name: 'Fishing', advancementWidgetId: 164},
{name: 'Firemaking', advancementWidgetId: 163},
{name: 'Crafting', advancementWidgetId: 160},
{name: 'Smithing', advancementWidgetId: 174},
{name: 'Mining', advancementWidgetId: 169},
{name: 'Herblore', advancementWidgetId: 166},
{name: 'Agility', advancementWidgetId: 157},
{name: 'Thieving', advancementWidgetId: 176},
{name: 'Slayer', advancementWidgetId: 173},
{name: 'Farming', advancementWidgetId: 162},
{name: 'Runecrafting', advancementWidgetId: 172},
null,
{ name: 'Construction' }
{name: 'Construction'}
];

export interface SkillValue {
Expand Down Expand Up @@ -135,7 +135,7 @@ export class Skills extends SkillShortcuts {
this[skillName] = new SkillShortcut(this, skillName as SkillName)
);

if(values) {
if (values) {
this._values = values;
} else {
this._values = this.defaultValues();
Expand All @@ -148,18 +148,17 @@ export class Skills extends SkillShortcuts {
}

public hasLevel(skill: number | SkillName, level: number, ignoreLevelModifications: boolean = false): boolean {
const s = this.get(skill);
return (ignoreLevelModifications ? s.level : s.modifiedLevel) >= level;
return this.getLevel(skill, ignoreLevelModifications) >= level;
}

public getLevelForExp(exp: number): number {
let points = 0;
let output = 0;

for(let i = 1; i <= 99; i++) {
for (let i = 1; i <= 99; i++) {
points += Math.floor(i + 300 * Math.pow(2, i / 7));
output = Math.floor(points / 4);
if(output >= exp) {
if (output >= exp) {
return i;
}
}
Expand All @@ -171,44 +170,44 @@ export class Skills extends SkillShortcuts {
const currentExp = this.get(skill).exp;
const currentLevel = this.getLevelForExp(currentExp);
let finalExp = currentExp + (exp * serverConfig.expRate);
if(finalExp > 200000000) {
if (finalExp > 200000000) {
finalExp = 200000000;
}

const finalLevel = this.getLevelForExp(finalExp);

this.setExp(skill, finalExp);

if(this.actor instanceof Player) {
if (this.actor instanceof Player) {
this.actor.outgoingPackets.updateSkill(this.getSkillId(skill), finalLevel, finalExp);
}

if(currentLevel !== finalLevel) {
if (currentLevel !== finalLevel) {
this.setLevel(skill, finalLevel);

if(this.actor instanceof Player) {
if (this.actor instanceof Player) {
const achievementDetails = skillDetails[this.getSkillId(skill)];
if(!achievementDetails) {
if (!achievementDetails) {
return;
}

this.actor.sendMessage(`Congratulations, you just advanced a ` +
`${ achievementDetails.name.toLowerCase() } level.`);
`${achievementDetails.name.toLowerCase()} level.`);
this.showLevelUpDialogue(skill, finalLevel);
}
}
}

public showLevelUpDialogue(skill: number | SkillName, level: number): void {
if(!(this.actor instanceof Player)) {
if (!(this.actor instanceof Player)) {
return;
}

const player = this.actor as Player;
const achievementDetails = skillDetails[this.getSkillId(skill)];
const widgetId = achievementDetails.advancementWidgetId;

if(!widgetId) {
if (!widgetId) {
return;
}

Expand All @@ -219,21 +218,25 @@ export class Skills extends SkillShortcuts {
type: 'CHAT',
closeOnWalk: true,
beforeOpened: () => {
player.modifyWidget(widgetId, { childId: 0,
text: `<col=000080>Congratulations, you just advanced ${ startsWithVowel(skillName) ? 'an' : 'a' } ` +
`${ skillName } level.</col>` });
player.modifyWidget(widgetId, { childId: 1,
text: `Your ${skillName} level is now ${ level }.` });
player.modifyWidget(widgetId, {
childId: 0,
text: `<col=000080>Congratulations, you just advanced ${startsWithVowel(skillName) ? 'an' : 'a'} ` +
`${skillName} level.</col>`
});
player.modifyWidget(widgetId, {
childId: 1,
text: `Your ${skillName} level is now ${level}.`
});
},
afterOpened: () => {
player.playGraphics({ id: gfxIds.levelUpFireworks, delay: 0, height: 125 });
player.playGraphics({id: gfxIds.levelUpFireworks, delay: 0, height: 125});
// @TODO sounds
}
});
}

public getSkillId(skill: number | SkillName) : number {
if(typeof skill === 'number') {
public getSkillId(skill: number | SkillName): number {
if (typeof skill === 'number') {
return skill;
} else {
const skillName = skill.toString().toUpperCase();
Expand All @@ -242,7 +245,7 @@ export class Skills extends SkillShortcuts {
}

public get(skill: number | SkillName): SkillValue {
if(typeof skill === 'number') {
if (typeof skill === 'number') {
return this._values[skill];
} else {
const skillName = skill.toString().toUpperCase();
Expand All @@ -252,8 +255,8 @@ export class Skills extends SkillShortcuts {

private defaultValues(): SkillValue[] {
const values: SkillValue[] = [];
skillDetails.forEach(s => values.push({ exp: 0, level: 1 }));
values[Skill.HITPOINTS] = { exp: 1154, level: 10 };
skillDetails.forEach(s => values.push({exp: 0, level: 1}));
values[Skill.HITPOINTS] = {exp: 1154, level: 10};
return values;
}

Expand Down
28 changes: 13 additions & 15 deletions src/world/config/harvest-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export interface HarvestTool {
itemId: number;
level: number;
animation: number;
pulses: number;
modifier: number;
}


Expand All @@ -31,23 +29,23 @@ export enum Axe {


const Pickaxes: HarvestTool[] = [
{itemId: 1265, level: 1, animation: 625, pulses: 8, modifier: 0},
{itemId: 1267, level: 1, animation: 626, pulses: 7, modifier: 0},
{itemId: 1269, level: 6, animation: 627, pulses: 6, modifier: 0},
{itemId: 1273, level: 21, animation: 629, pulses: 5, modifier: 0},
{itemId: 1271, level: 31, animation: 628, pulses: 4, modifier: 0},
{itemId: 1275, level: 41, animation: 624, pulses: 3, modifier: 0}
{itemId: 1265, level: 1, animation: 625},
{itemId: 1267, level: 1, animation: 626},
{itemId: 1269, level: 6, animation: 627},
{itemId: 1273, level: 21, animation: 629},
{itemId: 1271, level: 31, animation: 628},
{itemId: 1275, level: 41, animation: 624}
];


const Axes: HarvestTool[] = [
{itemId: 1351, level: 1, animation: 879, pulses: 8, modifier: 0},
{itemId: 1349, level: 1, animation: 877, pulses: 7, modifier: 0},
{itemId: 1353, level: 6, animation: 875, pulses: 6, modifier: 0},
{itemId: 1355, level: 21, animation: 871, pulses: 5, modifier: 0},
{itemId: 1357, level: 31, animation: 869, pulses: 4, modifier: 0},
{itemId: 1359, level: 41, animation: 867, pulses: 3, modifier: 0},
{itemId: 6739, level: 61, animation: 2846, pulses: 3, modifier: 10}
{itemId: 1351, level: 1, animation: 879},
{itemId: 1349, level: 1, animation: 877},
{itemId: 1353, level: 6, animation: 875},
{itemId: 1355, level: 21, animation: 871},
{itemId: 1357, level: 31, animation: 869},
{itemId: 1359, level: 41, animation: 867},
{itemId: 6739, level: 61, animation: 2846}
];

/**
Expand Down
Loading

0 comments on commit f55245e

Please sign in to comment.