Skip to content

Commit

Permalink
Make Movement AI instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ToxicKevinFerm committed May 12, 2024
1 parent 12c22d5 commit aaf6ce9
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 86 deletions.
Binary file modified assets/database/db.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions assets/database/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -10128,7 +10128,7 @@
],
"encounters":[
{"path":"Default/Raid Target","targets":[{"path":"Default/Raid Target","target":{"id":31146,"name":"Raid Target","level":88,"mobType":7,"stats":[0,0,0,0,0,0,0,0,0,0,0,650,0,0,0,0,0,0,11977,0,0,0,0,0,0,120016403,0,0,0,0,0,0,0],"minBaseDamage":210000,"damageSpread":0.4,"swingSpeed":2.5}}]},
{"path":"Movement/Light","targets":[{"path":"Movement/Light","target":{"id":31147,"name":"Light","level":88,"mobType":7,"stats":[0,0,0,0,0,0,0,0,0,0,0,650,0,0,0,0,0,0,11977,0,0,0,0,0,0,120016403,0,0,0,0,0,0,0],"minBaseDamage":210000,"damageSpread":0.4,"swingSpeed":2.5}}]},
{"path":"Default/Movement","targets":[{"path":"Default/Movement","target":{"id":31147,"name":"Movement","level":88,"mobType":7,"stats":[0,0,0,0,0,0,0,0,0,0,0,650,0,0,0,0,0,0,11977,0,0,0,0,0,0,120016403,0,0,0,0,0,0,0],"minBaseDamage":210000,"damageSpread":0.4,"swingSpeed":2.5,"targetInputs":[{"inputType":1,"label":"Movement Interval","tooltip":"How often the player will move in seconds","numberValue":10},{"inputType":1,"label":"Reaction Time","tooltip":"How long the player can wait for casts to finish before moving in seconds","numberValue":1.5},{"inputType":1,"label":"Yards","tooltip":"How many yards the player moves","numberValue":5}]}}]},
{"path":"Blackwing Descent/Magmaw 10","targets":[{"path":"Blackwing Descent/Magmaw 10","target":{"id":41570,"name":"Magmaw 10","level":88,"mobType":1,"stats":[0,0,0,0,0,0,0,0,0,0,0,650,0,0,0,0,0,0,11977,0,0,0,0,0,0,26798304,0,0,0,0,0,0,0],"minBaseDamage":110000,"damageSpread":0.4,"swingSpeed":2.5,"targetInputs":[{"inputType":1,"label":"Impale Reaction Time","tooltip":"How long will the Raid take to Impale Head in Seconds. (After the initial 10s)","numberValue":5}]}}]},
{"path":"Blackwing Descent/Magmaw 25","targets":[{"path":"Blackwing Descent/Magmaw 25","target":{"id":41571,"name":"Magmaw 25","level":88,"mobType":1,"stats":[0,0,0,0,0,0,0,0,0,0,0,650,0,0,0,0,0,0,11977,0,0,0,0,0,0,81082048,0,0,0,0,0,0,0],"minBaseDamage":150000,"damageSpread":0.4,"swingSpeed":2.5,"targetInputs":[{"inputType":1,"label":"Impale Reaction Time","tooltip":"How long will the Raid take to Impale Head in Seconds. (After the initial 10s)","numberValue":5}]}}]},
{"path":"Blackwing Descent/Magmaw 10 H","targets":[{"path":"Blackwing Descent/Magmaw 10 H","target":{"id":41572,"name":"Magmaw 10 H","level":88,"mobType":1,"stats":[0,0,0,0,0,0,0,0,0,0,0,650,0,0,0,0,0,0,11977,0,0,0,0,0,0,39200000,0,0,0,0,0,0,0],"minBaseDamage":150000,"damageSpread":0.4,"swingSpeed":2.5,"targetInputs":[{"inputType":1,"label":"Impale Reaction Time","tooltip":"How long will the Raid take to Impale Head in Seconds. (After the initial 10s)","numberValue":5}]}}]},
Expand Down Expand Up @@ -10482,4 +10482,4 @@
{"itemId":43380,"spellId":58038},
{"itemId":43379,"spellId":58039}
]
}
}
83 changes: 0 additions & 83 deletions sim/encounters/light_movement.go

This file was deleted.

141 changes: 141 additions & 0 deletions sim/encounters/movement_ai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package encounters

import (
"time"

"github.com/wowsims/cata/sim/core"
"github.com/wowsims/cata/sim/core/proto"
"github.com/wowsims/cata/sim/core/stats"
)

func addMovementAI() {
core.AddPresetTarget(&core.PresetTarget{
PathPrefix: "Default",
Config: &proto.Target{
Id: 31147,
Name: "Movement",
Level: 88,
MobType: proto.MobType_MobTypeMechanical,
TankIndex: 0,

Stats: stats.Stats{
stats.Health: 120_016_403,
stats.Armor: 11977,
stats.AttackPower: 650,
}.ToFloatArray(),

SpellSchool: proto.SpellSchool_SpellSchoolPhysical,
SwingSpeed: 2.5,
MinBaseDamage: 210000,
DamageSpread: 0.4,
SuppressDodge: false,
ParryHaste: false,
DualWield: false,
DualWieldPenalty: false,
TargetInputs: []*proto.TargetInput{
{
Label: "Movement Interval",
Tooltip: "How often the player will move in seconds",
InputType: proto.InputType_Number,
NumberValue: 10.0,
},
{
Label: "Reaction Time",
Tooltip: "How long the player can wait for casts to finish before moving in seconds",
InputType: proto.InputType_Number,
NumberValue: 1.5,
},
{
Label: "Yards",
Tooltip: "How many yards the player moves",
InputType: proto.InputType_Number,
NumberValue: 5,
},
},
},
AI: NewMovementAI(),
})
core.AddPresetEncounter("Movement", []string{
"Default/Movement",
})
}

type MovementAI struct {
Target *core.Target
LastMoveTime time.Duration
MoveInterval time.Duration // How often moves happen
ReactionTime time.Duration // Time available to react before area should be cleared
MoveYards float64 // Duration of the move
}

func NewMovementAI() core.AIFactory {
return func() core.TargetAI {
return &MovementAI{}
}
}

func (ai *MovementAI) Initialize(target *core.Target, config *proto.Target) {
ai.Target = target

if len(config.TargetInputs) > 0 {
ai.MoveInterval = core.DurationFromSeconds(config.TargetInputs[0].NumberValue)
} else {
ai.MoveInterval = core.DurationFromSeconds(10)
}

if len(config.TargetInputs) > 1 {
ai.ReactionTime = core.DurationFromSeconds(config.TargetInputs[1].NumberValue)
} else {
ai.ReactionTime = core.DurationFromSeconds(1.5)
}

if len(config.TargetInputs) > 2 {
ai.MoveYards = config.TargetInputs[2].NumberValue
} else {
ai.MoveYards = 5.0
}
}

func (ai *MovementAI) Reset(sim *core.Simulation) {
ai.LastMoveTime = 0
}

func (ai *MovementAI) ExecuteCustomRotation(sim *core.Simulation) {
players := sim.Raid.AllPlayerUnits

if !ai.ShouldMove(sim) {
return
}
for i := 0; i < len(players); i++ {
player := players[i]
duration := ai.TimeToMove(ai.MoveYards, player)
if player.Hardcast.Expires > sim.CurrentTime && !player.Hardcast.CanMove {
castEndsAt := player.Hardcast.Expires - sim.CurrentTime
// if castEndsAt < ai.ReactionTime {
core.StartDelayedAction(sim, core.DelayedActionOptions{
DoAt: sim.CurrentTime + castEndsAt,
Priority: core.ActionPriorityPrePull + 1,
OnAction: func(s *core.Simulation) {
player.MoveDuration(duration, sim)
},
})
// } else {
// // Cancel casted spell and move immediately
// // For now we do nothing in this scenario
// return
// }
} else {
player.MoveDuration(duration, sim)
}
}
}
func (ai *MovementAI) TimeToMove(distance float64, unit *core.Unit) time.Duration {
return core.DurationFromSeconds(distance / unit.GetMovementSpeed())
}
func (ai *MovementAI) ShouldMove(sim *core.Simulation) bool {
if sim.CurrentTime-ai.LastMoveTime >= ai.MoveInterval {
ai.LastMoveTime = sim.CurrentTime
return true
}
return false
}
2 changes: 1 addition & 1 deletion sim/encounters/register_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func init() {
AddDefaultPresetEncounter()
addLightMovementAI()
addMovementAI()
bwd.Register()

}
Expand Down

0 comments on commit aaf6ce9

Please sign in to comment.