Skip to content

Commit

Permalink
Add back hurt syntax (#1700)
Browse files Browse the repository at this point in the history
* add back hurt syntax

* adjust config file docs

* remove unused code

* remove vourukashasglow stacks param
- fix drain part triggering on non-external drain

* remove beaconofthereedsea damaged param

* remove alleyflash lambda param
- fix drain part triggering if someone other than holder is drained

* adjust drain event sub active checks
  • Loading branch information
k0l11 authored Sep 10, 2023
1 parent b837247 commit 5b544c7
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewSet(c *core.Core, char *character.CharWrapper, count int, param map[stri

c.Events.Subscribe(event.OnPlayerHPDrain, func(args ...interface{}) bool {
di := args[0].(player.DrainInfo)
if c.Player.Active() != char.Index {
if di.ActorIndex != char.Index {
return false
}
if di.ActorIndex != char.Index {
Expand Down
16 changes: 5 additions & 11 deletions internal/artifacts/vourukashasglow/vourukashasglow.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ func NewSet(c *core.Core, char *character.CharWrapper, count int, param map[stri

if count >= 4 {
counter := 0
permStacks := param["stacks"]
if permStacks > 5 {
permStacks = 5
}
mStack := make([]float64, attributes.EndStatType)
mStack[attributes.DmgP] = 0.08
addStackMod := func(idx int, duration int) {
Expand All @@ -69,20 +65,18 @@ func NewSet(c *core.Core, char *character.CharWrapper, count int, param map[stri
},
})
}
for i := 0; i < permStacks; i++ {
addStackMod(i, -1)
}
c.Events.Subscribe(event.OnPlayerHPDrain, func(args ...interface{}) bool {
di := args[0].(player.DrainInfo)
if di.Amount <= 0 {
if di.ActorIndex != char.Index {
return false
}
if di.ActorIndex != char.Index {
if di.Amount <= 0 {
return false
}
if counter >= permStacks {
addStackMod(counter, 300)
if !di.External {
return false
}
addStackMod(counter, 300)
counter = (counter + 1) % 5
return false
}, fmt.Sprintf("vg-4pc-%v", char.Base.Key.String()))
Expand Down
35 changes: 24 additions & 11 deletions internal/weapons/claymore/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/genshinsim/gcsim/pkg/core/event"
"github.com/genshinsim/gcsim/pkg/core/info"
"github.com/genshinsim/gcsim/pkg/core/keys"
"github.com/genshinsim/gcsim/pkg/core/player"
"github.com/genshinsim/gcsim/pkg/core/player/character"
"github.com/genshinsim/gcsim/pkg/modifier"
)
Expand All @@ -35,7 +36,6 @@ func NewWeapon(c *core.Core, char *character.CharWrapper, p info.WeaponProfile)
r := p.Refine

stackAtk := .15 + float64(r)*.05
damaged := p.Params["damaged"]

stackDuration := 480 //8s * 60
const skillKey = "beacon-of-the-reed-sea-skill"
Expand All @@ -55,6 +55,7 @@ func NewWeapon(c *core.Core, char *character.CharWrapper, p info.WeaponProfile)
})

mATK := make([]float64, attributes.EndStatType)
mATK[attributes.ATKP] = stackAtk
c.Events.Subscribe(event.OnEnemyDamage, func(args ...interface{}) bool {
atk := args[1].(*combat.AttackEvent)
if atk.Info.ActorIndex != char.Index {
Expand All @@ -64,26 +65,38 @@ func NewWeapon(c *core.Core, char *character.CharWrapper, p info.WeaponProfile)
return false
}

mATK[attributes.ATKP] = stackAtk
char.AddStatMod(character.StatMod{
Base: modifier.NewBaseWithHitlag(skillKey, stackDuration),
AffectedStat: attributes.ATKP,
Amount: func() ([]float64, bool) {
return mATK, true
},
})
if damaged > 0 {
char.AddStatMod(character.StatMod{
Base: modifier.NewBaseWithHitlag(damagedKey, stackDuration),
AffectedStat: attributes.ATKP,
Amount: func() ([]float64, bool) {
return mATK, true
},
})

return false
}, fmt.Sprintf("beacon-of-the-reed-sea-enemy-%v", char.Base.Key.String()))

c.Events.Subscribe(event.OnPlayerHPDrain, func(args ...interface{}) bool {
di := args[0].(player.DrainInfo)
if di.ActorIndex != char.Index {
return false
}
if di.Amount <= 0 {
return false
}
if !di.External {
return false
}

char.AddStatMod(character.StatMod{
Base: modifier.NewBaseWithHitlag(damagedKey, stackDuration),
AffectedStat: attributes.ATKP,
Amount: func() ([]float64, bool) {
return mATK, true
},
})
return false
}, fmt.Sprintf("beacon-of-the-reed-sea-%v", char.Base.Key.String()))
}, fmt.Sprintf("beacon-of-the-reed-sea-player-%v", char.Base.Key.String()))

return w, nil
}
27 changes: 4 additions & 23 deletions internal/weapons/sword/alley/alley.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package alley

import (
"fmt"
"math"

"github.com/genshinsim/gcsim/pkg/core"
"github.com/genshinsim/gcsim/pkg/core/attributes"
Expand All @@ -18,7 +17,6 @@ func init() {
core.RegisterWeaponFunc(keys.TheAlleyFlash, NewWeapon)
}

// Upon damaging an opponent, increases CRIT Rate by 8/10/12/14/16%. Max 5 stacks. A CRIT Hit removes all stacks.
type Weapon struct {
Index int
c *core.Core
Expand All @@ -29,15 +27,6 @@ const lockoutKey = "alley-flash-lockout"

func (w *Weapon) SetIndex(idx int) { w.Index = idx }
func (w *Weapon) Init() error { return nil }
func (w *Weapon) selfDisable(lambda float64) func() {
return func() {
//disable for 5 sec
w.char.AddStatus(lockoutKey, 300, true)
//-ln(U)/lambda` (where U~Uniform[0,1]).
next := int(math.Log(w.c.Rand.Float64()) / lambda)
w.c.Tasks.Add(w.selfDisable(lambda), next)
}
}

func NewWeapon(c *core.Core, char *character.CharWrapper, p info.WeaponProfile) (info.Weapon, error) {
w := &Weapon{
Expand All @@ -46,25 +35,17 @@ func NewWeapon(c *core.Core, char *character.CharWrapper, p info.WeaponProfile)
}
r := p.Refine

//allow user to periodically lock out this weapon (just to screw around with bennett)
//follows poisson distribution, user provides lambda:
//https://stackoverflow.com/questions/6527345/simulating-poisson-waiting-times
if lambda, ok := p.Params["lambda"]; ok {
//user supplied lambda should be per min, so we need to scale this down by *60*60
l := float64(lambda) / 3600.0
//queue tasks to disable
next := int(-math.Log(1-w.c.Rand.Float64()) / l)
c.Tasks.Add(w.selfDisable(l), next)
}

c.Events.Subscribe(event.OnPlayerHPDrain, func(args ...interface{}) bool {
di := args[0].(player.DrainInfo)
if !di.External {
if di.ActorIndex != char.Index {
return false
}
if di.Amount <= 0 {
return false
}
if !di.External {
return false
}
w.char.AddStatus(lockoutKey, 300, true)
return false
}, fmt.Sprintf("alleyflash-%v", char.Base.Key.String()))
Expand Down
2 changes: 1 addition & 1 deletion internal/weapons/sword/aquila/aquila.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewWeapon(c *core.Core, char *character.CharWrapper, p info.WeaponProfile)
if di.Amount <= 0 {
return false
}
if c.Player.Active() != char.Index {
if di.ActorIndex != char.Index {
return false
}
if char.StatusIsActive(icdKey) {
Expand Down
13 changes: 13 additions & 0 deletions pkg/core/info/actionlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"log"

"github.com/genshinsim/gcsim/pkg/core/attributes"
"github.com/genshinsim/gcsim/pkg/core/keys"
)

Expand All @@ -13,6 +14,7 @@ type ActionList struct {
Characters []CharacterProfile `json:"characters"`
InitialChar keys.Char `json:"initial"`
Energy EnergySettings `json:"energy_settings"`
Hurt HurtSettings `json:"hurt_settings"`
Settings SimulatorSettings `json:"settings"`
Errors []error `json:"-"` //These represents errors preventing ActionList from being executed
ErrorMsgs []string `json:"errors"`
Expand All @@ -27,6 +29,17 @@ type EnergySettings struct {
LastEnergyDrop int `json:"last_energy_drop"`
}

type HurtSettings struct {
Active bool `json:"active"`
Once bool `json:"once"`
Start int `json:"start"`
End int `json:"end"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Element attributes.Element `json:"element"`
LastHurt int `json:"last_hurt"`
}

type SimulatorSettings struct {
Duration float64 `json:"-"`
DamageMode bool `json:"damage_mode"`
Expand Down
1 change: 1 addition & 0 deletions pkg/gcs/ast/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const (
keywordEnergy // energy
keywordParticleThreshold // particle_threshold
keywordParticleDropCount // particle_drop_count
keywordHurt // hurt

// Keywords specific to gcsim appears after this
itemKeys
Expand Down
1 change: 1 addition & 0 deletions pkg/gcs/ast/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var key = map[string]TokenType{
"particle_drop_count": keywordParticleDropCount,
"resist": keywordResist,
"energy": keywordEnergy,
"hurt": keywordHurt,
//commands
//team keywords
//flags
Expand Down
3 changes: 3 additions & 0 deletions pkg/gcs/ast/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ func parseRows(p *Parser) (parseFn, error) {
case keywordEnergy:
p.next()
return parseEnergy, nil
case keywordHurt:
p.next()
return parseHurt, nil
case keywordOptions:
p.next()
return parseOptions, nil
Expand Down
Loading

0 comments on commit 5b544c7

Please sign in to comment.