-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #814 from shizukayuki/revamp-conditionals
Refactor conditionals
- Loading branch information
Showing
29 changed files
with
300 additions
and
629 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
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,10 @@ | ||
package character | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func (c *Character) Condition(fields []string) (any, error) { | ||
return false, fmt.Errorf("invalid character condition: .%v.%v", c.Base.Key.String(), strings.Join(fields, ".")) | ||
} |
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,103 @@ | ||
package conditional | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/genshinsim/gcsim/pkg/core" | ||
"github.com/genshinsim/gcsim/pkg/core/action" | ||
"github.com/genshinsim/gcsim/pkg/core/attributes" | ||
"github.com/genshinsim/gcsim/pkg/core/keys" | ||
"github.com/genshinsim/gcsim/pkg/core/player/character" | ||
) | ||
|
||
func evalCharacter(c *core.Core, key keys.Char, fields []string) (any, error) { | ||
if err := fieldsCheck(fields, 2, "character"); err != nil { | ||
return 0, err | ||
} | ||
char, ok := c.Player.ByKey(key) | ||
if !ok { | ||
return 0, fmt.Errorf("character %v not in team when evaluating condition", key) | ||
} | ||
|
||
// special case for ability conditions. since fields are swapped | ||
// .kokomi.<abil>.<cond> | ||
typ := fields[1] | ||
act := action.StringToAction(typ) | ||
if act != action.InvalidAction { | ||
if err := fieldsCheck(fields, 3, "character ability"); err != nil { | ||
return 0, err | ||
} | ||
return evalCharacterAbil(c, char, act, fields[2]) | ||
} | ||
|
||
switch typ { | ||
case "cons": | ||
return char.Base.Cons, nil | ||
case "energy": | ||
return char.Energy, nil | ||
case "energymax": | ||
return char.EnergyMax, nil | ||
case "normal": | ||
return char.NextNormalCounter(), nil | ||
case "onfield": | ||
return c.Player.Active() == char.Index, nil | ||
case "weapon": | ||
return int(char.Weapon.Key), nil | ||
case "status": | ||
if err := fieldsCheck(fields, 3, "character "+typ); err != nil { | ||
return 0, err | ||
} | ||
return char.StatusIsActive(fields[2]), nil | ||
case "mods": | ||
if err := fieldsCheck(fields, 3, "character "+typ); err != nil { | ||
return 0, err | ||
} | ||
return char.StatModIsActive(fields[2]), nil | ||
case "infusion": | ||
if err := fieldsCheck(fields, 3, "character "+typ); err != nil { | ||
return 0, err | ||
} | ||
return c.Player.WeaponInfuseIsActive(char.Index, fields[2]), nil | ||
case "tags": | ||
if err := fieldsCheck(fields, 3, "character "+typ); err != nil { | ||
return 0, err | ||
} | ||
return char.Tag(fields[2]), nil | ||
case "stats": | ||
if err := fieldsCheck(fields, 3, "character "+typ); err != nil { | ||
return 0, err | ||
} | ||
return evalCharacterStats(char, fields[2]) | ||
default: // .kokomi.* | ||
return char.Condition(fields[1:]) | ||
} | ||
|
||
} | ||
|
||
func evalCharacterStats(char *character.CharWrapper, stat string) (float64, error) { | ||
key := attributes.StrToStatType(stat) | ||
if key == -1 { | ||
return 0, fmt.Errorf("invalid stat key %v in character stat condition", stat) | ||
} | ||
return char.Stat(key), nil | ||
} | ||
|
||
func evalCharacterAbil(c *core.Core, char *character.CharWrapper, act action.Action, typ string) (any, error) { | ||
switch typ { | ||
case "cd": | ||
if act == action.ActionSwap { | ||
return c.Player.SwapCD, nil | ||
} | ||
return char.Cooldown(act), nil | ||
case "charge": | ||
return char.Charges(act), nil | ||
case "ready": | ||
if act == action.ActionSwap { | ||
return c.Player.SwapCD == 0 || c.Player.Active() == char.Index, nil | ||
} | ||
//TODO: nil map may cause problems here?? | ||
return char.ActionReady(act, nil), nil | ||
default: | ||
return 0, fmt.Errorf("bad character ability condition: invalid type %v", typ) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,52 +1,42 @@ | ||
package conditional | ||
|
||
import ( | ||
"strings" | ||
"fmt" | ||
|
||
"github.com/genshinsim/gcsim/pkg/core" | ||
"github.com/genshinsim/gcsim/pkg/shortcut" | ||
) | ||
|
||
func Eval(c *core.Core, fields []string) int64 { | ||
func fieldsCheck(fields []string, expecting int, category string) error { | ||
if len(fields) < expecting { | ||
return fmt.Errorf("bad %v condition; invalid num of fields; expecting at least %v; got %v", category, expecting, len(fields)) | ||
} | ||
return nil | ||
} | ||
|
||
func Eval(c *core.Core, fields []string) (any, error) { | ||
switch fields[0] { | ||
case ".debuff": | ||
case "debuff": | ||
return evalDebuff(c, fields) | ||
case ".element": | ||
case "element": | ||
return evalElement(c, fields) | ||
case ".cd": | ||
return evalCD(c, fields) | ||
case ".energy": | ||
return evalEnergy(c, fields) | ||
case ".status": | ||
return evalStatus(c, fields) | ||
case ".tags": | ||
return evalTags(c, fields) | ||
case ".stam": | ||
return evalStam(c, fields) | ||
case ".ready": | ||
return evalReady(c, fields) | ||
case ".mods": | ||
return evalCharMods(c, fields) | ||
case ".infusion": | ||
return evalInfusion(c, fields) | ||
case ".construct": | ||
case "status": | ||
if err := fieldsCheck(fields, 2, "status"); err != nil { | ||
return 0, err | ||
} | ||
return c.Status.Duration(fields[1]), nil | ||
case "stam": | ||
return c.Player.Stam, nil | ||
case "construct": | ||
return evalConstruct(c, fields) | ||
case ".normal": | ||
return evalNormalCounter(c, fields) | ||
case ".onfield": | ||
return evalOnField(c, fields) | ||
case ".weapon": | ||
return evalWeapon(c, fields) | ||
case ".keys": | ||
case "keys": | ||
return evalKeys(c, fields) | ||
case ".cons": | ||
return evalConstellation(c, fields) | ||
default: | ||
//check if it's a char name; if so check char custom eval func | ||
name := strings.TrimPrefix(fields[0], ".") | ||
name := fields[0] | ||
if key, ok := shortcut.CharNameToKey[name]; ok { | ||
return evalCharCustom(c, key, fields) | ||
return evalCharacter(c, key, fields) | ||
} | ||
return 0 | ||
return 0, fmt.Errorf("invalid character %v in character condition", name) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.