From 4e93d157b20dc2060e9e3cd3e72bc8119c3db9d0 Mon Sep 17 00:00:00 2001 From: kdovtdc Date: Tue, 3 Dec 2024 18:50:18 +0100 Subject: [PATCH 1/2] Implement Concert for Two (LC) * init lc setup * register modifiers * add Def% to owner * uses `ShieldAdded` and `ShieldRemoved` events to check for shield count and apply/remove buff --- .../concertfortwo/concertfortwo.go | 86 +++++++++++++++++++ .../preservation/concertfortwo/data.go | 71 +++++++++++++++ pkg/key/lightcone.go | 1 + pkg/simulation/imports.go | 1 + 4 files changed, 159 insertions(+) create mode 100644 internal/lightcone/preservation/concertfortwo/concertfortwo.go create mode 100644 internal/lightcone/preservation/concertfortwo/data.go diff --git a/internal/lightcone/preservation/concertfortwo/concertfortwo.go b/internal/lightcone/preservation/concertfortwo/concertfortwo.go new file mode 100644 index 00000000..7863dda9 --- /dev/null +++ b/internal/lightcone/preservation/concertfortwo/concertfortwo.go @@ -0,0 +1,86 @@ +package concertfortwo + +import ( + "github.com/simimpact/srsim/pkg/engine" + "github.com/simimpact/srsim/pkg/engine/equip/lightcone" + "github.com/simimpact/srsim/pkg/engine/event" + "github.com/simimpact/srsim/pkg/engine/info" + "github.com/simimpact/srsim/pkg/engine/modifier" + "github.com/simimpact/srsim/pkg/engine/prop" + "github.com/simimpact/srsim/pkg/key" + "github.com/simimpact/srsim/pkg/model" +) + +const ( + Check = "concert-for-two" + Buff = "concert-for-two-buff" +) + +type state struct { + shieldCount int + dmgPerStack float64 +} + +// Increases the wearer's DEF by 16/20/24/28/32%. +// For every on-field character that has a Shield, the DMG dealt by the wearer increases by 4/5/6/7/8%. + +func init() { + lightcone.Register(key.ConcertforTwo, lightcone.Config{ + CreatePassive: Create, + Rarity: 4, + Path: model.Path_PRESERVATION, + Promotions: promotions, + }) + + modifier.Register(Check, modifier.Config{ + Listeners: modifier.Listeners{ + OnAdd: listenShield, + }, + }) + + modifier.Register(Buff, modifier.Config{ + Stacking: modifier.Replace, + StatusType: model.StatusType_STATUS_BUFF, + CanDispel: true, + }) +} + +func Create(engine engine.Engine, owner key.TargetID, lc info.LightCone) { + state := state{ + shieldCount: 0, + dmgPerStack: 0.03 + 0.01*float64(lc.Imposition), + } + + engine.AddModifier(owner, info.Modifier{ + Name: Check, + Source: owner, + Stats: info.PropMap{prop.DEFPercent: 0.12 + 0.04*float64(lc.Imposition)}, + State: &state, + }) +} + +func listenShield(mod *modifier.Instance) { + st := mod.State().(*state) + + mod.Engine().Events().ShieldAdded.Subscribe(func(event event.ShieldAdded) { + if !mod.Engine().IsCharacter(event.Info.Target) { + return + } + st.shieldCount++ + mod.Engine().AddModifier(mod.Source(), info.Modifier{ + Name: Buff, + Source: mod.Owner(), + Stats: info.PropMap{prop.AllDamagePercent: st.dmgPerStack * float64(st.shieldCount)}, + }) + }) + + mod.Engine().Events().ShieldRemoved.Subscribe(func(event event.ShieldRemoved) { + if !mod.Engine().IsCharacter(event.Target) { + return + } + st.shieldCount-- + if st.shieldCount == 0 { + mod.Engine().RemoveModifier(mod.Source(), Buff) + } + }) +} diff --git a/internal/lightcone/preservation/concertfortwo/data.go b/internal/lightcone/preservation/concertfortwo/data.go new file mode 100644 index 00000000..be8ddc0d --- /dev/null +++ b/internal/lightcone/preservation/concertfortwo/data.go @@ -0,0 +1,71 @@ +// Code generated by "weapstat"; DO NOT EDIT. + +package concertfortwo + +import "github.com/simimpact/srsim/pkg/engine/equip/lightcone" + +var promotions = []lightcone.PromotionData{ + { + MaxLevel: 20, + HPBase: 43.2, + HPAdd: 6.48, + ATKBase: 16.8, + ATKAdd: 2.52, + DEFBase: 21, + DEFAdd: 3.15, + }, + { + MaxLevel: 30, + HPBase: 95.04, + HPAdd: 6.48, + ATKBase: 36.96, + ATKAdd: 2.52, + DEFBase: 46.2, + DEFAdd: 3.15, + }, + { + MaxLevel: 40, + HPBase: 164.16, + HPAdd: 6.48, + ATKBase: 63.84, + ATKAdd: 2.52, + DEFBase: 79.8, + DEFAdd: 3.15, + }, + { + MaxLevel: 50, + HPBase: 233.28, + HPAdd: 6.48, + ATKBase: 90.72, + ATKAdd: 2.52, + DEFBase: 113.4, + DEFAdd: 3.15, + }, + { + MaxLevel: 60, + HPBase: 302.4, + HPAdd: 6.48, + ATKBase: 117.6, + ATKAdd: 2.52, + DEFBase: 147, + DEFAdd: 3.15, + }, + { + MaxLevel: 70, + HPBase: 371.52, + HPAdd: 6.48, + ATKBase: 144.48, + ATKAdd: 2.52, + DEFBase: 180.6, + DEFAdd: 3.15, + }, + { + MaxLevel: 80, + HPBase: 440.64, + HPAdd: 6.48, + ATKBase: 171.36, + ATKAdd: 2.52, + DEFBase: 214.2, + DEFAdd: 3.15, + }, +} \ No newline at end of file diff --git a/pkg/key/lightcone.go b/pkg/key/lightcone.go index bf2afa89..7dcd470a 100644 --- a/pkg/key/lightcone.go +++ b/pkg/key/lightcone.go @@ -89,6 +89,7 @@ const ( Pioneering LightCone = "pioneering" WeAreWildfire LightCone = "we_are_wildfire" LandausChoice LightCone = "landaus_choice" + ConcertforTwo LightCone = "concert_for_two" ) // Abundance diff --git a/pkg/simulation/imports.go b/pkg/simulation/imports.go index 78e8c59e..d3c1d4d8 100644 --- a/pkg/simulation/imports.go +++ b/pkg/simulation/imports.go @@ -99,6 +99,7 @@ import ( _ "github.com/simimpact/srsim/internal/lightcone/nihility/void" _ "github.com/simimpact/srsim/internal/lightcone/nihility/wewillmeetagain" _ "github.com/simimpact/srsim/internal/lightcone/preservation/amber" + _ "github.com/simimpact/srsim/internal/lightcone/preservation/concertfortwo" _ "github.com/simimpact/srsim/internal/lightcone/preservation/dayoneofmynewlife" _ "github.com/simimpact/srsim/internal/lightcone/preservation/defense" _ "github.com/simimpact/srsim/internal/lightcone/preservation/landauschoice" From 6393dd53a2221666f76bda0f44bf9f07776f3e0b Mon Sep 17 00:00:00 2001 From: kdovtdc Date: Tue, 3 Dec 2024 19:14:56 +0100 Subject: [PATCH 2/2] Add counting number of shielded characters at the beginning * handles edge cases where the LC effect is registered after another character with a shield already exists --- .../lightcone/preservation/concertfortwo/concertfortwo.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/lightcone/preservation/concertfortwo/concertfortwo.go b/internal/lightcone/preservation/concertfortwo/concertfortwo.go index 7863dda9..724b758d 100644 --- a/internal/lightcone/preservation/concertfortwo/concertfortwo.go +++ b/internal/lightcone/preservation/concertfortwo/concertfortwo.go @@ -62,6 +62,13 @@ func Create(engine engine.Engine, owner key.TargetID, lc info.LightCone) { func listenShield(mod *modifier.Instance) { st := mod.State().(*state) + // Makes sure initial shield count is correct + for _, trg := range mod.Engine().Characters() { + if mod.Engine().IsShielded(trg) { + st.shieldCount++ + } + } + mod.Engine().Events().ShieldAdded.Subscribe(func(event event.ShieldAdded) { if !mod.Engine().IsCharacter(event.Info.Target) { return