-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script to lookup skill values over multiple chars
- Loading branch information
Showing
5 changed files
with
235 additions
and
57 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package com.lkroll.ep.api | ||
|
||
import com.lkroll.roll20.core._ | ||
import com.lkroll.roll20.api.{ Character => Roll20Char, _ } | ||
import com.lkroll.roll20.api.conf._ | ||
import com.lkroll.roll20.api.templates._ | ||
import scalajs.js | ||
import scalajs.js.JSON | ||
import util.{ Try, Success, Failure } | ||
import com.lkroll.ep.model.{ EPCharModel => epmodel, ActiveSkillSection, KnowledgeSkillSection } | ||
|
||
object GMTools extends APIScript { | ||
override def apiCommands: Seq[APICommand[_]] = Seq(GMToolsCommand); | ||
} | ||
|
||
class GMToolsConf(args: Seq[String]) extends ScallopAPIConf(args) { | ||
|
||
val bestMod = opt[Boolean]("best-mod", descr = "List selected characters sorted by best modifier."); | ||
|
||
val skillName = opt[String]( | ||
"skill-name", | ||
descr = "Select skills by name for selected characters.")( | ||
ScallopUtils.singleArgSpacedConverter(identity)); | ||
|
||
val characterNames = opt[List[String]]( | ||
"char-name", | ||
descr = "Use character of this name instead of selected tokens. (Can be specified multiple times.)")( | ||
ScallopUtils.singleListArgConverter(identity)); | ||
|
||
val charIds = opt[Boolean]("char-ids", descr = "Read character ids from trailing args."); | ||
|
||
val trailing = trailArg[List[String]]("trailing", hidden = true, required = false); | ||
|
||
dependsOnAll(bestMod, List(skillName)); | ||
requireOne(bestMod); | ||
verify(); | ||
} | ||
|
||
object GMToolsCommand extends APICommand[GMToolsConf] { | ||
import CoreImplicits._; | ||
override def command = "epgmtools"; | ||
override def options = (args) => new GMToolsConf(args); | ||
override def apply(config: GMToolsConf, ctx: ChatContext): Unit = { | ||
val skill = config.skillName(); | ||
val res = if (config.characterNames.isSupplied || config.charIds()) { | ||
var chars = List.empty[Roll20Char]; | ||
if (config.characterNames.isSupplied) { | ||
val charNames = config.characterNames(); | ||
chars ++= charNames.flatMap { charName => | ||
val r = Roll20Char.find(charName); | ||
if (r.isEmpty) { | ||
ctx.reply(s"No character found for name $charName"); | ||
} | ||
r | ||
} | ||
} | ||
if (config.charIds()) { | ||
val charIds = config.trailing(); | ||
chars ++= charIds.flatMap { charId => | ||
val r = Roll20Char.get(charId); | ||
if (r.isEmpty) { | ||
ctx.reply(s"No character found for ID $charId"); | ||
} | ||
r | ||
} | ||
} | ||
chars.map(skillTotals(_, skill)) | ||
} else ctx.forChar(skillTotals(_, skill)); | ||
if (config.bestMod()) { | ||
val bySkillName = res.flatMap { | ||
case (char, mods) => { | ||
mods.map(t => (char.name, t._1, t._2)) | ||
} | ||
}.groupBy(_._2).map { | ||
case (skillName, l) => { | ||
val l2 = l.map(t => (t._1, t._3)); | ||
(skillName -> l2) | ||
} | ||
}; | ||
val organised = bySkillName.map(t => (t._1 -> t._2.sortBy(_._2))); | ||
val results = organised.map(_ match { | ||
case (skill, mods) => { | ||
val title = s"<b>$skill</b>"; | ||
val modsS = mods.map{ | ||
case (char, total) => s"<em>$char</em> has [[$total]]" | ||
}.mkString("<ul><li>", "</li><li>", "</li></ul>"); | ||
title + modsS | ||
} | ||
}).mkString("<ul><li>", "</li><li>", "</li></ul>"); | ||
debug(s"Results: $results"); | ||
ctx.reply(s"Best Modifiers (incl. wounds and traumas):$results"); | ||
} | ||
} | ||
|
||
private def skillTotals(char: Roll20Char, skill: String): (Roll20Char, List[(String, Int)]) = { | ||
val woundMod = char.attribute(epmodel.woundMod)(); | ||
val traumaMod = char.attribute(epmodel.traumaMod)(); | ||
val aSkills = char.repeating(ActiveSkillSection.skillName).filter(_.current.equalsIgnoreCase(skill)); | ||
val aSkillMods: List[(String, Int)] = aSkills.flatMap { skillNameAttr => | ||
val Some(rowId) = skillNameAttr.getRowId; | ||
val field = char.repeatingAt(rowId)(ActiveSkillSection.field).map(_.apply). | ||
map(f => if (f.isEmpty) "" else s" ($f)").getOrElse(""); | ||
val name = s"${skillNameAttr()}$field"; | ||
val totalO = char.repeatingAt(rowId)(ActiveSkillSection.total).map(_.apply); | ||
totalO.map { total => | ||
val totalModded = total - woundMod - traumaMod; | ||
(name -> totalModded) | ||
} | ||
}; | ||
val kSkills = char.repeating(KnowledgeSkillSection.skillName).filter(_.current.equalsIgnoreCase(skill)); | ||
val kSkillMods: List[(String, Int)] = kSkills.flatMap { skillNameAttr => | ||
val Some(rowId) = skillNameAttr.getRowId; | ||
val field = char.repeatingAt(rowId)(KnowledgeSkillSection.field).map(_.apply). | ||
map(f => if (f.isEmpty) "" else s" ($f)").getOrElse(""); | ||
val name = s"${skillNameAttr()}$field"; | ||
val totalO = char.repeatingAt(rowId)(KnowledgeSkillSection.total).map(_.apply); | ||
totalO.map { total => | ||
val totalModded = total - woundMod - traumaMod; | ||
(name -> totalModded) | ||
} | ||
}; | ||
val skillMods: List[(String, Int)] = aSkillMods ++ kSkillMods; | ||
(char -> skillMods) | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,80 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017 Lars Kroll <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
package com.lkroll.ep | ||
|
||
import com.lkroll.ep.compendium.ChatRenderable | ||
import com.lkroll.roll20.core.{ Rolls, APIButton, RollExpression } | ||
import com.lkroll.ep.model.{ EPCharModel => epmodel } | ||
import com.lkroll.roll20.api._ | ||
import com.lkroll.roll20.api.templates._ | ||
|
||
package object api { | ||
implicit class EnhancedContext(ctx: ChatContext) { | ||
import com.lkroll.roll20.core._ | ||
def withChars(f: List[Character] => Unit): Unit = { | ||
val graphicTokens = ctx.selected; | ||
if (graphicTokens.isEmpty) { | ||
ctx.reply("No tokens selected. Nothing to do..."); | ||
} else { | ||
val tokens = graphicTokens.flatMap { | ||
case t: Token => Some(t) | ||
case c => APILogger.debug(s"Ignoring non-Token $c"); None | ||
}; | ||
val chars = tokens.flatMap { token => | ||
APILogger.debug(s"Working on token: ${token.name} (${token.id})"); | ||
val tO = token.represents; | ||
if (tO.isEmpty) { | ||
ctx.reply(s"Token ${token.name}(${token.id}) does not represent any character!"); | ||
} | ||
tO | ||
} | ||
f(chars) | ||
} | ||
} | ||
|
||
def forChar[T](f: Character => T): List[T] = { | ||
val graphicTokens = ctx.selected; | ||
if (graphicTokens.isEmpty) { | ||
ctx.reply("No tokens selected. Nothing to do..."); | ||
List.empty | ||
} else { | ||
val tokens = graphicTokens.flatMap { | ||
case t: Token => Some(t) | ||
case c => APILogger.debug(s"Ignoring non-Token $c"); None | ||
}; | ||
tokens.flatMap { token => | ||
APILogger.debug(s"Working on token: ${token.name} (${token.id})"); | ||
token.represents match { | ||
case Some(char) => Some(f(char)) | ||
case None => ctx.reply(s"Token ${token.name}(${token.id}) does not represent any character!"); None | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
import TemplateImplicits._; | ||
|
||
def asInfoTemplate(title: String, subtitle: String, importButton: Option[APIButton], keys: List[(String, String)], description: String): String = { | ||
|