pushing current
This commit is contained in:
@@ -34,10 +34,12 @@ type Character struct {
|
||||
WorldKills int64 `json:"worldKills"`
|
||||
BossKills int64 `json:"bossKills"`
|
||||
WorldsSurvived int64 `json:"worldsSurvived"`
|
||||
StatsVersion int `json:"statsVersion"`
|
||||
}
|
||||
type Corpse struct {
|
||||
Entity p.Entity `json:"entity"`
|
||||
Inventory map[string]int64 `json:"inventory"`
|
||||
Items []p.ItemInstance `json:"items"`
|
||||
}
|
||||
type Mob struct {
|
||||
Entity p.Entity `json:"entity"`
|
||||
@@ -63,6 +65,8 @@ type World struct {
|
||||
Mobs map[string]*Mob `json:"mobs"`
|
||||
Balance content.Balance `json:"balance"`
|
||||
PendingTitles []TitleCandidate `json:"-"`
|
||||
CatalogVersion int64 `json:"catalogVersion"`
|
||||
RandomCounter uint64 `json:"randomCounter"`
|
||||
terrain *Terrain
|
||||
chunks map[string]p.Chunk
|
||||
now time.Time
|
||||
@@ -98,6 +102,26 @@ func (w *World) Restore(now time.Time) error {
|
||||
}
|
||||
w.dirty = true
|
||||
}
|
||||
if w.Balance.Stats == nil {
|
||||
defaults, err := content.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w.Balance.Stats = defaults.Stats
|
||||
w.Balance.Items = defaults.Items
|
||||
rules := *w.Balance.Progression
|
||||
rules.StatPointsPerLevel = defaults.Progression.StatPointsPerLevel
|
||||
rules.StaminaPerLevel = defaults.Progression.StaminaPerLevel
|
||||
rules.VitalPointsPerChoice = defaults.Progression.VitalPointsPerChoice
|
||||
w.Balance.Progression = &rules
|
||||
w.dirty = true
|
||||
}
|
||||
if w.Balance.CriticalMultiplier == 0 {
|
||||
defaults, err := content.Load()
|
||||
if err != nil { return err }
|
||||
w.Balance.CriticalMultiplier = defaults.CriticalMultiplier
|
||||
w.dirty = true
|
||||
}
|
||||
if err := w.Balance.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -112,6 +136,12 @@ func (w *World) Restore(now time.Time) error {
|
||||
if err := w.restoreProgression(c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := w.restoreEquipment(c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := w.initializeStats(c); err != nil {
|
||||
return err
|
||||
}
|
||||
c.Online = false
|
||||
c.MoveX = 0
|
||||
c.MoveZ = 0
|
||||
@@ -205,6 +235,8 @@ func (w *World) Join(account, name string) (*Character, error) {
|
||||
for k, v := range w.Balance.StartingKit {
|
||||
c.View.Inventory[k] = v
|
||||
}
|
||||
if err := w.restoreEquipment(c); err != nil { return nil, err }
|
||||
if err := w.initializeStats(c); err != nil { return nil, err }
|
||||
w.Characters[c.View.Entity.ID] = c
|
||||
c.BornAt = w.now
|
||||
w.evaluateTitles(c)
|
||||
@@ -221,6 +253,8 @@ func (w *World) Import(c *Character) error {
|
||||
if err := w.restoreProgression(c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := w.restoreEquipment(c); err != nil { return err }
|
||||
if err := w.initializeStats(c); err != nil { return err }
|
||||
pos, err := w.spawn("")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -307,15 +341,25 @@ func (w *World) Intent(id string, i p.Intent) error {
|
||||
if i.Seq <= c.View.ACK || i.Seq > c.View.ACK+10000 {
|
||||
return errors.New("invalid input sequence")
|
||||
}
|
||||
if math.IsNaN(i.X) || math.IsNaN(i.Z) || math.IsInf(i.X, 0) || math.IsInf(i.Z, 0) || math.Abs(i.X) > 1 || math.Abs(i.Z) > 1 || len(i.Target) > 100 {
|
||||
if math.IsNaN(i.X) || math.IsNaN(i.Z) || math.IsInf(i.X, 0) || math.IsInf(i.Z, 0) || math.Abs(i.X) > 1 || math.Abs(i.Z) > 1 || len(i.Target) > 100 || len(i.Slot) > 30 {
|
||||
return errors.New("invalid intent")
|
||||
}
|
||||
c.View.ACK = i.Seq
|
||||
if c.Sheltered && ((i.Op == "move" && (i.X != 0 || i.Z != 0)) || (i.Op != "move" && i.Op != "heal")) {
|
||||
if c.Sheltered && ((i.Op == "move" && (i.X != 0 || i.Z != 0)) || (i.Op != "move" && i.Op != "heal" && i.Op != "allocate-stat" && i.Op != "choose-vital" && i.Op != "equip" && i.Op != "unequip" && i.Op != "drop")) {
|
||||
c.Sheltered = false
|
||||
w.dirty = true
|
||||
}
|
||||
switch i.Op {
|
||||
case "allocate-stat":
|
||||
return w.allocateStat(c, i.Target)
|
||||
case "choose-vital":
|
||||
return w.chooseVital(c, i.Target)
|
||||
case "equip":
|
||||
return w.equip(c, i.Target, i.Slot)
|
||||
case "unequip":
|
||||
return w.unequip(c, i.Target)
|
||||
case "drop":
|
||||
return w.dropItem(c, i.Target)
|
||||
case "move":
|
||||
n := math.Max(1, math.Hypot(i.X, i.Z))
|
||||
c.MoveX = i.X / n
|
||||
@@ -333,6 +377,7 @@ func (w *World) Intent(id string, i p.Intent) error {
|
||||
return errors.New("no bandage needed or available")
|
||||
}
|
||||
c.View.Inventory["bandage"]--
|
||||
w.RefreshStats(c)
|
||||
c.View.Entity.HP = math.Min(c.View.Entity.MaxHP, c.View.Entity.HP+w.Balance.BandageHealing)
|
||||
w.dirty = true
|
||||
case "return":
|
||||
@@ -347,15 +392,7 @@ func (w *World) Intent(id string, i p.Intent) error {
|
||||
c.View.HasKeystone = false
|
||||
w.dirty = true
|
||||
case "loot":
|
||||
corpse := w.Corpses[i.Target]
|
||||
if corpse == nil || distance(c.View.Entity.Position, corpse.Entity.Position) > w.Balance.GatherRange {
|
||||
return errors.New("corpse out of reach")
|
||||
}
|
||||
for k, v := range corpse.Inventory {
|
||||
c.View.Inventory[k] += v
|
||||
}
|
||||
delete(w.Corpses, i.Target)
|
||||
w.dirty = true
|
||||
return w.lootCorpse(c, i.Target)
|
||||
default:
|
||||
return errors.New("unknown intent")
|
||||
}
|
||||
@@ -380,7 +417,7 @@ func (w *World) gather(c *Character, target string) error {
|
||||
if item == "" {
|
||||
return errors.New("not gatherable")
|
||||
}
|
||||
c.View.Inventory[item]++
|
||||
c.View.Inventory[item] += w.yieldAmount(c.View.Stats["gatherRate"].Final)
|
||||
c.View.Skills["gathering"] += w.Balance.SkillXpPerAction
|
||||
c.LastGather = w.Age()
|
||||
w.Depleted[target] = w.Age() + w.Balance.ResourceRespawnSeconds
|
||||
@@ -407,8 +444,9 @@ func (w *World) craft(c *Character, name string) error {
|
||||
c.View.Inventory[k] -= v
|
||||
}
|
||||
for k, v := range r.Outputs {
|
||||
c.View.Inventory[k] += v
|
||||
if err := w.grantItems(c, k, v); err != nil { return err }
|
||||
}
|
||||
w.RefreshStats(c)
|
||||
c.View.Skills["crafting"] += w.Balance.SkillXpPerAction
|
||||
c.Message = "Crafted " + name
|
||||
w.grantXP(c, w.Balance.Progression.CraftXP)
|
||||
@@ -420,15 +458,14 @@ func (w *World) attack(c *Character, target string) error {
|
||||
if w.Age()-c.LastAttack < w.Balance.AttackCooldown {
|
||||
return errors.New("attack cooldown")
|
||||
}
|
||||
damage := w.Balance.PlayerDamage
|
||||
if c.View.Inventory["spear"] > 0 {
|
||||
damage = w.Balance.SpearDamage
|
||||
}
|
||||
damage = math.Max(0, damage+c.titleEffects().Damage)
|
||||
damage := c.View.Stats["meleeDamage"].Final
|
||||
if target == "boss" {
|
||||
if w.Phase != "cataclysm" || distance(c.View.Entity.Position, w.terrain.Position(0, 0)) > w.Balance.AttackRange+4 {
|
||||
return errors.New("boss out of reach")
|
||||
}
|
||||
if w.roll(c.View.Stats["criticalChance"].Final) {
|
||||
damage *= w.Balance.CriticalMultiplier
|
||||
}
|
||||
w.BossHP = math.Max(0, w.BossHP-damage)
|
||||
if w.BossHP == 0 {
|
||||
c.BossKills++
|
||||
@@ -454,13 +491,21 @@ func (w *World) attack(c *Character, target string) error {
|
||||
if m == nil || m.Entity.HP <= 0 || distance(c.View.Entity.Position, m.Entity.Position) > w.Balance.AttackRange {
|
||||
return errors.New("target out of reach")
|
||||
}
|
||||
if w.roll(c.View.Stats["criticalChance"].Final) {
|
||||
damage *= w.Balance.CriticalMultiplier
|
||||
}
|
||||
m.Entity.HP = math.Max(0, m.Entity.HP-damage)
|
||||
if m.Entity.HP == 0 {
|
||||
m.Entity.State = "dead"
|
||||
m.RespawnAt = w.Age() + w.Balance.MobRespawnSeconds
|
||||
c.View.Kills++
|
||||
c.WorldKills++
|
||||
c.View.Inventory["herb"]++
|
||||
c.View.Inventory["herb"] += w.yieldAmount(c.View.Stats["dropRate"].Final)
|
||||
for _, item := range w.Balance.Items {
|
||||
if w.roll(item.DropChance*c.View.Stats["dropRate"].Final/100) {
|
||||
if err := w.grantItems(c, item.ID, 1); err != nil { return err }
|
||||
}
|
||||
}
|
||||
w.grantXP(c, w.Balance.Progression.MobKillXP)
|
||||
}
|
||||
}
|
||||
@@ -479,8 +524,11 @@ func (w *World) kill(c *Character, reason string) {
|
||||
e.Kind = "corpse"
|
||||
e.State = "dead"
|
||||
e.HP = 0
|
||||
w.Corpses[e.ID] = &Corpse{Entity: e, Inventory: c.View.Inventory}
|
||||
w.Corpses[e.ID] = &Corpse{Entity: e, Inventory: c.View.Inventory, Items: c.View.Items}
|
||||
c.View.Inventory = map[string]int64{}
|
||||
c.View.Items = []p.ItemInstance{}
|
||||
c.View.Equipment = map[string]string{}
|
||||
c.View.CarryWeight = 0
|
||||
c.View.Entity.HP = 0
|
||||
c.View.Entity.State = "dead"
|
||||
c.MoveX = 0
|
||||
@@ -579,6 +627,9 @@ func (w *World) Advance(now time.Time, dt float64) {
|
||||
}
|
||||
}
|
||||
if c.Online {
|
||||
if c.View.Entity.HP > 0 { c.View.Entity.HP = math.Min(c.View.Entity.MaxHP, c.View.Entity.HP+c.View.Stats["healthRecovery"].Final*dt) }
|
||||
c.View.Mana = math.Min(c.View.Stats["manaPoints"].Final, c.View.Mana+c.View.Stats["manaRecovery"].Final*dt)
|
||||
c.View.Stamina = math.Min(c.View.Stats["stamina"].Final, c.View.Stamina+c.View.Stats["staminaRecovery"].Final*dt)
|
||||
// A generous window: the client resends its move intent well under this on every
|
||||
// rendered frame, but a slow/throttled frame (e.g. software-rendered CI) shouldn't
|
||||
// zero out in-flight movement and strand a walk-to-target action mid-course.
|
||||
@@ -610,7 +661,7 @@ func (w *World) Advance(now time.Time, dt float64) {
|
||||
if w.Age()-w.BossLastAttack >= w.Balance.BossCooldown {
|
||||
for _, c := range characters {
|
||||
if c.Online && !c.Sheltered && c.View.Entity.State == "alive" && distance(c.View.Entity.Position, w.terrain.Position(0, 0)) <= w.Balance.BossRange {
|
||||
c.View.Entity.HP -= w.Balance.BossDamage
|
||||
w.damageCharacter(c, w.Balance.BossDamage)
|
||||
w.dirty = true
|
||||
if c.View.Entity.HP <= 0 {
|
||||
w.kill(c, "The Harbinger ended this character's journey.")
|
||||
@@ -700,7 +751,7 @@ func (w *World) updateMobs(active map[string]bool, dt float64) {
|
||||
}
|
||||
if nearest <= w.Balance.MobAttackRange {
|
||||
if w.Age()-m.LastAttack >= w.Balance.MobCooldown {
|
||||
target.View.Entity.HP -= w.Balance.MobDamage * (1 + w.Age()/86400*w.Balance.MobScalePerDay)
|
||||
w.damageCharacter(target, w.Balance.MobDamage*(1+w.Age()/86400*w.Balance.MobScalePerDay))
|
||||
m.LastAttack = w.Age()
|
||||
w.dirty = true
|
||||
if target.View.Entity.HP <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user