-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathshellfish_harvesting.java
More file actions
135 lines (131 loc) · 4.93 KB
/
shellfish_harvesting.java
File metadata and controls
135 lines (131 loc) · 4.93 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package script.harvesting;
import script.*;
import script.library.minigame;
import script.library.resource;
import script.library.utils;
public class shellfish_harvesting extends script.base_script
{
public shellfish_harvesting()
{
}
public static final string_id SID_USE = new string_id("sui", "use");
public static final string_id SID_FOUND_NOTHING = new string_id("harvesting", "found_nothing");
public static final string_id SID_FOUND_MOLLUSKS = new string_id("harvesting", "found_mollusks");
public static final string_id SID_FOUND_CRUSTACEANS = new string_id("harvesting", "found_crustaceans");
public static final string_id SID_SWIMMING = new string_id("harvesting", "swimming");
public static final string_id SID_INSIDE = new string_id("harvesting", "inside");
public static final string_id SID_IN_WATER = new string_id("harvesting", "in_water");
public static final string_id SID_SAMPLE_MIND = new string_id("error_message", "sample_mind");
public static final string_id SID_SURVEY_ON_MOUNT = new string_id("error_message", "survey_on_mount");
public static final string_id SID_BUSY = new string_id("harvesting", "busy");
public static final string_id SID_INV_FULL = new string_id("harvesting", "inv_full");
public static final int SAMPLE_ACTION_COST = 50;
public int OnObjectMenuRequest(obj_id self, obj_id player, menu_info mi) throws InterruptedException
{
if (!utils.isNestedWithin(self, player))
{
return SCRIPT_CONTINUE;
}
menu_info_data mid = mi.getMenuItemByType(menu_info_types.ITEM_USE);
if (mid != null)
{
mid.setServerNotify(true);
}
return SCRIPT_CONTINUE;
}
public int OnObjectMenuSelect(obj_id self, obj_id player, int item) throws InterruptedException
{
if (item == menu_info_types.ITEM_USE)
{
use(self, player);
return SCRIPT_CONTINUE;
}
return SCRIPT_CONTINUE;
}
public void use(obj_id self, obj_id player) throws InterruptedException
{
obj_id inventory = utils.getInventoryContainer(player);
if (getVolumeFree(inventory) <= 0)
{
sendSystemMessage(player, SID_INV_FULL);
return;
}
obj_id pInv = utils.getInventoryContainer(player);
if (!isIdValid(pInv))
{
return;
}
if (getState(player, STATE_SWIMMING) != 0)
{
sendSystemMessage(player, SID_SWIMMING);
return;
}
obj_id playerCurrentMount = getMountId(player);
if (isIdValid(playerCurrentMount))
{
sendSystemMessage(player, SID_SURVEY_ON_MOUNT);
return;
}
location here = getLocation(player);
if (here == null)
{
return;
}
if (isIdValid(here.cell))
{
sendSystemMessage(player, SID_INSIDE);
return;
}
if (!minigame.isLocationFishable(here))
{
sendSystemMessage(player, SID_IN_WATER);
return;
}
boolean harvesting = utils.hasScriptVar(player, "shellfish_harvesting");
if (harvesting)
{
sendSystemMessage(player, SID_BUSY);
return;
}
int action = getAttrib(player, ACTION);
int actioncost = SAMPLE_ACTION_COST;
if (!drainAttributes(player, actioncost, 0))
{
sendSystemMessage(player, SID_SAMPLE_MIND);
return;
}
utils.setScriptVar(player, "shellfish_harvesting", 1);
dictionary harvester = new dictionary();
harvester.put("player", player);
messageTo(self, "harvest", harvester, 5.0f, false);
}
public int harvest(obj_id self, dictionary params) throws InterruptedException
{
obj_id player = params.getObjId("player");
obj_id pInv = utils.getInventoryContainer(player);
if (!isIdValid(pInv))
{
return SCRIPT_CONTINUE;
}
location playerLocation = getLocation(player);
int searchRoll = rand(1, 100);
if (searchRoll < 25)
{
sendSystemMessage(player, SID_FOUND_NOTHING);
}
else if (searchRoll < 70)
{
sendSystemMessage(player, SID_FOUND_MOLLUSKS);
int amt = rand(8, 14);
resource.createRandom("seafood_mollusk_" + playerLocation.area, amt, playerLocation, pInv, player, 2);
}
else
{
sendSystemMessage(player, SID_FOUND_CRUSTACEANS);
int amt = rand(8, 14);
resource.createRandom("seafood_crustacean_" + playerLocation.area, amt, playerLocation, pInv, player, 2);
}
utils.removeScriptVar(player, "shellfish_harvesting");
return SCRIPT_CONTINUE;
}
}