mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-04 17:27:16 -05:00
88326b5278
* Casting a skill now plays the corresponding overlay(if any). * Prevent a crash caused by nil pointer in HeroSkill deserialization, happening when unmarshalling HeroSkill from packets as a remote client. * Add PlayerAnimationModeNone to handle some of the Skills(e.g. Paladin auras) having "" as animation mode. * Joining a game as remote client now waits for map generation to finish before rendering map or processing map entities. This is temporary hack to prevent the game from crashing due to concurrent map read & write exception. * Send CastSkill packet to other clients. Co-authored-by: Presiyan Ivanov <presiyan-ivanov@users.noreply.github.com>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package d2hero
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
|
)
|
|
|
|
// HeroSkill stores additional payload for a skill of a hero.
|
|
type HeroSkill struct {
|
|
*d2records.SkillRecord
|
|
*d2records.SkillDescriptionRecord
|
|
SkillPoints int
|
|
shallow *shallowHeroSkill
|
|
}
|
|
|
|
// An auxilary struct which only stores the ID of the SkillRecord, instead of the whole SkillRecord and SkillDescrptionRecord.
|
|
type shallowHeroSkill struct {
|
|
SkillID int `json:"skillId"`
|
|
SkillPoints int `json:"skillPoints"`
|
|
}
|
|
|
|
// 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)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
return bytes, err
|
|
}
|
|
|
|
// UnmarshalJSON overrides the default logic used when the HeroSkill is deserialized from a byte array.
|
|
func (hs *HeroSkill) UnmarshalJSON(data []byte) error {
|
|
shallow := &shallowHeroSkill{}
|
|
if err := json.Unmarshal(data, shallow); err != nil {
|
|
return err
|
|
}
|
|
|
|
hs.shallow = shallow
|
|
|
|
return nil
|
|
}
|