Skip to content

Commit

Permalink
Merge pull request #111 from mgovea/multiplayer
Browse files Browse the repository at this point in the history
Update ride prices via Game Action, hopefully adding MP support
  • Loading branch information
mgovea committed Mar 30, 2021
2 parents 437e9a5 + 365a5de commit b8c9497
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 69 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@
"code": 120
}
],
"no-shadow": "off",
"@typescript-eslint/no-shadow": [
"error"
],
"no-undef": 0,
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error"
],
"no-use-before-define": [
"error",
"nofunc"
Expand Down
145 changes: 84 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rollup.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ export default {
plugins: [
typescript(),
terser({
compress: false,
format: {
beautify: true,
quote_style: 1,
wrap_iife: true,
preamble: '// Mod powered by https://github.com/wisnia74/openrct2-typescript-mod-template - MIT license',
},
mangle: false,
}),
],
};
23 changes: 15 additions & 8 deletions src/ridePriceFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ function forceUpdateRidePrices(): void {

function makeRidesFree(): void {
map.rides.map((ride: Ride) => { // eslint-disable-line array-callback-return
// The API doesn't detect deep changes, so we need a new array.
const ridePrices = ride.price.slice(0);
ridePrices[0] = 0;
ride.price = ridePrices; // eslint-disable-line no-param-reassign
setRidePrice(ride, 0);
});
}

Expand Down Expand Up @@ -62,10 +59,20 @@ function updateRidePrice(ride: Ride): void {
priceInDimes = Math.min(priceInDimes, 200);
}

// The API doesn't detect deep changes, so we need a new array.
const ridePrices = ride.price.slice(0);
ridePrices[0] = priceInDimes;
ride.price = ridePrices; // eslint-disable-line no-param-reassign
setRidePrice(ride, priceInDimes);
}

function setRidePrice(ride: Ride, priceInDimes: number): void {
// Set the price via an action (so it works in multiplayer)
context.executeAction(
'ridesetprice',
{
ride: ride.id,
price: priceInDimes,
isPrimaryPrice: true,
},
() => { },
);
}

export {
Expand Down

0 comments on commit b8c9497

Please sign in to comment.