-
Notifications
You must be signed in to change notification settings - Fork 0
/
activeobject_serialize.go
103 lines (89 loc) · 3.22 KB
/
activeobject_serialize.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2014,2015,2016,2017,2018,2019,2020,2021 SeukWon Kang (kasworld@gmail.com)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package activeobject
import (
"github.com/kasworld/goguelike-single/enum/achievetype"
"github.com/kasworld/goguelike-single/enum/condition_flag"
"github.com/kasworld/goguelike-single/enum/turnresulttype"
"github.com/kasworld/goguelike-single/game/aoexpsort"
"github.com/kasworld/goguelike-single/game/csprotocol"
)
func (ao *ActiveObject) ToPacket_ActiveObjClient(x, y int) *csprotocol.ActiveObjClient {
if ao.aoClientCache != nil {
return ao.aoClientCache
}
cnf := ao.AOTurnData.Condition
cnf.ClearByConditionFlag(condition_flag.HideOther())
aoc := &csprotocol.ActiveObjClient{
UUID: ao.uuid,
NickName: ao.nickName,
Faction: ao.currentBias.NearFaction(),
EquippedPo: ao.inven.ToPacket_EquipClient(),
Conditions: cnf,
X: x,
Y: y,
Alive: ao.IsAlive(),
Chat: ao.chat,
}
if stepAct := ao.turnActReqRsp; stepAct != nil && stepAct.Acted {
aoc.Act = stepAct.Done.Act
aoc.Dir = stepAct.Done.Dir
aoc.Result = stepAct.Error
}
var DamageGive float64
var DamageTake float64
for _, v := range ao.turnResultList {
switch v.GetTurnResultType() {
case turnresulttype.AttackTo:
DamageGive += v.GetDamage()
case turnresulttype.AttackedFrom:
DamageTake += v.GetDamage()
case turnresulttype.DamagedByTile:
DamageTake += v.GetDamage()
}
}
aoc.DamageGive = int(DamageGive)
aoc.DamageTake = int(DamageTake)
ao.aoClientCache = aoc
return aoc
}
func (ao *ActiveObject) ToPacket_PlayerActiveObjInfo() *csprotocol.PlayerActiveObjInfo {
aoList := ao.GetHomeFloor().GetTower().GetExpRanking()
rank := aoexpsort.ByExp(aoList).FindPosByKey(ao.AOTurnData.TotalExp)
cnf := ao.AOTurnData.Condition
cnf.ClearByConditionFlag(condition_flag.HideSelf())
rtn := csprotocol.PlayerActiveObjInfo{
Bias: ao.currentBias,
Conditions: cnf,
Exp: int(ao.AOTurnData.TotalExp),
Ranking: rank,
TotalAO: len(aoList),
Death: int(ao.achieveStat.Get(achievetype.Death)),
Kill: int(ao.achieveStat.Get(achievetype.Kill)),
Sight: ao.AOTurnData.Sight,
HP: ao.hp,
HPMax: ao.AOTurnData.HPMax,
SP: ao.sp,
SPMax: ao.AOTurnData.SPMax,
AIPlan: ao.ai.RunningPlanList.GetCurrentPlan(),
Act: ao.turnActReqRsp,
AP: ao.ap,
}
rtn.Wealth = int(ao.inven.GetTotalValue())
rtn.EquippedPo, rtn.EquipBag, rtn.PotionBag, rtn.ScrollBag, rtn.Wallet = ao.inven.ToPacket_InvenInfos()
rtn.TurnResult = make([]csprotocol.TurnResultClient,
0, len(ao.turnResultList))
for _, v := range ao.turnResultList {
rtn.TurnResult = append(rtn.TurnResult, v.ToPacket_TurnResultClient())
}
rtn.ActiveBuff = ao.buffManager.ToPacket_ActiveObjBuffList()
return &rtn
}