-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Architecture Review: ComboMultiplier device (new type) #1324
Comments
Sounds like a good idea. I like it. The logic for when which counter increases seems to be complex. Is that a common thing? It looks like there is one counter per switch.
I guess you build the same with counters and timers but it seems like a common element so this makes sense to me.
Not much. It is a dict which is passed by reference so assembling the dict should be most of the cost.
Would be probably fine for most users. It might limit the number of switch hits on embedded/low-power devices such as the RPi Zero.
This would make it a core feature in MPF. Does it have to be that deeply integrated?
What about this: Instead of passing the combo value as argument you could also reference the device directly like this:
The syntax would become a bit more explicit but it would allow integration via events. It would even allow combos on non-switch events. Instead of Would that work? It would be totally decoupled and maybe even a bit more universal. What do you think? |
Thanks for the feedback @jabdoa2 ! I made many attempts to try and access the multiplier value through the device at the time of scoring, but there were two issues that I couldn't get past.
These two challenges led me to the belief that event args were the way to go, because those could be captured by the original switch at the time of the hit, and passed along to the shots, shot_groups, logic_blocks, and event_players that might end up triggering a variable_player event. Ideas? |
Understood. I guess we should use the event approach (option 1). Args overhead should not be high. Additionally, we could later add the same for non-switch hits in case someone wants this. |
Closing this issue because we now include |
I'm looking into replicating a scoring feature I've seen in the wild, and haven't found a good way to do it with native MPF functionality. The feature is a global per-shot multiplier that applies to any scoring awards triggered by that shot.
As seen in a number of recent Stern titles, each lane has a starting 1X multiplier. Hitting a lane increases the multiplier (some titles increase the hit lane, other titles increase all other lanes), up to a maximum amount of 5-8X. After a timeout, all lanes reset back to 1X. Any scoring triggered by a lane—whether a hurryup during a mode, collecting a mystery award, or building a jackpot value during multiball—any number awarded by a lane is multiplied by its multiplier.
Proposal: a ComboMultiplier device type
My thought would be to create a new device type that can configure an arbitrary number of (stackable) multipliers. In order for the multipliers to be universal, they would have to be attached to
Switches
instead ofShots
. My initial idea is that switches attached toComboMultipliers
would track their own current multiplier(s) and pass those in their active and inactive events.Shots
andShotGroups
that triggered hits from those switches would also pass the multiplier value(s) in the hit events.Example Config
In this scenario, when the
ComboMultiplier
device initializes it finds all of theSwitch
devices and attaches itself. The Switch has a public method to attach a combo multiplier, which causes the Switch to defineself.combo_multipliers = {}
(if None) and setsself.combo_multipliers[(combo_multiplier_name)]
to the default value.Option 1: Coordination via Events
ComboMultiplier tracking hits
The ComboMultiplier listens to the hit events of all its switches and when one is hit, it broadcasts a combo_multiplier_(name)_increment event with kwargs for each switch and its increment amount. The ComboMultiplier internally tracks the current and previous switches, so it can set increment values per-switch.
Switches increasing their multiplier
Switches that were attached to the ComboMultiplier are listening for the combo_multiplier_(name)_increment event, and look to see if their switch name is one of the kwargs. If so, the switch increases its internal
self.combo_multipliers[(name)]
value by the kwarg value.Option 2: Coordination via Callback
ComboMultiplier tracking hits
When the ComboMultiplier attaches itself to a Switch, it provides a callback method that the Switch stores. When the Switch's
self.hit()
event is called, the switch calls any ComboMultiplier callbacks it's attached to and passes itself as the argument. The ComboMultiplier tracks the identity of the hit Switch and increments accordingly.Switches increasing their multiplier
Switches have a public method to increment/reset their multiplier value for a given ComboMultiplier name. Each ComboMultiplier device has a list containing the instances of its Switches. When a hit occurs, the ComboMultiplier iterates through each Switch in the list and calls its increment method, passing the multiplier's name and the increment/reset value for that particular switch.
Example Event Sequence
reset_events
triggers a reset call. All Switches are set to thestarting_value
.s_left_orbit_active Args={ combo_multiplier_hyperdrive: 1.0 }
sh_orbit_hit Args={ combo_multiplier_hyperdrive: 1.0 }
combo_multiplier_hyperdrive
in the dynamic value.s_left_orbit
. It passes no increment to that switch, but passes an increment of 1.0 to all the other switches in its configuration.s_right_ramp_active Args={ combo_multiplier_hyperdrive: 2.0 }
sh_right_ramp_hit Args={ combo_multiplier_hyperdrive: 2.0 }
s_right_ramp
. It passes no increment to that switch. It passes a 0.5 increment tos_left_orbit
and a 1.0 increment to the other three switches.Questions
The text was updated successfully, but these errors were encountered: