mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-30 07:06:18 -04:00
Merge pull request #942 from ThomasChr/#866_save_act_and_difficulty
save act and difficulty. Fixes #866
This commit is contained in:
commit
3d00a0fd17
13
d2common/d2enum/difficulty.go
Normal file
13
d2common/d2enum/difficulty.go
Normal 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
|
||||||
|
)
|
@ -19,4 +19,5 @@ type HeroState struct {
|
|||||||
LeftSkill int `json:"leftSkill"`
|
LeftSkill int `json:"leftSkill"`
|
||||||
RightSkill int `json:"rightSkill"`
|
RightSkill int `json:"rightSkill"`
|
||||||
Gold int `json:"Gold"`
|
Gold int `json:"Gold"`
|
||||||
|
Difficulty d2enum.DifficultyType `json:"difficulty"`
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,7 @@ func (f *MapEntityFactory) NewPlayer(id, name string, x, y, direction int, heroT
|
|||||||
isInTown: true,
|
isInTown: true,
|
||||||
isRunning: false,
|
isRunning: false,
|
||||||
Gold: gold,
|
Gold: gold,
|
||||||
|
Act: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
result.mapEntity.uuid = id
|
result.mapEntity.uuid = id
|
||||||
|
@ -30,6 +30,7 @@ type Player struct {
|
|||||||
isRunning bool
|
isRunning bool
|
||||||
isCasting bool
|
isCasting bool
|
||||||
onFinishedCasting func()
|
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.
|
// run speed should be walkspeed * 1.5, since in the original game it is 6 yards walk and 9 yards run.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package d2records
|
package d2records
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,7 +28,14 @@ func difficultyLevelsLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
|||||||
LifeStealDivisor: d.Number("LifeStealDivisor"),
|
LifeStealDivisor: d.Number("LifeStealDivisor"),
|
||||||
ManaStealDivisor: d.Number("ManaStealDivisor"),
|
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 {
|
if d.Err != nil {
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package d2records
|
package d2records
|
||||||
|
|
||||||
|
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
|
|
||||||
// DifficultyLevels contain the difficulty records for each difficulty
|
// 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
|
// DifficultyLevelRecord contain the parameters that change for different difficulties
|
||||||
type DifficultyLevelRecord struct {
|
type DifficultyLevelRecord struct {
|
||||||
|
@ -343,7 +343,7 @@ func (v *Game) OnPlayerMove(targetX, targetY float64) {
|
|||||||
func (v *Game) OnPlayerSave() error {
|
func (v *Game) OnPlayerSave() error {
|
||||||
playerState := v.gameClient.Players[v.gameClient.PlayerID]
|
playerState := v.gameClient.Players[v.gameClient.PlayerID]
|
||||||
|
|
||||||
sp, err := d2netpacket.CreateSavePlayerPacket(playerState)
|
sp, err := d2netpacket.CreateSavePlayerPacket(playerState, d2enum.DifficultyNormal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("SavePlayerPacket: %v", err)
|
return fmt.Errorf("SavePlayerPacket: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package d2netpacket
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity"
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||||
)
|
)
|
||||||
@ -10,13 +12,15 @@ import (
|
|||||||
// SavePlayerPacket has the actual selected left and right skill
|
// SavePlayerPacket has the actual selected left and right skill
|
||||||
// the Server has to check if these skills are actually allowed for the Player
|
// the Server has to check if these skills are actually allowed for the Player
|
||||||
type SavePlayerPacket struct {
|
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
|
// 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{
|
savePlayerData := SavePlayerPacket{
|
||||||
Player: playerState,
|
Player: playerState,
|
||||||
|
Difficulty: difficulty,
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := json.Marshal(savePlayerData)
|
b, err := json.Marshal(savePlayerData)
|
||||||
|
@ -483,6 +483,8 @@ func (g *GameServer) OnPacketReceived(client ClientConnection, packet d2netpacke
|
|||||||
playerState.LeftSkill = savePacket.Player.LeftSkill.Shallow.SkillID
|
playerState.LeftSkill = savePacket.Player.LeftSkill.Shallow.SkillID
|
||||||
playerState.RightSkill = savePacket.Player.RightSkill.Shallow.SkillID
|
playerState.RightSkill = savePacket.Player.RightSkill.Shallow.SkillID
|
||||||
playerState.Stats = savePacket.Player.Stats
|
playerState.Stats = savePacket.Player.Stats
|
||||||
|
playerState.Act = savePacket.Player.Act
|
||||||
|
playerState.Difficulty = savePacket.Difficulty
|
||||||
|
|
||||||
err = g.heroStateFactory.Save(playerState)
|
err = g.heroStateFactory.Save(playerState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user