mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-16 09:25:57 -05:00
Merge pull request #933 from ThomasChr/#865_save_mana
save player: level, health, mana, experience
This commit is contained in:
commit
34f9538afb
@ -12,7 +12,7 @@ type HeroSkill struct {
|
||||
*d2records.SkillRecord
|
||||
*d2records.SkillDescriptionRecord
|
||||
SkillPoints int
|
||||
shallow *shallowHeroSkill
|
||||
Shallow *shallowHeroSkill
|
||||
}
|
||||
|
||||
// An auxiliary struct which only stores the ID of the SkillRecord, instead of the whole SkillRecord
|
||||
@ -24,8 +24,8 @@ type shallowHeroSkill struct {
|
||||
|
||||
// MarshalJSON overrides the default logic used when the HeroSkill is serialized to a byte array.
|
||||
func (hs *HeroSkill) MarshalJSON() ([]byte, error) {
|
||||
// only serialize the shallow object instead of the SkillRecord & SkillDescriptionRecord
|
||||
bytes, err := json.Marshal(hs.shallow)
|
||||
// only serialize the Shallow object instead of the SkillRecord & SkillDescriptionRecord
|
||||
bytes, err := json.Marshal(hs.Shallow)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@ -40,7 +40,7 @@ func (hs *HeroSkill) UnmarshalJSON(data []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
hs.shallow = shallow
|
||||
hs.Shallow = shallow
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
type HeroState struct {
|
||||
HeroName string `json:"heroName"`
|
||||
HeroType d2enum.Hero `json:"heroType"`
|
||||
HeroLevel int `json:"heroLevel"`
|
||||
Act int `json:"act"`
|
||||
FilePath string `json:"-"`
|
||||
Equipment d2inventory.CharacterEquipment `json:"equipment"`
|
||||
|
@ -164,7 +164,7 @@ func (f *HeroStateFactory) CreateHeroSkill(points int, name string) (*HeroSkill,
|
||||
SkillPoints: points,
|
||||
SkillRecord: skillRecord,
|
||||
SkillDescriptionRecord: skillDescRecord,
|
||||
shallow: &shallowHeroSkill{SkillID: skillRecord.ID, SkillPoints: points},
|
||||
Shallow: &shallowHeroSkill{SkillID: skillRecord.ID, SkillPoints: points},
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@ -200,7 +200,7 @@ func (f *HeroStateFactory) LoadHeroState(filePath string) *HeroState {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Here, we turn the shallow skill data back into records from the asset manager.
|
||||
// Here, we turn the Shallow skill data back into records from the asset manager.
|
||||
// This is because this factory has a reference to the asset manager with loaded records.
|
||||
// We cant do this while unmarshalling because there is no reference to the asset manager.
|
||||
for idx := range result.Skills {
|
||||
@ -210,9 +210,9 @@ func (f *HeroStateFactory) LoadHeroState(filePath string) *HeroState {
|
||||
continue
|
||||
}
|
||||
|
||||
hs.SkillRecord = f.asset.Records.Skill.Details[hs.shallow.SkillID]
|
||||
hs.SkillRecord = f.asset.Records.Skill.Details[hs.Shallow.SkillID]
|
||||
hs.SkillDescriptionRecord = f.asset.Records.Skill.Descriptions[hs.SkillRecord.Skilldesc]
|
||||
hs.SkillPoints = hs.shallow.SkillPoints
|
||||
hs.SkillPoints = hs.Shallow.SkillPoints
|
||||
}
|
||||
|
||||
return result
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"image/color"
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
||||
|
||||
@ -346,7 +347,7 @@ func (v *CharacterSelect) updateCharacterBoxes() {
|
||||
}
|
||||
|
||||
heroName := v.gameStates[idx].HeroName
|
||||
heroInfo := "Level 1 " + v.gameStates[idx].HeroType.String()
|
||||
heroInfo := "Level " + strconv.FormatInt(int64(v.gameStates[idx].Stats.Level), 10) + " " + v.gameStates[idx].HeroType.String()
|
||||
|
||||
v.characterNameLabel[i].SetText(d2ui.ColorTokenize(heroName, d2ui.ColorTokenGold))
|
||||
v.characterStatsLabel[i].SetText(d2ui.ColorTokenize(heroInfo, d2ui.ColorTokenWhite))
|
||||
|
@ -11,15 +11,13 @@ 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 {
|
||||
LeftSkill int `json:"leftSkill"`
|
||||
RightSkill int `json:"rightSkill"`
|
||||
Player *d2mapentity.Player `json:"Player"`
|
||||
}
|
||||
|
||||
// CreateSavePlayerPacket sends a packet which instructs the server to save the Player
|
||||
func CreateSavePlayerPacket(playerState *d2mapentity.Player) NetPacket {
|
||||
savePlayerData := SavePlayerPacket{
|
||||
LeftSkill: playerState.LeftSkill.ID,
|
||||
RightSkill: playerState.RightSkill.ID,
|
||||
Player: playerState,
|
||||
}
|
||||
|
||||
b, err := json.Marshal(savePlayerData)
|
||||
|
@ -437,8 +437,9 @@ func (g *GameServer) OnPacketReceived(client ClientConnection, packet d2netpacke
|
||||
}
|
||||
|
||||
playerState := g.connections[client.GetUniqueID()].GetPlayerState()
|
||||
playerState.LeftSkill = savePacket.LeftSkill
|
||||
playerState.RightSkill = savePacket.RightSkill
|
||||
playerState.LeftSkill = savePacket.Player.LeftSkill.Shallow.SkillID
|
||||
playerState.RightSkill = savePacket.Player.RightSkill.Shallow.SkillID
|
||||
playerState.Stats = savePacket.Player.Stats
|
||||
|
||||
err = g.heroStateFactory.Save(playerState)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user