diff --git a/src/core/constants/SmallEventConstants.ts b/src/core/constants/SmallEventConstants.ts index fe56d649a..2c1215287 100644 --- a/src/core/constants/SmallEventConstants.ts +++ b/src/core/constants/SmallEventConstants.ts @@ -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) } }; } \ No newline at end of file diff --git a/src/core/database/game/models/Player.ts b/src/core/database/game/models/Player.ts index 50c7ffca4..5846a3217 100644 --- a/src/core/database/game/models/Player.ts +++ b/src/core/database/game/models/Player.ts @@ -717,25 +717,27 @@ export class Player extends Model { * @param response */ public async leavePVEIslandIfNoFightPoints(response: DraftBotPacket[]): Promise { - 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; } /** diff --git a/src/core/smallEvents/advanceTime.ts b/src/core/smallEvents/advanceTime.ts index 714d8a055..4478f5f61 100644 --- a/src/core/smallEvents/advanceTime.ts +++ b/src/core/smallEvents/advanceTime.ts @@ -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 => { const timeAdvanced = RandomUtils.draftbotRandom.integer(10, 50); await TravelTime.timeTravel(player, timeAdvanced, NumberChangeReason.SMALL_EVENT); await player.save(); - response.push(makePacket({time: timeAdvanced})); + response.push(makePacket({amount: timeAdvanced})); } }; \ No newline at end of file diff --git a/src/core/smallEvents/bigBad.ts b/src/core/smallEvents/bigBad.ts index e8c74e6a0..97bd52785 100644 --- a/src/core/smallEvents/bigBad.ts +++ b/src/core/smallEvents/bigBad.ts @@ -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 => { const outRand = RandomUtils.draftbotRandom.integer(0, 2); let lifeLoss, seFallen, moneyLoss; diff --git a/src/core/smallEvents/staffMember.ts b/src/core/smallEvents/staffMember.ts index 23aa70bbd..989ea06f6 100644 --- a/src/core/smallEvents/staffMember.ts +++ b/src/core/smallEvents/staffMember.ts @@ -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({})); } diff --git a/src/core/smallEvents/winEnergy.ts b/src/core/smallEvents/winEnergy.ts new file mode 100644 index 000000000..b24a6071f --- /dev/null +++ b/src/core/smallEvents/winEnergy.ts @@ -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 => { + player.setFightPointsLost(0, NumberChangeReason.SMALL_EVENT); + await player.save(); + response.push(makePacket({})); + } +}; \ No newline at end of file diff --git a/src/core/smallEvents/winFightPoints.ts b/src/core/smallEvents/winFightPoints.ts new file mode 100644 index 000000000..1f638ee4e --- /dev/null +++ b/src/core/smallEvents/winFightPoints.ts @@ -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 => { + 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({amount})); + } +}; \ No newline at end of file diff --git a/src/core/smallEvents/winGuildXP.ts b/src/core/smallEvents/winGuildXP.ts new file mode 100644 index 000000000..4af496bb0 --- /dev/null +++ b/src/core/smallEvents/winGuildXP.ts @@ -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 => { + 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({amount: xpWon})); + } +}; \ No newline at end of file diff --git a/src/core/smallEvents/winHealth.ts b/src/core/smallEvents/winHealth.ts new file mode 100644 index 000000000..0f85a234a --- /dev/null +++ b/src/core/smallEvents/winHealth.ts @@ -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 => { + const healthWon = RandomUtils.rangedInt(SmallEventConstants.HEALTH); + await player.addHealth(healthWon, response, NumberChangeReason.SMALL_EVENT); + await player.save(); + response.push(makePacket({amount: healthWon})); + } +}; \ No newline at end of file diff --git a/src/core/smallEvents/winPersonnalXP.ts b/src/core/smallEvents/winPersonnalXP.ts new file mode 100644 index 000000000..fa8f99e5c --- /dev/null +++ b/src/core/smallEvents/winPersonnalXP.ts @@ -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 => { + const xpWon = RandomUtils.rangedInt(SmallEventConstants.EXPERIENCE); + await player.addExperience({ + amount: xpWon, + response, + reason: NumberChangeReason.SMALL_EVENT + }); + await player.save(); + response.push(makePacket({amount: xpWon})); + } +}; \ No newline at end of file