aboutsummaryrefslogtreecommitdiff
path: root/internal/game/tick.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/tick.go')
-rw-r--r--internal/game/tick.go92
1 files changed, 77 insertions, 15 deletions
diff --git a/internal/game/tick.go b/internal/game/tick.go
index 9595668..7eb63eb 100644
--- a/internal/game/tick.go
+++ b/internal/game/tick.go
@@ -6,6 +6,7 @@ import (
"thirdcollapse/internal/combat"
"thirdcollapse/internal/player"
+ "thirdcollapse/internal/world"
)
func (g *Game) DisconnectTick() {
@@ -72,29 +73,32 @@ func (g *Game) WanderTick() {
var moves []moveEvent
- // Mob wandering
+ // Mob wandering — exit-based
for _, inst := range g.MobStore.AllInstances() {
- if inst.HP <= 0 || len(inst.WanderRooms) == 0 || inst.WanderInterval <= 0 {
+ if inst.HP <= 0 || inst.WanderInterval <= 0 {
continue
}
if combat.IsMobInCombat(inst.InstanceID) {
continue
}
inst.WanderTickCounter++
- if inst.WanderTickCounter >= inst.WanderInterval {
- inst.WanderTickCounter = 0
- toRoom := inst.WanderRooms[rand.Intn(len(inst.WanderRooms))]
- if toRoom == inst.RoomID {
- continue
- }
- moves = append(moves, moveEvent{
- name: mobDisplayName(inst, false),
- fromRoom: inst.RoomID,
- toRoom: toRoom,
- level: mobCombatLevel(inst),
- })
- inst.RoomID = toRoom
+ if inst.WanderTickCounter < inst.WanderInterval {
+ continue
}
+ inst.WanderTickCounter = 0
+
+ legal := g.legalMobExits(inst)
+ if len(legal) == 0 {
+ continue
+ }
+ toRoom := legal[rand.Intn(len(legal))]
+ moves = append(moves, moveEvent{
+ name: mobDisplayName(inst, false),
+ fromRoom: inst.RoomID,
+ toRoom: toRoom,
+ level: mobCombatLevel(inst),
+ })
+ inst.RoomID = toRoom
}
// Object wandering (fishing spots, etc.)
@@ -139,3 +143,61 @@ func (g *Game) WanderTick() {
}
}
}
+
+func (g *Game) WoodcuttingTick() {
+ all := g.World.AllSharedObjStates()
+ for _, st := range all {
+ if st.Depleted {
+ continue
+ }
+ key := g.World.ObjStateKey(st.RoomID, st.DefID, st.Index)
+ choppers := g.countChoppers(st.RoomID, key)
+ if choppers > 0 {
+ if st.SharedTimer > 0 {
+ st.SharedTimer--
+ }
+ } else {
+ if st.SharedTimer < st.SharedMax {
+ st.SharedTimer++
+ }
+ }
+ }
+}
+
+func (g *Game) countChoppers(roomID int, instanceKey string) int {
+ count := 0
+ for _, sess := range g.Hub.PlayersInRoom(roomID) {
+ p, ok := sess.Player.(*player.Player)
+ if !ok || p.Action == nil || p.Action.Type != "gather" {
+ continue
+ }
+ if key, ok := p.Action.Data["instance_key"].(string); ok && key == instanceKey {
+ count++
+ }
+ }
+ return count
+}
+
+func (g *Game) legalMobExits(inst *world.MobInstance) []int {
+ room, err := g.World.LoadRoom(inst.RoomID)
+ if err != nil || len(room.Exits) == 0 {
+ return nil
+ }
+ allowed := make(map[int]bool)
+ if len(inst.WanderRooms) > 0 {
+ for _, r := range inst.WanderRooms {
+ allowed[r] = true
+ }
+ }
+ var legal []int
+ for _, exitDef := range room.Exits {
+ if exitDef.Condition != nil {
+ continue
+ }
+ if len(allowed) > 0 && !allowed[exitDef.Room] {
+ continue
+ }
+ legal = append(legal, exitDef.Room)
+ }
+ return legal
+}