Documentation ¶
Index ¶
- Constants
- Variables
- func Abs[T int | int64](v T) T
- func SimAllBattles(fn string, totalval int, minpropval int) error
- func SimBattle(hero0 *Hero, hero1 *Hero) int
- type Battle
- func (battle *Battle) GenAliveHeroList(onhero FuncEachHeroBool) *HeroList
- func (battle *Battle) GenBuffInstanceID() BuffInstanceID
- func (battle *Battle) GenCurHeroList() *HeroList
- func (battle *Battle) GenHeroInstanceID() HeroInstanceID
- func (battle *Battle) GetTeam(index int) *Team
- func (battle *Battle) NewBuff(buffid BuffID, from *Hero, skill *Skill) (*Buff, error)
- func (battle *Battle) SetTeam(index int, lst []*HeroData, autoSetPos bool)
- func (battle *Battle) StartBattle()
- type BattleActionFromData
- type BattleLog
- func (bl *BattleLog) BattleEnd(parent *BattleLogNode) *BattleLogNode
- func (bl *BattleLog) BattleReady(parent *BattleLogNode) *BattleLogNode
- func (bl *BattleLog) EndTurn(parent *BattleLogNode, turn int) *BattleLogNode
- func (bl *BattleLog) FindSkillTarget(parent *BattleLogNode, src *Hero, target *Hero) *BattleLogNode
- func (bl *BattleLog) FindTarget(parent *BattleLogNode, src *Hero, target *Hero) *BattleLogNode
- func (bl *BattleLog) GenNodeID() BattleLogNodeID
- func (bl *BattleLog) HeroComeIn(parent *BattleLogNode, hero *Hero) *BattleLogNode
- func (bl *BattleLog) HeroMove(parent *BattleLogNode, src *Hero, target *Pos) *BattleLogNode
- func (bl *BattleLog) KillHero(parent *BattleLogNode, src *Hero, target *Hero, skill *Skill) *BattleLogNode
- func (bl *BattleLog) SaveJson(fn string) error
- func (bl *BattleLog) SaveText(fn string) error
- func (bl *BattleLog) SkillAttack(parent *BattleLogNode, src *Hero, target *Hero, skill *Skill, starthp int, ...) *BattleLogNode
- func (bl *BattleLog) StartBattle() *BattleLogNode
- func (bl *BattleLog) StartTurn(parent *BattleLogNode, turn int) *BattleLogNode
- func (bl *BattleLog) UseSkill(parent *BattleLogNode, src *Hero, skill *Skill) *BattleLogNode
- type BattleLogNode
- func (bln *BattleLogNode) GenString(tab string, tabnum int, ontext FuncOnText)
- func (bln *BattleLogNode) SetFromSkill(skill *Skill)
- func (bln *BattleLogNode) SetSrc(hero *Hero)
- func (bln *BattleLogNode) SetTarget(hero *Hero)
- func (bln *BattleLogNode) SetTargetPos(pos *Pos)
- func (bln *BattleLogNode) SetTargetSkill(skill *Skill)
- type BattleLogNodeID
- type BattleLogNodeType
- type Buff
- type BuffData
- type BuffDataMgr
- type BuffEffect
- type BuffID
- type BuffInstanceID
- type BuffList
- type BuffTriggerMap
- type FuncData
- type FuncEachHero
- type FuncEachHeroBool
- type FuncEachHeroSkill
- type FuncInitAllFuncs
- type FuncIsLess
- type FuncLib
- type FuncLibInit
- type FuncLibProc
- type FuncMgr
- type FuncOnText
- type Hero
- func (hero *Hero) Attack(toHero *Hero) bool
- func (hero *Hero) CanAttackWithDistance(toHero *Hero) bool
- func (hero *Hero) CanMove() bool
- func (hero *Hero) Clone() *Hero
- func (hero *Hero) FindFar(lst0 *HeroList, num int) *HeroList
- func (hero *Hero) FindNear(lst0 *HeroList, num int) *HeroList
- func (hero *Hero) FindTarget() *HeroList
- func (hero *Hero) ForEachSkills(oneach FuncEachHeroSkill) bool
- func (hero *Hero) GetEnemyTeamIndex() int
- func (hero *Hero) GetRealPos() *Pos
- func (hero *Hero) IsAlive() bool
- func (hero *Hero) IsMe(h *Hero) bool
- func (hero *Hero) Move2Target(target *Hero) *Pos
- func (hero *Hero) OnPropChg(pt PropType, startval int, endval int, fd *BattleActionFromData)
- func (hero *Hero) UseSkill(parent *BattleLogNode, skill *Skill)
- type HeroData
- type HeroDataMgr
- type HeroID
- type HeroInstanceID
- type HeroList
- func (hl *HeroList) AddHero(h *Hero) error
- func (hl *HeroList) Clone() *HeroList
- func (hl *HeroList) CloneEx(onhero FuncEachHeroBool) *HeroList
- func (hl *HeroList) Find(h *Hero) int
- func (hl *HeroList) ForEach(oneach FuncEachHero)
- func (hl *HeroList) ForEachWithBreak(oneach FuncEachHeroBool) bool
- func (hl *HeroList) Format() *HeroList
- func (hl *HeroList) GetAliveHeros() *HeroList
- func (hl *HeroList) GetNum() int
- func (hl *HeroList) Init(battle *Battle, lst []*HeroData)
- func (hl *HeroList) IsEmpty() bool
- func (hl *HeroList) RemoveHero(h *Hero)
- func (hl *HeroList) Sort(isless FuncIsLess)
- func (hl *HeroList) SortInAutoSetPos()
- func (hl *HeroList) SortInAutoSetPosSlow()
- func (hl *HeroList) SortInBattle()
- type LibFuncParams
- type Pos
- type PropType
- type ReleaseSkillType
- type Scene
- type Skill
- type SkillData
- type SkillDataMgr
- type SkillID
- type SkillType
- type StaticMgr
- type TargetType
- type Team
- type TriggerData
- type TriggerType
Constants ¶
View Source
const ( MaxTurn = 10 // 最大回合数为10 SceneWidth = 7 // 宽度 SceneHeight = 3 // 高度 )
View Source
const ( BuffEffectUnknow = 0 BuffEffectTaunt = 1 BuffEffectChgDamage = 2 )
Variables ¶
View Source
var ( // ErrInvalidFuncName - invalid func name ErrInvalidFuncName = errors.New("invalid func name") // ErrInvalidBuffID - invalid buffid ErrInvalidBuffID = errors.New("invalid buffid") // ErrInvalidFuncValsLength - invalid funcvals length ErrInvalidFuncValsLength = errors.New("invalid funcvals length") // ErrHeroIsNull - null hero ErrHeroIsNull = errors.New("null hero") // ErrDuplicateHero - duplicate hero ErrDuplicateHero = errors.New("duplicate hero") // ErrInvalidBuffEffectString - invalid Buff Effect string ErrInvalidBuffEffectString = errors.New("invalid Buff Effect string") )
View Source
var MapPropTypeStr map[PropType]string
Functions ¶
Types ¶
type Battle ¶
type Battle struct { Scene *Scene Log *BattleLog CurTurn int // contains filtered or unexported fields }
func NewBattleEx ¶
func (*Battle) GenAliveHeroList ¶
func (battle *Battle) GenAliveHeroList(onhero FuncEachHeroBool) *HeroList
func (*Battle) GenBuffInstanceID ¶
func (battle *Battle) GenBuffInstanceID() BuffInstanceID
func (*Battle) GenCurHeroList ¶
func (*Battle) GenHeroInstanceID ¶
func (battle *Battle) GenHeroInstanceID() HeroInstanceID
func (*Battle) StartBattle ¶
func (battle *Battle) StartBattle()
type BattleActionFromData ¶
type BattleActionFromData struct { Parent *BattleLogNode Hero *Hero Skill *Skill }
func NewBattleActionFromData ¶
func NewBattleActionFromData(parent *BattleLogNode, hero *Hero, skill *Skill) *BattleActionFromData
type BattleLog ¶
type BattleLog struct { Root *BattleLogNode `json:"root"` HashCode string `json:"hashcode"` // contains filtered or unexported fields }
func NewBattleLog ¶
func NewBattleLog() *BattleLog
func (*BattleLog) BattleEnd ¶
func (bl *BattleLog) BattleEnd(parent *BattleLogNode) *BattleLogNode
func (*BattleLog) BattleReady ¶
func (bl *BattleLog) BattleReady(parent *BattleLogNode) *BattleLogNode
func (*BattleLog) EndTurn ¶
func (bl *BattleLog) EndTurn(parent *BattleLogNode, turn int) *BattleLogNode
func (*BattleLog) FindSkillTarget ¶
func (bl *BattleLog) FindSkillTarget(parent *BattleLogNode, src *Hero, target *Hero) *BattleLogNode
func (*BattleLog) FindTarget ¶
func (bl *BattleLog) FindTarget(parent *BattleLogNode, src *Hero, target *Hero) *BattleLogNode
func (*BattleLog) GenNodeID ¶
func (bl *BattleLog) GenNodeID() BattleLogNodeID
func (*BattleLog) HeroComeIn ¶
func (bl *BattleLog) HeroComeIn(parent *BattleLogNode, hero *Hero) *BattleLogNode
func (*BattleLog) HeroMove ¶
func (bl *BattleLog) HeroMove(parent *BattleLogNode, src *Hero, target *Pos) *BattleLogNode
func (*BattleLog) KillHero ¶
func (bl *BattleLog) KillHero(parent *BattleLogNode, src *Hero, target *Hero, skill *Skill) *BattleLogNode
func (*BattleLog) SkillAttack ¶
func (bl *BattleLog) SkillAttack(parent *BattleLogNode, src *Hero, target *Hero, skill *Skill, starthp int, endhp int) *BattleLogNode
func (*BattleLog) StartBattle ¶
func (bl *BattleLog) StartBattle() *BattleLogNode
func (*BattleLog) StartTurn ¶
func (bl *BattleLog) StartTurn(parent *BattleLogNode, turn int) *BattleLogNode
func (*BattleLog) UseSkill ¶
func (bl *BattleLog) UseSkill(parent *BattleLogNode, src *Hero, skill *Skill) *BattleLogNode
type BattleLogNode ¶
type BattleLogNode struct { NodeID BattleLogNodeID `json:"nodeid"` Type BattleLogNodeType `json:"type"` Turn int `json:"turn,omitempty"` // turn从1开始,turnindex从0开始 SrcTeam int `json:"srcteam,omitempty"` SrcHeroID HeroID `json:"srcheroid,omitempty"` SrcHeroInstanceID HeroInstanceID `json:"srcheroinstanceid,omitempty"` SrcPos *Pos `json:"srcpos,omitempty"` TargetTeam int `json:"targetteam,omitempty"` TargetHeroID HeroID `json:"targetheroid,omitempty"` TargetHeroInstanceID HeroInstanceID `json:"targetheroinstanceid,omitempty"` TargetPos *Pos `json:"targetpos,omitempty"` Children []*BattleLogNode `json:"children,omitempty"` Props []PropType `json:"props,omitempty"` OldPropVals []int `json:"oldpropvals,omitempty"` PropVals []int `json:"propvals,omitempty"` TargetSkillID SkillID `json:"targetskillid,omitempty"` FromSkillID SkillID `json:"fromskillid,omitempty"` // contains filtered or unexported fields }
func (*BattleLogNode) GenString ¶
func (bln *BattleLogNode) GenString(tab string, tabnum int, ontext FuncOnText)
func (*BattleLogNode) SetFromSkill ¶
func (bln *BattleLogNode) SetFromSkill(skill *Skill)
func (*BattleLogNode) SetSrc ¶
func (bln *BattleLogNode) SetSrc(hero *Hero)
func (*BattleLogNode) SetTarget ¶
func (bln *BattleLogNode) SetTarget(hero *Hero)
func (*BattleLogNode) SetTargetPos ¶
func (bln *BattleLogNode) SetTargetPos(pos *Pos)
func (*BattleLogNode) SetTargetSkill ¶
func (bln *BattleLogNode) SetTargetSkill(skill *Skill)
type BattleLogNodeID ¶
type BattleLogNodeID int
type BattleLogNodeType ¶
type BattleLogNodeType int
const ( BLNTBattleStart BattleLogNodeType = 1 // 战斗开始,根节点,不需要额外的数据 BLNTHeroComeIn BattleLogNodeType = 2 // 角色进场 BLNTTurnStart BattleLogNodeType = 3 // 回合开始 BLNTTurnEnd BattleLogNodeType = 4 // 回合结束 BLNTHeroMove BattleLogNodeType = 5 // 角色主动移动 BLNTChgProp BattleLogNodeType = 6 // 改变属性 BLNTBattleReady BattleLogNodeType = 7 // 战斗开始后的准备阶段,也不需要额外的数据,处理角色上场及角色特性技能、被动技能释放、装备等 BLNTFindTarget BattleLogNodeType = 8 // 寻找目标 BLNTUseSkill BattleLogNodeType = 9 // 开始放技能 BLNTReadySkill BattleLogNodeType = 10 // 准备放技能 BLNTFindSkillTarget BattleLogNodeType = 11 // 寻找技能目标 BLNTSkillAttack BattleLogNodeType = 12 // 技能伤害 BLNTKillHero BattleLogNodeType = 13 // 击杀hero BLNTBattleEnd BattleLogNodeType = 14 // 战斗结束 )
type Buff ¶
type Buff struct { InstanceID BuffInstanceID Data *BuffData From *Hero FromSkill *Skill // contains filtered or unexported fields }
type BuffDataMgr ¶
type BuffDataMgr struct {
// contains filtered or unexported fields
}
func LoadBuffData ¶
func LoadBuffData(fn string) (*BuffDataMgr, error)
func (*BuffDataMgr) GetBuffData ¶
func (mgr *BuffDataMgr) GetBuffData(id BuffID) *BuffData
type BuffEffect ¶
type BuffEffect int
func Str2BuffEffect ¶
func Str2BuffEffect(str string) BuffEffect
type BuffInstanceID ¶
type BuffInstanceID int
type BuffList ¶
type BuffList struct {
Buffs []*Buff
}
func NewBuffList ¶
func NewBuffList() *BuffList
type BuffTriggerMap ¶
type BuffTriggerMap struct {
MapBuffs map[TriggerType]*BuffList
}
func NewBuffTriggerMap ¶
func NewBuffTriggerMap() *BuffTriggerMap
func (*BuffTriggerMap) Add ¶
func (btm *BuffTriggerMap) Add(trigger TriggerType, buff *Buff)
func (*BuffTriggerMap) AddEx ¶
func (btm *BuffTriggerMap) AddEx(buff *Buff)
func (*BuffTriggerMap) OnTrigger ¶
func (btm *BuffTriggerMap) OnTrigger(trigger TriggerType, params *LibFuncParams) (bool, error)
func (*BuffTriggerMap) RemoveAll ¶
func (btm *BuffTriggerMap) RemoveAll()
type FuncData ¶
type FuncEachHeroSkill ¶
遍历hero skills,返回false会break
type FuncInitAllFuncs ¶
type FuncIsLess ¶
type FuncLib ¶
type FuncLib struct { OnProc FuncLibProc OnInit FuncLibInit }
type FuncLibInit ¶
type FuncLibProc ¶
type FuncLibProc func(*FuncData, *LibFuncParams) (bool, error)
type FuncOnText ¶
type FuncOnText func(string)
type Hero ¶
type Hero struct { Battle *Battle ID HeroID Props map[PropType]int StaticPos *Pos // 初始坐标,按本地坐标来的,也就是2队人,这个坐标都是对自己在左边的 Pos *Pos // 坐标 TeamIndex int // 队伍索引,0-进攻方,1-防守方 InstanceID HeroInstanceID // 战斗里hero的唯一标识 Data *HeroData // 直接读表数据 Skills []*Skill // 技能 LastTarget *Hero // 上一次的目标 MapSingleState map[BuffEffect]*Buff // 简单状态 Trigger *BuffTriggerMap // contains filtered or unexported fields }
func (*Hero) CanAttackWithDistance ¶
是否可以攻击到
func (*Hero) ForEachSkills ¶
func (hero *Hero) ForEachSkills(oneach FuncEachHeroSkill) bool
func (*Hero) GetEnemyTeamIndex ¶
获取攻击队伍,可能会被混乱等状态影响,如果返回-1,表示所有队伍都需要选择
func (*Hero) GetRealPos ¶
func (*Hero) OnPropChg ¶
func (hero *Hero) OnPropChg(pt PropType, startval int, endval int, fd *BattleActionFromData)
func (*Hero) UseSkill ¶
func (hero *Hero) UseSkill(parent *BattleLogNode, skill *Skill)
type HeroData ¶
type HeroDataMgr ¶
type HeroDataMgr struct {
// contains filtered or unexported fields
}
func LoadHeroData ¶
func LoadHeroData(fn string) (*HeroDataMgr, error)
func (*HeroDataMgr) GetHeroData ¶
func (mgr *HeroDataMgr) GetHeroData(id HeroID) *HeroData
type HeroInstanceID ¶
type HeroInstanceID int
type HeroList ¶
type HeroList struct {
Heros []*Hero
}
func NewHeroList ¶
func NewHeroList() *HeroList
func NewHeroListEx ¶
func NewHeroListEx2 ¶
func (*HeroList) CloneEx ¶
func (hl *HeroList) CloneEx(onhero FuncEachHeroBool) *HeroList
func (*HeroList) ForEach ¶
func (hl *HeroList) ForEach(oneach FuncEachHero)
func (*HeroList) ForEachWithBreak ¶
func (hl *HeroList) ForEachWithBreak(oneach FuncEachHeroBool) bool
func (*HeroList) GetAliveHeros ¶
func (*HeroList) RemoveHero ¶
func (*HeroList) Sort ¶
func (hl *HeroList) Sort(isless FuncIsLess)
func (*HeroList) SortInAutoSetPos ¶
func (hl *HeroList) SortInAutoSetPos()
func (*HeroList) SortInAutoSetPosSlow ¶
func (hl *HeroList) SortInAutoSetPosSlow()
func (*HeroList) SortInBattle ¶
func (hl *HeroList) SortInBattle()
type LibFuncParams ¶
type LibFuncParams struct { Src *Hero Target *HeroList Battle *Battle LogParent *BattleLogNode Skill *Skill Results *HeroList TriggerData *TriggerData CacheVals []int }
func NewLibFuncParams ¶
func NewLibFuncParams(battle *Battle, src *Hero, target *HeroList, skill *Skill, parent *BattleLogNode, triggerdata *TriggerData) *LibFuncParams
type Pos ¶
关于位置 (x3,y1) (x2,y1) (x1,y1) (x3,y2) (x2,y2) (x1,y2) (x3,y3) (x2,y3) (x1,y3)
func (*Pos) CalcDistance ¶
type PropType ¶
type PropType int
const ( PropTypeNone PropType = 0 // none // 这一组是基本属性 PropTypeHP PropType = 1 // 初始HP PropTypeAtk PropType = 2 // 初始atk PropTypeDef PropType = 3 // 初始def PropTypeMagic PropType = 4 // 初始magic PropTypeSpeed PropType = 5 // 初始speed PropTypeDodge PropType = 6 // 初始闪避 PropTypeCrit PropType = 7 // 初始暴击 PropTypeMovDistance PropType = 20 // 移动距离 PropTypeAtkDistance PropType = 21 // 攻击距离 PropTypePlace PropType = 22 // 位置,1是前排、2是中排、3是后排 PropTypeAttackType PropType = 50 // 默认是物理攻击还是魔法攻击,0 表示物理,1 表示魔法 // 这一组是实际参与战斗的基本属性,一般是经过培养系统以后的值 PropTypeMaxHP PropType = 100 // 最大HP PropTypeCurHP PropType = 101 // 当前HP PropTypeCurAtk PropType = 102 // 当前atk PropTypeCurDef PropType = 103 // 当前def PropTypeCurMagic PropType = 104 // 当前magic PropTypeCurSpeed PropType = 105 // 当前speed PropTypeCurMovDistance PropType = 120 // 当前移动距离 PropTypeCurAtkDistance PropType = 121 // 当前攻击距离 PropTypeTeamSpeedVal PropType = 150 // 队伍速度值,快的队里这个值大于慢的队 // 状态值,是 或者 否 PropTypeTaunt PropType = 200 // 嘲讽 // 百分比附加属性 PropTypeReduceDamageToMe PropType = 300 // 减少受到伤害 PropTypeIncreaseDamage PropType = 301 // 增加造成伤害 )
func Str2PropType ¶
type ReleaseSkillType ¶
type ReleaseSkillType int
const ( ReleaseSkillTypeNormal ReleaseSkillType = 1 // 主动技能 ReleaseSkillTypePassive ReleaseSkillType = 2 // 被动 )
func Str2ReleaseSkillType ¶
func Str2ReleaseSkillType(str string) ReleaseSkillType
type SkillDataMgr ¶
type SkillDataMgr struct {
// contains filtered or unexported fields
}
func LoadSkillData ¶
func LoadSkillData(fn string) (*SkillDataMgr, error)
func (*SkillDataMgr) GetSkillData ¶
func (mgr *SkillDataMgr) GetSkillData(id SkillID) *SkillData
type StaticMgr ¶
type StaticMgr struct { MgrHeroData *HeroDataMgr MgrSkillData *SkillDataMgr MgrBuffData *BuffDataMgr MgrFunc *FuncMgr }
var MgrStatic *StaticMgr
func NewStaticMgr ¶
func NewStaticMgr(dir string, oninitallfuncs FuncInitAllFuncs) (*StaticMgr, error)
type TargetType ¶
type TargetType int
const ( TargetTypeEnemy TargetType = 1 // 敌人 TargetTypeFriend TargetType = 2 // 友方 TargetTypeAll TargetType = 3 // 不分敌我 )
type Team ¶
type Team struct { Heros *HeroList TeamIndex int Speed int SpeedVal int // contains filtered or unexported fields }
func (*Team) AutoSetPos ¶
func (team *Team) AutoSetPos()
func (*Team) CountSpeed ¶
func (*Team) SetTeamSpeedVal ¶
type TriggerData ¶
type TriggerData struct { Parent *TriggerData // 父节点,某些情况下,是A打B,B反击然后触发一个判断,所以这里需要有溯源机制 Trigger TriggerType // 类型 Turn int // 回合 Src *Hero // 源英雄,发起方,譬如攻击、寻敌等 Target *Hero // 目标英雄,受击方,被确定为目标等 SrcSkill *Skill // 源技能 SrcBuff *Buff // 源buff }
触发时数据,这里面的数据可以完整的表达任意时点
func NewTriggerDataFind ¶
func NewTriggerDataFind(turn int, src *Hero) *TriggerData
func NewTriggerDataTurnEnd ¶
func NewTriggerDataTurnEnd(turn int) *TriggerData
func NewTriggerDataTurnStart ¶
func NewTriggerDataTurnStart(turn int) *TriggerData
type TriggerType ¶
type TriggerType int
const ( TriggerTypeNone TriggerType = 0 // none TriggerTypeAttach TriggerType = 1 // attach buff时,buff在被附加时 TriggerTypeTurnStart TriggerType = 2 // 回合开始 TriggerTypeTurnEnd TriggerType = 3 // 回合结束 TriggerTypeFind TriggerType = 4 // 寻找目标时 )
func ParseTriggerList ¶
func ParseTriggerList(str string) []TriggerType
func Str2TriggerType ¶
func Str2TriggerType(str string) TriggerType
Source Files ¶
Click to show internal directories.
Click to hide internal directories.