1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-24 11:06:51 -05:00

save act and difficulty. Fixes #866

This commit is contained in:
Thomas Christlieb 2020-11-25 11:48:23 +01:00
parent 19e3053c0a
commit 320583b5d4
9 changed files with 38 additions and 6 deletions

View File

@ -0,0 +1,13 @@
package d2enum
// DifficultyType is an enum for the possible difficulties
type DifficultyType int
const (
// DifficultyNormal is the normal difficulty
DifficultyNormal DifficultyType = iota
// DifficultyNightmare is the nightmare difficulty
DifficultyNightmare
// DifficultyHell is the hell difficulty
DifficultyHell
)

View File

@ -19,4 +19,5 @@ type HeroState struct {
LeftSkill int `json:"leftSkill"`
RightSkill int `json:"rightSkill"`
Gold int `json:"Gold"`
Difficulty d2enum.DifficultyType `json:"difficulty"`
}

View File

@ -102,6 +102,7 @@ func (f *MapEntityFactory) NewPlayer(id, name string, x, y, direction int, heroT
isInTown: true,
isRunning: false,
Gold: gold,
Act: 1,
}
result.mapEntity.uuid = id

View File

@ -30,6 +30,7 @@ type Player struct {
isRunning bool
isCasting bool
onFinishedCasting func()
Act int
}
// run speed should be walkspeed * 1.5, since in the original game it is 6 yards walk and 9 yards run.

View File

@ -1,6 +1,7 @@
package d2records
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
)
@ -27,7 +28,14 @@ func difficultyLevelsLoader(r *RecordManager, d *d2txt.DataDictionary) error {
LifeStealDivisor: d.Number("LifeStealDivisor"),
ManaStealDivisor: d.Number("ManaStealDivisor"),
}
records[record.Name] = record
switch record.Name {
case "Normal":
records[d2enum.DifficultyNormal] = record
case "Nightmare":
records[d2enum.DifficultyNightmare] = record
case "Hell":
records[d2enum.DifficultyHell] = record
}
}
if d.Err != nil {

View File

@ -1,7 +1,9 @@
package d2records
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
// DifficultyLevels contain the difficulty records for each difficulty
type DifficultyLevels map[string]*DifficultyLevelRecord
type DifficultyLevels map[d2enum.DifficultyType]*DifficultyLevelRecord
// DifficultyLevelRecord contain the parameters that change for different difficulties
type DifficultyLevelRecord struct {

View File

@ -343,7 +343,7 @@ func (v *Game) OnPlayerMove(targetX, targetY float64) {
func (v *Game) OnPlayerSave() error {
playerState := v.gameClient.Players[v.gameClient.PlayerID]
sp, err := d2netpacket.CreateSavePlayerPacket(playerState)
sp, err := d2netpacket.CreateSavePlayerPacket(playerState, d2enum.DifficultyNormal)
if err != nil {
return fmt.Errorf("SavePlayerPacket: %v", err)
}

View File

@ -3,6 +3,8 @@ package d2netpacket
import (
"encoding/json"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity"
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
)
@ -10,13 +12,15 @@ import (
// SavePlayerPacket has the actual selected left and right skill
// the Server has to check if these skills are actually allowed for the Player
type SavePlayerPacket struct {
Player *d2mapentity.Player `json:"Player"`
Player *d2mapentity.Player `json:"Player"`
Difficulty d2enum.DifficultyType `json:"Difficulty"`
}
// CreateSavePlayerPacket sends a packet which instructs the server to save the Player
func CreateSavePlayerPacket(playerState *d2mapentity.Player) (NetPacket, error) {
func CreateSavePlayerPacket(playerState *d2mapentity.Player, difficulty d2enum.DifficultyType) (NetPacket, error) {
savePlayerData := SavePlayerPacket{
Player: playerState,
Player: playerState,
Difficulty: difficulty,
}
b, err := json.Marshal(savePlayerData)

View File

@ -483,6 +483,8 @@ func (g *GameServer) OnPacketReceived(client ClientConnection, packet d2netpacke
playerState.LeftSkill = savePacket.Player.LeftSkill.Shallow.SkillID
playerState.RightSkill = savePacket.Player.RightSkill.Shallow.SkillID
playerState.Stats = savePacket.Player.Stats
playerState.Act = savePacket.Player.Act
playerState.Difficulty = savePacket.Difficulty
err = g.heroStateFactory.Save(playerState)
if err != nil {