-
Notifications
You must be signed in to change notification settings - Fork 0
/
drop.go
85 lines (79 loc) · 1.76 KB
/
drop.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
package events
// Drop events
import (
"github.com/qbradq/sharduo/internal/game"
"github.com/qbradq/sharduo/lib/uo"
)
func init() {
reg("DropToContainer", DropToContainer)
reg("DropToPlayer", DropToPlayer)
reg("DropToPackAnimal", DropToPackAnimal)
}
func DropToContainer(receiver, source game.Object, v any) bool {
rc, ok := receiver.(game.Container)
if !ok {
return false
}
sm, ok := source.(game.Mobile)
if !ok {
return false
}
item, ok := v.(game.Item)
if !ok {
return false
}
if sm.Location().XYDistance(item.Location()) > uo.MaxDropRange {
return false
}
if !sm.CanAccess(rc) {
return false
}
// Line of sight check
if !sm.HasLineOfSight(rc) {
sm.NetState().Cliloc(nil, 500950) // You cannot see that.
return false
}
return rc.AddObject(item)
}
func DropToPlayer(receiver, source game.Object, v any) bool {
rm, ok := receiver.(game.Mobile)
if !ok {
return false
}
sm, ok := source.(game.Mobile)
if !ok {
return false
}
item, ok := v.(game.Item)
if !ok {
return false
}
if rm.Serial() == sm.Serial() {
// Drop to self, just put it in the backpack
return rm.DropToBackpack(item, false)
} else if sm.IsPlayerCharacter() {
// TODO Secure trade
return false
} // Else this is a non-player mobile trying to drop something on us. This
// should not happen.
return false
}
func DropToPackAnimal(receiver, source game.Object, v any) bool {
rm, ok := receiver.(game.Mobile)
if !ok {
return false
}
sm, ok := source.(game.Mobile)
if !ok {
return false
}
// Check control master
if rm.ControlMaster().Serial() != sm.Serial() {
return false
}
item, ok := v.(game.Item)
if !ok {
return false
}
return rm.DropToBackpack(item, false)
}