Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
fc16f9d6
Commit
fc16f9d6
authored
Jul 19, 2022
by
Melledy
Browse files
Refactor out `InsectCaptureManager`
parent
f020cefd
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/data/common/ItemParamData.java
View file @
fc16f9d6
...
...
@@ -2,6 +2,7 @@ package emu.grasscutter.data.common;
import
com.google.gson.annotations.SerializedName
;
// Used in excels
public
class
ItemParamData
{
@SerializedName
(
value
=
"id"
,
alternate
={
"itemId"
})
private
int
id
;
...
...
@@ -10,6 +11,7 @@ public class ItemParamData {
private
int
count
;
public
ItemParamData
()
{}
public
ItemParamData
(
int
id
,
int
count
)
{
this
.
id
=
id
;
this
.
count
=
count
;
...
...
src/main/java/emu/grasscutter/data/excels/EnvAnimalGatherConfigData.java
View file @
fc16f9d6
...
...
@@ -4,37 +4,32 @@ import java.util.List;
import
emu.grasscutter.data.GameResource
;
import
emu.grasscutter.data.ResourceType
;
import
emu.grasscutter.data.common.ItemParamData
;
@ResourceType
(
name
=
"EnvAnimalGatherExcelConfigData.json"
,
loadPriority
=
ResourceType
.
LoadPriority
.
LOW
)
public
class
EnvAnimalGatherConfigData
extends
GameResource
{
private
int
animalId
;
private
String
entityType
;
private
List
<
GatherItem
>
gatherItemId
;
private
List
<
ItemParamData
>
gatherItemId
;
private
String
excludeWeathers
;
private
int
aliveTime
;
private
int
escapeTime
;
private
int
escapeRadius
;
@Override
public
int
getId
()
{
return
animalId
;
}
public
int
getAnimalId
(){
return
animalId
;
}
public
String
getEntityType
(){
return
entityType
;
}
public
GatherItem
gatherItem
(){
return
gatherItemId
.
get
(
0
);
}
public
static
class
GatherItem
{
private
int
id
;
private
int
count
;
public
int
getId
(){
return
id
;
}
public
int
getCount
(){
return
count
;
}
public
ItemParamData
getGatherItem
()
{
return
gatherItemId
.
size
()
>
0
?
gatherItemId
.
get
(
0
)
:
null
;
}
}
src/main/java/emu/grasscutter/game/entity/EntityMonster.java
View file @
fc16f9d6
package
emu.grasscutter.game.entity
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.common.ItemParamData
;
import
emu.grasscutter.data.common.PropGrowCurve
;
import
emu.grasscutter.data.excels.EnvAnimalGatherConfigData
;
import
emu.grasscutter.data.excels.ItemData
;
import
emu.grasscutter.data.excels.MonsterCurveData
;
import
emu.grasscutter.data.excels.MonsterData
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.props.EntityIdType
;
import
emu.grasscutter.game.props.FightProperty
;
import
emu.grasscutter.game.props.PlayerProperty
;
import
emu.grasscutter.game.props.WatcherTriggerType
;
import
emu.grasscutter.game.world.Scene
;
import
emu.grasscutter.net.proto.VisionTypeOuterClass
;
import
emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo
;
import
emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair
;
import
emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo
;
...
...
@@ -115,7 +122,15 @@ public class EntityMonster extends GameEntity {
@Override
public
void
onInteract
(
Player
player
,
GadgetInteractReq
interactReq
)
{
player
.
getInsectCaptureManager
().
arrestSmallCreature
(
this
);
EnvAnimalGatherConfigData
gatherData
=
GameData
.
getEnvAnimalGatherConfigDataMap
().
get
(
this
.
getMonsterData
().
getId
());
if
(
gatherData
==
null
)
{
return
;
}
player
.
getInventory
().
addItem
(
gatherData
.
getGatherItem
(),
ActionReason
.
SubfieldDrop
);
this
.
getScene
().
killEntity
(
this
);
}
@Override
...
...
src/main/java/emu/grasscutter/game/entity/EntityVehicle.java
View file @
fc16f9d6
...
...
@@ -84,11 +84,6 @@ public class EntityVehicle extends EntityBaseGadget {
return
this
.
rot
;
}
@Override
public
void
onInteract
(
Player
player
,
GadgetInteractReq
interactReq
)
{
player
.
getInsectCaptureManager
().
arrestSmallCreature
(
this
);
}
@Override
public
SceneEntityInfo
toProto
()
{
...
...
src/main/java/emu/grasscutter/game/inventory/Inventory.java
View file @
fc16f9d6
...
...
@@ -77,6 +77,10 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
}
public
boolean
addItem
(
int
itemId
,
int
count
)
{
return
addItem
(
itemId
,
count
,
null
);
}
public
boolean
addItem
(
int
itemId
,
int
count
,
ActionReason
reason
)
{
ItemData
itemData
=
GameData
.
getItemDataMap
().
get
(
itemId
);
if
(
itemData
==
null
)
{
...
...
@@ -85,9 +89,9 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
GameItem
item
=
new
GameItem
(
itemData
,
count
);
return
addItem
(
item
);
return
addItem
(
item
,
reason
);
}
public
boolean
addItem
(
GameItem
item
)
{
GameItem
result
=
putItem
(
item
);
...
...
@@ -120,6 +124,15 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
return
result
;
}
public
boolean
addItem
(
ItemParamData
itemParam
)
{
return
addItem
(
itemParam
,
null
);
}
public
boolean
addItem
(
ItemParamData
itemParam
,
ActionReason
reason
)
{
if
(
itemParam
==
null
)
return
false
;
return
addItem
(
itemParam
.
getId
(),
itemParam
.
getCount
(),
reason
);
}
public
void
addItems
(
Collection
<
GameItem
>
items
)
{
this
.
addItems
(
items
,
null
);
}
...
...
src/main/java/emu/grasscutter/game/managers/InsectCaptureManager.java
deleted
100644 → 0
View file @
f020cefd
package
emu.grasscutter.game.managers
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.excels.EnvAnimalGatherConfigData
;
import
emu.grasscutter.data.excels.ItemData
;
import
emu.grasscutter.game.entity.EntityMonster
;
import
emu.grasscutter.game.entity.EntityVehicle
;
import
emu.grasscutter.game.entity.GameEntity
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.player.BasePlayerManager
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.net.proto.VisionTypeOuterClass
;
public
class
InsectCaptureManager
extends
BasePlayerManager
{
public
InsectCaptureManager
(
Player
player
)
{
super
(
player
);
}
public
void
arrestSmallCreature
(
GameEntity
entity
)
{
//System.out.println("arrestSmallCreature!");
EnvAnimalGatherConfigData
gather
;
int
thingId
;
if
(
entity
instanceof
EntityMonster
monster
)
{
thingId
=
monster
.
getMonsterData
().
getId
();
gather
=
GameData
.
getEnvAnimalGatherConfigDataMap
().
get
(
thingId
);
}
else
if
(
entity
instanceof
EntityVehicle
gadget
)
{
thingId
=
gadget
.
getGadgetId
();
gather
=
GameData
.
getEnvAnimalGatherConfigDataMap
().
get
(
thingId
);
}
else
{
return
;
}
if
(
gather
==
null
)
{
Grasscutter
.
getLogger
().
warn
(
"monster/gather(id={}) couldn't be caught."
,
thingId
);
return
;
}
String
type
=
gather
.
getEntityType
();
if
((
type
.
equals
(
"Monster"
)
&&
entity
instanceof
EntityMonster
)
||
(
type
.
equals
(
"Gadget"
)
&&
entity
instanceof
EntityVehicle
))
{
EnvAnimalGatherConfigData
.
GatherItem
gatherItem
=
gather
.
gatherItem
();
ItemData
data
=
GameData
.
getItemDataMap
().
get
(
gatherItem
.
getId
());
GameItem
item
=
new
GameItem
(
data
,
gatherItem
.
getCount
());
player
.
getInventory
().
addItem
(
item
,
ActionReason
.
SubfieldDrop
);
entity
.
getScene
().
removeEntity
(
entity
,
VisionTypeOuterClass
.
VisionType
.
VISION_TYPE_REMOVE
);
}
else
{
Grasscutter
.
getLogger
().
warn
(
"monster/gather(id={}) has a wrong type."
,
thingId
);
}
}
}
src/main/java/emu/grasscutter/game/player/Player.java
View file @
fc16f9d6
...
...
@@ -30,7 +30,6 @@ import emu.grasscutter.game.mail.Mail;
import
emu.grasscutter.game.mail.MailHandler
;
import
emu.grasscutter.game.managers.CookingManager
;
import
emu.grasscutter.game.managers.FurnitureManager
;
import
emu.grasscutter.game.managers.InsectCaptureManager
;
import
emu.grasscutter.game.managers.ResinManager
;
import
emu.grasscutter.game.managers.collection.CollectionRecordStore
;
import
emu.grasscutter.game.managers.deforestation.DeforestationManager
;
...
...
@@ -142,7 +141,6 @@ public class Player {
@Getter
private
transient
QuestManager
questManager
;
@Getter
private
transient
TowerManager
towerManager
;
@Getter
private
transient
SotSManager
sotsManager
;
@Getter
private
transient
InsectCaptureManager
insectCaptureManager
;
@Getter
private
transient
MapMarksManager
mapMarksManager
;
@Getter
private
transient
StaminaManager
staminaManager
;
@Getter
private
transient
EnergyManager
energyManager
;
...
...
@@ -197,7 +195,6 @@ public class Player {
this
.
towerManager
=
new
TowerManager
(
this
);
this
.
abilityManager
=
new
AbilityManager
(
this
);
this
.
deforestationManager
=
new
DeforestationManager
(
this
);
this
.
insectCaptureManager
=
new
InsectCaptureManager
(
this
);
this
.
questManager
=
new
QuestManager
(
this
);
this
.
position
=
new
Position
(
GameConstants
.
START_POSITION
);
this
.
rotation
=
new
Position
(
0
,
307
,
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment