Skip to content

Commit

Permalink
dbv5: smallEvent workout part 1 #2318
Browse files Browse the repository at this point in the history
  • Loading branch information
romain22222 committed Nov 27, 2023
1 parent 0a1e123 commit 2da5335
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/core/constants/SmallEventConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ export abstract class SmallEventConstants {

static readonly DEFAULT_FUNCTIONS = {
CAN_BE_EXECUTED: {
CONTINENT: (player: Player): boolean => Maps.isOnContinent(player)
onContinent: (player: Player): boolean => Maps.isOnContinent(player),
onPveIsland: (player: Player): boolean => Maps.isOnPveIsland(player)
}
};
}
38 changes: 20 additions & 18 deletions src/core/database/game/models/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,25 +717,27 @@ export class Player extends Model {
* @param response
*/
public async leavePVEIslandIfNoFightPoints(response: DraftBotPacket[]): Promise<boolean> {
if (Maps.isOnPveIsland(this) && this.fightPointsLost >= this.getMaxCumulativeFightPoint()) {
const {moneyLost, guildPointsLost} = await this.getAndApplyLostRessourcesOnPveFaint(response);
const packet: PlayerLeavePveIslandPacket = {
moneyLost,
guildPointsLost
};
response.push(packet);
await Maps.stopTravel(this);
await Maps.startTravel(
this,
MapLinkDataController.instance.getById(MapConstants.WATER_MAP_LINKS[RandomUtils.randInt(0, MapConstants.WATER_MAP_LINKS.length)]),
Date.now()
);
await TravelTime.applyEffect(this, EffectsConstants.EMOJI_TEXT.CONFOUNDED, 0, new Date(), NumberChangeReason.PVE_ISLAND);
await PlayerSmallEvents.removeSmallEventsOfPlayer(this.id);
return true;
if (!(Maps.isOnPveIsland(this) && this.fightPointsLost >= this.getMaxCumulativeFightPoint())) {
return false;
}

return false;
const {
moneyLost,
guildPointsLost
} = await this.getAndApplyLostRessourcesOnPveFaint(response);
const packet: PlayerLeavePveIslandPacket = {
moneyLost,
guildPointsLost
};
response.push(packet);
await Maps.stopTravel(this);
await Maps.startTravel(
this,
MapLinkDataController.instance.getById(MapConstants.WATER_MAP_LINKS[RandomUtils.randInt(0, MapConstants.WATER_MAP_LINKS.length)]),
Date.now()
);
await TravelTime.applyEffect(this, EffectsConstants.EMOJI_TEXT.CONFOUNDED, 0, new Date(), NumberChangeReason.PVE_ISLAND);
await PlayerSmallEvents.removeSmallEventsOfPlayer(this.id);
return true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/smallEvents/advanceTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {NumberChangeReason} from "../constants/LogsConstants";
import {SmallEventAdvanceTimePacket} from "../../../../Lib/src/packets/smallEvents/SmallEventAdvanceTimePacket";

export const smallEventFuncs: SmallEventFuncs = {
canBeExecuted: SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.CONTINENT,
canBeExecuted: SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.onContinent,
executeSmallEvent: async (response, player): Promise<void> => {
const timeAdvanced = RandomUtils.draftbotRandom.integer(10, 50);
await TravelTime.timeTravel(player, timeAdvanced, NumberChangeReason.SMALL_EVENT);
await player.save();
response.push(makePacket<SmallEventAdvanceTimePacket>({time: timeAdvanced}));
response.push(makePacket<SmallEventAdvanceTimePacket>({amount: timeAdvanced}));
}
};
2 changes: 1 addition & 1 deletion src/core/smallEvents/bigBad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type BigBadProperties = {
}

export const smallEventFuncs: SmallEventFuncs = {
canBeExecuted: SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.CONTINENT,
canBeExecuted: SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.onContinent,
executeSmallEvent: async (response, player): Promise<void> => {
const outRand = RandomUtils.draftbotRandom.integer(0, 2);
let lifeLoss, seFallen, moneyLoss;
Expand Down
2 changes: 1 addition & 1 deletion src/core/smallEvents/staffMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {makePacket} from "../../../../Lib/src/packets/DraftBotPacket";
import {SmallEventStaffMemberPacket} from "../../../../Lib/src/packets/smallEvents/SmallEventStaffMemberPacket";

export const smallEventFuncs: SmallEventFuncs = {
canBeExecuted: SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.CONTINENT,
canBeExecuted: SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.onContinent,
executeSmallEvent: (response): void => {
response.push(makePacket<SmallEventStaffMemberPacket>({}));
}
Expand Down
18 changes: 18 additions & 0 deletions src/core/smallEvents/winEnergy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {SmallEventFuncs} from "../../data/SmallEvent";
import {makePacket} from "../../../../Lib/src/packets/DraftBotPacket";
import {MapConstants} from "../constants/MapConstants";
import {NumberChangeReason} from "../constants/LogsConstants";
import {SmallEventWinEnergyPacket} from "../../../../Lib/src/packets/smallEvents/SmallEventWinEnergyPacket";

export const smallEventFuncs: SmallEventFuncs = {
canBeExecuted: (player) => {
const destinationId = player.getDestinationId();
const originId = player.getPreviousMapId();
return player.fightPointsLost > 0 && (destinationId === MapConstants.LOCATIONS_IDS.CLAIRE_DE_VILLE || originId === MapConstants.LOCATIONS_IDS.CLAIRE_DE_VILLE);
},
executeSmallEvent: async (response, player): Promise<void> => {
player.setFightPointsLost(0, NumberChangeReason.SMALL_EVENT);
await player.save();
response.push(makePacket<SmallEventWinEnergyPacket>({}));
}
};
20 changes: 20 additions & 0 deletions src/core/smallEvents/winFightPoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {SmallEventFuncs} from "../../data/SmallEvent";
import {SmallEventConstants} from "../constants/SmallEventConstants";
import {makePacket} from "../../../../Lib/src/packets/DraftBotPacket";
import {RandomUtils} from "../utils/RandomUtils";
import {PVEConstants} from "../constants/PVEConstants";
import {SmallEventWinFightPointsPacket} from "../../../../Lib/src/packets/smallEvents/SmallEventWinFightPointsPacket";

export const smallEventFuncs: SmallEventFuncs = {
canBeExecuted: (player) => SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.onPveIsland(player) && player.fightPointsLost > 0,
executeSmallEvent: async (response, player): Promise<void> => {
const maxFightPoints = player.getMaxCumulativeFightPoint();
const amount = RandomUtils.randInt(
Math.max(PVEConstants.FIGHT_POINTS_SMALL_EVENT.MIN_PERCENT * maxFightPoints, 1),
PVEConstants.FIGHT_POINTS_SMALL_EVENT.MAX_PERCENT * maxFightPoints
);
player.addFightPoints(amount, maxFightPoints);
await player.save();
response.push(makePacket<SmallEventWinFightPointsPacket>({amount}));
}
};
21 changes: 21 additions & 0 deletions src/core/smallEvents/winGuildXP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {SmallEventFuncs} from "../../data/SmallEvent";
import {SmallEventConstants} from "../constants/SmallEventConstants";
import {makePacket} from "../../../../Lib/src/packets/DraftBotPacket";
import {RandomUtils} from "../utils/RandomUtils";
import {Guilds} from "../database/game/models/Guild";
import {NumberChangeReason} from "../constants/LogsConstants";
import {SmallEventWinGuildXPPacket} from "../../../../Lib/src/packets/smallEvents/SmallEventWinGuildXPPacket";

export const smallEventFuncs: SmallEventFuncs = {
canBeExecuted: (player) => SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.onContinent(player) && player.hasAGuild(),
executeSmallEvent: async (response, player): Promise<void> => {
const guild = await Guilds.getById(player.guildId);
const xpWon = RandomUtils.draftbotRandom.integer(
SmallEventConstants.GUILD_EXPERIENCE.MIN + guild.level,
SmallEventConstants.GUILD_EXPERIENCE.MAX + guild.level * 2
);
await guild.addExperience(xpWon, response, NumberChangeReason.SMALL_EVENT);
await guild.save();
response.push(makePacket<SmallEventWinGuildXPPacket>({amount: xpWon}));
}
};
16 changes: 16 additions & 0 deletions src/core/smallEvents/winHealth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {SmallEventFuncs} from "../../data/SmallEvent";
import {SmallEventConstants} from "../constants/SmallEventConstants";
import {makePacket} from "../../../../Lib/src/packets/DraftBotPacket";
import {RandomUtils} from "../utils/RandomUtils";
import {NumberChangeReason} from "../constants/LogsConstants";
import {SmallEventWinHealthPacket} from "../../../../Lib/src/packets/smallEvents/SmallEventWinHealthPacket";

export const smallEventFuncs: SmallEventFuncs = {
canBeExecuted: SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.onContinent,
executeSmallEvent: async (response, player): Promise<void> => {
const healthWon = RandomUtils.rangedInt(SmallEventConstants.HEALTH);
await player.addHealth(healthWon, response, NumberChangeReason.SMALL_EVENT);
await player.save();
response.push(makePacket<SmallEventWinHealthPacket>({amount: healthWon}));
}
};
20 changes: 20 additions & 0 deletions src/core/smallEvents/winPersonnalXP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {SmallEventFuncs} from "../../data/SmallEvent";
import {SmallEventConstants} from "../constants/SmallEventConstants";
import {makePacket} from "../../../../Lib/src/packets/DraftBotPacket";
import {RandomUtils} from "../utils/RandomUtils";
import {NumberChangeReason} from "../constants/LogsConstants";
import {SmallEventWinPersonnalXPPacket} from "../../../../Lib/src/packets/smallEvents/SmallEventWinPersonnalXPPacket";

export const smallEventFuncs: SmallEventFuncs = {
canBeExecuted: SmallEventConstants.DEFAULT_FUNCTIONS.CAN_BE_EXECUTED.onContinent,
executeSmallEvent: async (response, player): Promise<void> => {
const xpWon = RandomUtils.rangedInt(SmallEventConstants.EXPERIENCE);
await player.addExperience({
amount: xpWon,
response,
reason: NumberChangeReason.SMALL_EVENT
});
await player.save();
response.push(makePacket<SmallEventWinPersonnalXPPacket>({amount: xpWon}));
}
};

0 comments on commit 2da5335

Please sign in to comment.