refactor(common): 重构 Conn 实体并优化地图进入逻辑
- 优化 Conn 实体的 SendPack 方法,提高代码复用性 - 添加 goja 模块到 go.work 文件 - 重构地图进入逻辑,增加玩家广播和刷怪功能 - 调整 OutInfo 结构中的 Vip 和 Viped 字段类型 - 简化 MonsterRefresh 结构体定义
This commit is contained in:
98
common/utils/goja/ipow.go
Normal file
98
common/utils/goja/ipow.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package goja
|
||||
|
||||
// inspired by https://gist.github.com/orlp/3551590
|
||||
|
||||
var overflows = [64]int64{
|
||||
9223372036854775807, 9223372036854775807, 3037000499, 2097151,
|
||||
55108, 6208, 1448, 511,
|
||||
234, 127, 78, 52,
|
||||
38, 28, 22, 18,
|
||||
15, 13, 11, 9,
|
||||
8, 7, 7, 6,
|
||||
6, 5, 5, 5,
|
||||
4, 4, 4, 4,
|
||||
3, 3, 3, 3,
|
||||
3, 3, 3, 3,
|
||||
2, 2, 2, 2,
|
||||
2, 2, 2, 2,
|
||||
2, 2, 2, 2,
|
||||
2, 2, 2, 2,
|
||||
2, 2, 2, 2,
|
||||
2, 2, 2, 2,
|
||||
}
|
||||
|
||||
var highestBitSet = [63]byte{
|
||||
0, 1, 2, 2, 3, 3, 3, 3,
|
||||
4, 4, 4, 4, 4, 4, 4, 4,
|
||||
5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5,
|
||||
6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6,
|
||||
}
|
||||
|
||||
func ipow(base, exp int64) (result int64) {
|
||||
if exp >= 63 {
|
||||
if base == 1 {
|
||||
return 1
|
||||
}
|
||||
|
||||
if base == -1 {
|
||||
return 1 - 2*(exp&1)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
if base > overflows[exp] || -base > overflows[exp] {
|
||||
return 0
|
||||
}
|
||||
|
||||
result = 1
|
||||
|
||||
switch highestBitSet[byte(exp)] {
|
||||
case 6:
|
||||
if exp&1 != 0 {
|
||||
result *= base
|
||||
}
|
||||
exp >>= 1
|
||||
base *= base
|
||||
fallthrough
|
||||
case 5:
|
||||
if exp&1 != 0 {
|
||||
result *= base
|
||||
}
|
||||
exp >>= 1
|
||||
base *= base
|
||||
fallthrough
|
||||
case 4:
|
||||
if exp&1 != 0 {
|
||||
result *= base
|
||||
}
|
||||
exp >>= 1
|
||||
base *= base
|
||||
fallthrough
|
||||
case 3:
|
||||
if exp&1 != 0 {
|
||||
result *= base
|
||||
}
|
||||
exp >>= 1
|
||||
base *= base
|
||||
fallthrough
|
||||
case 2:
|
||||
if exp&1 != 0 {
|
||||
result *= base
|
||||
}
|
||||
exp >>= 1
|
||||
base *= base
|
||||
fallthrough
|
||||
case 1:
|
||||
if exp&1 != 0 {
|
||||
result *= base
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
return result
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user