Last active
April 29, 2019 14:43
-
-
Save id-ilych/5e180309564d8ec39e615c9ea38cb12e to your computer and use it in GitHub Desktop.
Before/after (Either)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// before | |
override def receive(ev: AnyRef)(implicit self: ItemValue) = ev match { | |
case ev: MsgItems.ApplyAction if ev.getChoice == ActionChoice.Activate => | |
if (ev.getArgsCount > 0) { | |
val arg = ev.getArgs(0) | |
cfg.targets.lift(arg) match { | |
case Some(target) => | |
items.syncBroadcast(SyncToolForUpgrade(typeId = target.toolTypeId)).info match { | |
case Some(tool) => | |
target.nextUpgrade(upgradesHave = tool.upgrades) match { | |
case Some(upgrade) => | |
val spilUpdate = context.registerSpilInventoryUpdate(SpilUpdateReason.ToolUpgrade) | |
val reason = SpendReason.toolUpgrade( | |
itemType = tool.item.typeId, | |
gmaItemId = gamec.toolAnalyticItemIds(tool.item.typeId), | |
spilUpdate | |
) | |
val price = upgrade.price | |
paidAction(ev, price, reason, "[Lab] [Activate]") { | |
linkTool(tool.item) | |
upgradeDuration.set(upgrade.duration) | |
self.become(fsm.upgrading) | |
} | |
case None => | |
logger.warning(s"[Lab] [Activate] [upgrade is not available] upgrades=${tool.upgrades}") | |
} | |
case None => | |
logger.warning(s"[Lab] [Activate] [tool not found] $arg") | |
} | |
case None => | |
logger.warning(s"[Lab] [Activate] [target not found] $arg") | |
} | |
} | |
else { | |
logger.warning(s"[Lab] [Activate] [no args]") | |
} | |
case _ => super.receive(ev) | |
} | |
// after | |
override def receive(ev: AnyRef)(implicit self: ItemValue) = ev match { | |
case ev: MsgItems.ApplyAction if ev.getChoice == ActionChoice.Activate => | |
val result = for { | |
arg <- Either.cond(ev.getArgsCount > 0, ev.getArgs(0), s"[no args]") | |
target <- VectorUtils.getOrLeft(cfg.targets, arg, s"[target not found] $arg") | |
sync = items.syncBroadcast(SyncToolForUpgrade(typeId = target.toolTypeId)) | |
tool <- sync.info.toRight( s"[tool not found] arg=$arg type=${sync.typeId}") | |
upgrade <- target.nextUpgrade(upgradesHave = tool.upgrades).toRight(s"[upgrade is not available] upgrades=${tool.upgrades}") | |
} yield { | |
val spilUpdate = context.registerSpilInventoryUpdate(SpilUpdateReason.ToolUpgrade) | |
val reason = SpendReason.toolUpgrade( | |
itemType = tool.item.typeId, | |
gmaItemId = gamec.toolAnalyticItemIds(tool.item.typeId), | |
spilUpdate | |
) | |
val price = upgrade.price | |
paidAction(ev, price, reason, "[Lab] [Activate]"){ | |
linkTool(tool.item) | |
upgradeDuration.set(upgrade.duration) | |
self.become(fsm.upgrading) | |
} | |
} | |
result.left.foreach(msg => logger.warning(s"[Lab] [Activate] $msg")) | |
case _ => super.receive(ev) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment