finished incorporating messaging into the UI window and added another custom control to make updating the UI easier

This commit is contained in:
James Daly
2019-06-14 22:15:58 -04:00
parent 0b52e91a3d
commit 38dbb7fa92
13 changed files with 131 additions and 193 deletions

View File

@@ -61,8 +61,11 @@ object Ability {
private val helper = """
implicit val gen = rng
implicit val signalConsumer = reader
def msg(text: String): Unit = {
reader ! Message(text)
}
def trigger {
reader ! Message(s"[${mon}'s ${self}]")
msg(s"[${mon}'s ${self}]")
}
def effect = EffectSource(mon, self)
"""

View File

@@ -41,7 +41,7 @@ class Monster(val base : StorageMon) {
def statuses = volatile ++ status
def cureStatus() {
def cureStatus()(implicit reader: SignalConsumer, rng: Random) {
status.map(_.onEnd(this))
status = None
}
@@ -54,11 +54,11 @@ class Monster(val base : StorageMon) {
status = Some(s)
s.onStart(this, source)
} else {
println("But it failed!")
reader ! Message("But it failed!")
}
}
def -=(s : Status) = {
def -=(s : Status)(implicit reader: SignalConsumer, rng: Random) = {
if (s.effectType == EffectType.Volatile) {
s.onEnd(this)
volatile = volatile.filterNot(_.name == s.name)
@@ -67,13 +67,13 @@ class Monster(val base : StorageMon) {
}
}
def applyBoost(s : Stat, boost : Int, effect: EffectSource) {
def applyBoost(s : Stat, boost : Int, effect: EffectSource)(implicit reader: SignalConsumer, rng: Random) {
val modified = boosts.getOrElse(s, 0) + boost
boosts = boosts.updated(s, Math.min(MaxBoost, Math.max(-MaxBoost, modified)))
if (boost > 0) {
println(s"$this's $s rose!")
reader ! Message(s"$this's $s rose!")
} else if (boost < 0) {
println(s"$this's $s fell!")
reader ! Message(s"$this's $s fell!")
}
}

View File

@@ -174,7 +174,7 @@ abstract class Move extends MoveTurn {
}
}
def applyBoosts(target: Monster, boosts: Map[Stat, Int], source: Monster) {
def applyBoosts(target: Monster, boosts: Map[Stat, Int], source: Monster)(implicit read: SignalConsumer, rng: Random) {
if (target.isAlive) {
boosts.foreach {
case (s, b) => {

View File

@@ -19,7 +19,7 @@ object EffectType extends Enumeration {
case "ability" => AbilityEffect
case "item" => ItemEffect
case "move" => MoveEffect
case "status" => NonVolatile
case "status" | "Status" | "nonvolatile" => NonVolatile
case "volatile" => Volatile
case "weather" => Weather
case _ => default
@@ -49,14 +49,14 @@ class Status(template: StatusTemplate) extends Effect {
// val id
def effectType = template.effectType
def onStart(mon: Monster, source: EffectSource)(implicit reader: SignalConsumer, rng: Random) = template.onStart(this, mon, source, reader, rng)
def onEnd(mon: Monster) = template.onEnd(this, mon)
def onEnd(mon: Monster)(implicit reader: SignalConsumer, rng: Random) = template.onEnd(this, mon, reader, rng)
def onModifyStat(mon: Monster, stat: Stat) = template.onModifyStat(this, mon, stat)
// val onBeforeMovePriority : Int
def onBeforeMove(mon: Monster, move: MoveTurn, target: Monster)(implicit reader: SignalConsumer, rng: Random) = template.onBeforeMove(this, mon, move, target, reader, rng)
// val onModifyMove
// val onHit
def onResidualOrder = template.onResidualOrder
def onResidual(mon: Monster) = template.onResidual(this, mon)
def onResidual(mon: Monster)(implicit reader: SignalConsumer, rng: Random) = template.onResidual(this, mon, reader, rng)
// val onSwitchIn
val intData: MutMap[String, Int] = MutMap[String, Int]()
@@ -70,14 +70,14 @@ abstract class StatusTemplate {
// val id
val effectType: EffectType
val onStart: (Status, Monster, EffectSource, SignalConsumer, Random) => Unit
val onEnd: (Status, Monster) => Unit
val onEnd: (Status, Monster, SignalConsumer, Random) => Unit
val onModifyStat: (Status, Monster, Stat) => Fraction
// val onBeforeMovePriority : Int
val onBeforeMove: (Status, Monster, MoveTurn, Monster, SignalConsumer, Random) => Boolean
// val onModifyMove
// val onHit
val onResidualOrder: Int
val onResidual: (Status, Monster) => Unit
val onResidual: (Status, Monster, SignalConsumer, Random) => Unit
// val onSwitchIn
def build = new Status(this)
@@ -135,7 +135,7 @@ object Status {
}
"""
def compileOnStart(code: String): (Status, Monster, EffectSource, SignalConsumer, Random ) => Unit = {
def compileOnStart(code: String): (Status, Monster, EffectSource, SignalConsumer, Random) => Unit = {
if (code == null) {
(_, _, _, _, _) => ()
} else {
@@ -154,21 +154,22 @@ object Status {
}
}
def compileOnEnd(code: String): (Status, Monster) => Unit = {
def compileOnEnd(code: String): (Status, Monster, SignalConsumer, Random) => Unit = {
if (code == null) {
(_, _) => ()
(_, _, _, _) => ()
} else {
val tree = tb.parse(
s"""
|$header
|def onStart(self:Status, mon: Monster) = {
|def onStart(self:Status, mon: Monster, reader: SignalConsumer, rng: Random) = {
| $helpers
| $code
|}
onStart _
""".stripMargin)
val f = tb.compile(tree)
val wrapper = f()
wrapper.asInstanceOf[(Status, Monster) => Unit]
wrapper.asInstanceOf[(Status, Monster, SignalConsumer, Random) => Unit]
}
}
@@ -210,14 +211,15 @@ object Status {
}
}
def compileOnResidual(code: String): (Status, Monster) => Unit = {
def compileOnResidual(code: String): (Status, Monster, SignalConsumer, Random) => Unit = {
if (code == null) {
(_, _) => ()
(_, _, _, _) => ()
} else {
val tree = tb.parse(
s"""
|$header
|def onResidual(self: Status, mon: Monster) = {
|def onResidual(self: Status, mon: Monster, reader: SignalConsumer, rng: Random) = {
| $helpers
| $code
|}
|onResidual _
@@ -225,7 +227,7 @@ object Status {
val f = tb.compile(tree)
val wrapper = f()
wrapper.asInstanceOf[(Status, Monster) => Unit]
wrapper.asInstanceOf[(Status, Monster, SignalConsumer, Random) => Unit]
}
}
}

View File

@@ -16,7 +16,7 @@ aftermath:
onAfterDamage: |-
if ((source != null) && (source != mon) && (move != null) && move.flags("contact") && !mon.isAlive) {
trigger
println(s"$source is damaged in the aftermath!")
msg(s"$source is damaged in the aftermath!")
source.takeDamage(source(Hp) / 4);
}
onAfterDamageOrder: 1
@@ -31,6 +31,7 @@ flamebody:
onAfterDamage: |-
if (move != null && move.flags("contact")) {
if (rng.chance(3, 10)) {
trigger
source.addStatus(Status("brn"), EffectSource(mon, self))
}
}
@@ -59,7 +60,7 @@ innardsout:
onAfterDamage: |-
if (source != null && source != mon && move != null /* && move.effectType === 'Move'*/ && !mon.isAlive) {
trigger
println(s"$source is damaged in the aftermath!")
msg(s"$source is damaged in the aftermath!")
source.takeDamage(damage)//, source, target);
}
onAfterDamageOrder: 1
@@ -76,7 +77,7 @@ ironbarbs:
onAfterDamage: |-
if (source != null && source != mon && move != null && move.flags("contact")) {
trigger
println(s"Pointed barbs dug into $source!")
msg(s"Pointed barbs dug into $source!")
source.takeDamage(source(Hp) / 8)//, source, target)
}
onAfterDamageOrder: 1
@@ -90,6 +91,7 @@ poisonpoint:
onAfterDamage: |-
if (move != null && move.flags("contact")) {
if (rng.chance(3, 10)) {
trigger
source.addStatus(Status("psn"), EffectSource(mon, self))
}
}
@@ -105,7 +107,7 @@ roughskin:
onAfterDamage: |-
if (source != null && source != mon && move != null && move.flags("contact")) {
trigger
println(s"$source is damaged by rough skin!")
msg(s"$source is damaged by rough skin!")
source.takeDamage(source(Hp) / 8)//, source, target)
}
onAfterDamageOrder: 1
@@ -131,6 +133,7 @@ static:
onAfterDamage: |-
if (move != null && move.flags("contact")) {
if (rng.chance(3, 10)) {
trigger
source.addStatus(Status("par"), EffectSource(mon, self))
}
}
@@ -143,10 +146,8 @@ tanglinghair:
num: 221
onAfterDamage: |-
if (move != null && move.flags("contact")) {
//this.add('-ability', target, 'Tangling Hair');
trigger
source.applyBoost(Speed, -1, effect)
//this.boost({'spe': -1}, source, target, null, true);
}
rating: 2.5
shortDesc: Pokemon making contact with this Pokemon have their Speed lowered by
@@ -160,10 +161,8 @@ weakarmor:
num: 133
onAfterDamage: |-
if (move.category == Physical) {
//this.boost({'def': -1, 'spe': 2}, target, target);
trigger
mon.applyBoost(PDef, -1)
trigger
mon.applyBoost(Speed, +2)
}
rating: 1

View File

@@ -10,24 +10,13 @@ brn:
1.frac
}
onStart: |
if (!source.isMove) {
print(s"[${source.mon}'s ${source.effect}]")
}
msg(s"${mon} was burned!")
/*
if (sourceEffect && sourceEffect.id === 'flameorb') {
target.status = Status('brn', '[from] 'item': Flame Orb');
} else if (sourceEffect && sourceEffect.effectType === 'Ability') {
target.status = Status('brn', '[from] 'ability': ' + sourceEffect.name, '[of] ' + source);
} else {
target.status = Status('brn');
}*/
onEnd: |
println(s"${mon} was healed of its burn.")
msg(s"${mon} was healed of its burn.")
onResidualOrder: 9
onResidual: |
mon.takeDamage(mon(Hp) / 16);
println(s"${mon} was hurt by its burn!")
msg(s"${mon} was hurt by its burn!")
confusion:
id: confusion
@@ -39,7 +28,7 @@ confusion:
mon -= self
true
} else {
println(s"${mon} is confused!")
msg(s"${mon} is confused!")
if (rng.chance(1, 3)) {
// confusion damage
val maxDmg = (2 * mon.level / 5 + 2) * 40 * mon(PAtk) / (mon(PDef) * 50) + 2
@@ -63,15 +52,9 @@ confusion:
}));
*/
onBeforeMovePriority: 3
onEnd: println(s"${mon} snapped out of its confusion.")
onEnd: msg(s"${mon} snapped out of its confusion.")
onStart: |-
msg(s"${mon} was confused!")
/*
if (sourceEffect && sourceEffect.id === 'lockedmove') {
this.add('-start', target, 'confusion', '[fatigue]');
} else {
this.add('-start', target, 'confusion');
}*/
self.intData("time") = rng.nextInt(2, 6);
par:
@@ -80,19 +63,9 @@ par:
num: 0
effectType: 'Status'
onStart: |
if (!source.isMove) {
print(s"[${source.mon}'s ${source.effect}]")
}
println(s"${mon} was paralyzed!")
/*
if (sourceEffect && sourceEffect.effectType === 'Ability') {
this.add('-status', target, 'par', '[from] ability: ' + sourceEffect.name, '[of] ' + source);
} else {
this.add('-status', target, 'par');
}
*/
msg(s"${mon} was paralyzed!")
onEnd: |
println(s"${mon} is no longer paralyzed!")
msg(s"${mon} is no longer paralyzed!")
onModifyStat: |
if (stat == Speed /* && !mon.hasAbility('quickfeet') */) {
1 \\ 2
@@ -114,21 +87,12 @@ slp:
num: 0
effectType: 'Status'
onStart: |
println(s"${mon} fell asleep!")
/*
if (sourceEffect && sourceEffect.effectType === 'Ability') {
this.add('-status', target, 'slp', '[from] ability: ' + sourceEffect.name, '[of] ' + source);
} else if (sourceEffect && sourceEffect.effectType === 'Move') {
this.add('-status', target, 'slp', '[from] move: ' + sourceEffect.name);
} else {
this.add('-status', target, 'slp');
}
*/
msg(s"${mon} fell asleep!")
// 1-3 turns
self.intData("startTime") = rng.nextInt(2, 5)
self.intData("time") = self.intData("startTime")
onEnd: |
println(s"${mon} woke up!")
msg(s"${mon} woke up!")
onBeforeMovePriority: 10
onBeforeMove: |
/*
@@ -141,7 +105,7 @@ slp:
mon.cureStatus();
true
} else {
println(s"${mon} is fast asleep.")
msg(s"${mon} is fast asleep.")
!move.flags("sleepUsable")
}
@@ -151,7 +115,7 @@ flinch:
name: flinch
num: 0
onBeforeMove: |-
println(s"${mon} flinched!")
msg(s"${mon} flinched!")
false
onBeforeMovePriority: 8
onResidualOrder: 13
@@ -168,7 +132,7 @@ frz:
mon.cureStatus()
true
} else {
println(s"${mon} is completely frozen!")
msg(s"${mon} is completely frozen!")
false
}
onBeforeMovePriority: 10
@@ -177,19 +141,9 @@ frz:
target.cureStatus()
}
onStart: |-
println(s"${mon} was frozen solid!")
/*
if (sourceEffect && sourceEffect.effectType === 'Ability') {
target.status = Status('frz', '[from] 'ability': ' + sourceEffect.name, '[of] ' + source);
} else {
target.status = Status('frz');
}
if (target.template.species === 'Shaymin-Sky' && target.baseTemplate.baseSpecies === 'Shaymin') {
target.formeChange('Shaymin', this.effect, true);
}
*/
msg(s"${mon} was frozen solid!")
onEnd: |-
println(s"${mon} thawed out.")
msg(s"${mon} thawed out.")
onModifyMove: |
if (move.flags("defrost")) {
mon.cureStatus()
@@ -201,20 +155,13 @@ psn:
num: 0
effectType: 'Status'
onStart: |
println(s"${mon} was poisoned!")
/*
if (sourceEffect && sourceEffect.effectType === 'Ability') {
this.add('-status', target, 'psn', '[from] ability: ' + sourceEffect.name, '[of] ' + source);
} else {
this.add('-status', target, 'psn');
}
*/
msg(s"${mon} was poisoned!")
oneEnd: |
println(s"${mon} was cured of its poison.")
msg(s"${mon} was cured of its poison.")
onResidualOrder: 9
onResidual: |
mon.takeDamage(mon(Hp) / 8);
println(s"${mon} was damaged by poison!")
msg(s"${mon} was damaged by poison!")
tox:
name: 'tox'
@@ -222,16 +169,8 @@ tox:
num: 0
effectType: 'Status'
onStart: |
println(s"${mon} was baddly poisoned!")
msg(s"${mon} was baddly poisoned!")
self.intData("stage") = 0;
/*
if (sourceEffect && sourceEffect.id === 'toxicorb') {
this.add('-status', target, 'tox', '[from] item: Toxic Orb');
} else if (sourceEffect && sourceEffect.effectType === 'Ability') {
this.add('-status', target, 'tox', '[from] ability: ' + sourceEffect.name, '[of] ' + source);
} else {
this.add('-status', target, 'tox');
}*/
onSwitchIn: |
this.effectData.stage = 0;
onResidualOrder: 9
@@ -240,4 +179,4 @@ tox:
self.intData("stage") += 1
}
mon.takeDamage(self.intData("stage") \\ 16 * mon(Hp));
println(s"${mon} was damaged by poison!")
msg(s"${mon} was damaged by poison!")