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
420801b4
Commit
420801b4
authored
May 12, 2022
by
AnimeGitB
Committed by
Melledy
May 13, 2022
Browse files
Updated cost logic and default weights
parent
736ca853
Changes
4
Show whitespace changes
Inline
Side-by-side
data/Banners.json
View file @
420801b4
...
@@ -6,7 +6,9 @@
...
@@ -6,7 +6,9 @@
"prefabPath"
:
"GachaShowPanel_A022"
,
"prefabPath"
:
"GachaShowPanel_A022"
,
"previewPrefabPath"
:
"UI_Tab_GachaShowPanel_A022"
,
"previewPrefabPath"
:
"UI_Tab_GachaShowPanel_A022"
,
"titlePath"
:
"UI_GACHA_SHOW_PANEL_A022_TITLE"
,
"titlePath"
:
"UI_GACHA_SHOW_PANEL_A022_TITLE"
,
"costItem"
:
224
,
"costItemId"
:
224
,
"costItemAmount"
:
1
,
"costItemAmount10"
:
10
,
"beginTime"
:
0
,
"beginTime"
:
0
,
"endTime"
:
1924992000
,
"endTime"
:
1924992000
,
"sortId"
:
1000
,
"sortId"
:
1000
,
...
@@ -21,7 +23,7 @@
...
@@ -21,7 +23,7 @@
"prefabPath"
:
"GachaShowPanel_A079"
,
"prefabPath"
:
"GachaShowPanel_A079"
,
"previewPrefabPath"
:
"UI_Tab_GachaShowPanel_A079"
,
"previewPrefabPath"
:
"UI_Tab_GachaShowPanel_A079"
,
"titlePath"
:
"UI_GACHA_SHOW_PANEL_A048_TITLE"
,
"titlePath"
:
"UI_GACHA_SHOW_PANEL_A048_TITLE"
,
"costItem"
:
223
,
"costItem
Id
"
:
223
,
"beginTime"
:
0
,
"beginTime"
:
0
,
"endTime"
:
1924992000
,
"endTime"
:
1924992000
,
"sortId"
:
9998
,
"sortId"
:
9998
,
...
@@ -37,7 +39,7 @@
...
@@ -37,7 +39,7 @@
"prefabPath"
:
"GachaShowPanel_A080"
,
"prefabPath"
:
"GachaShowPanel_A080"
,
"previewPrefabPath"
:
"UI_Tab_GachaShowPanel_A080"
,
"previewPrefabPath"
:
"UI_Tab_GachaShowPanel_A080"
,
"titlePath"
:
"UI_GACHA_SHOW_PANEL_A021_TITLE"
,
"titlePath"
:
"UI_GACHA_SHOW_PANEL_A021_TITLE"
,
"costItem"
:
223
,
"costItem
Id
"
:
223
,
"beginTime"
:
0
,
"beginTime"
:
0
,
"endTime"
:
1924992000
,
"endTime"
:
1924992000
,
"sortId"
:
9997
,
"sortId"
:
9997
,
...
@@ -47,6 +49,7 @@
...
@@ -47,6 +49,7 @@
"rateUpItems4"
:
[
11401
,
12402
,
13407
,
14401
,
15401
],
"rateUpItems4"
:
[
11401
,
12402
,
13407
,
14401
,
15401
],
"rateUpItems5"
:
[
11509
,
12504
],
"rateUpItems5"
:
[
11509
,
12504
],
"fallbackItems5Pool1"
:
[],
"fallbackItems5Pool1"
:
[],
"weights4"
:
[[
1
,
600
],
[
7
,
600
],
[
8
,
6600
],
[
10
,
12600
]],
"weights5"
:
[[
1
,
100
],
[
62
,
100
],
[
73
,
7800
],
[
80
,
10000
]]
"weights5"
:
[[
1
,
100
],
[
62
,
100
],
[
73
,
7800
],
[
80
,
10000
]]
}
}
]
]
src/main/java/emu/grasscutter/game/gacha/GachaBanner.java
View file @
420801b4
...
@@ -6,6 +6,7 @@ import emu.grasscutter.utils.Utils;
...
@@ -6,6 +6,7 @@ import emu.grasscutter.utils.Utils;
import
static
emu
.
grasscutter
.
Configuration
.*;
import
static
emu
.
grasscutter
.
Configuration
.*;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.common.ItemParamData
;
import
emu.grasscutter.data.common.ItemParamData
;
public
class
GachaBanner
{
public
class
GachaBanner
{
...
@@ -145,25 +146,26 @@ public class GachaBanner {
...
@@ -145,25 +146,26 @@ public class GachaBanner {
+
"/gacha/details?s="
+
sessionKey
+
"&gachaType="
+
gachaType
;
+
"/gacha/details?s="
+
sessionKey
+
"&gachaType="
+
gachaType
;
// Grasscutter.getLogger().info("record = " + record);
// Grasscutter.getLogger().info("record = " + record);
ItemParamData
costItem1
=
this
.
getCost
(
1
);
ItemParamData
costItem10
=
this
.
getCost
(
10
);
GachaInfo
.
Builder
info
=
GachaInfo
.
newBuilder
()
GachaInfo
.
Builder
info
=
GachaInfo
.
newBuilder
()
.
setGachaType
(
this
.
getGachaType
())
.
setGachaType
(
this
.
getGachaType
())
.
setScheduleId
(
this
.
getScheduleId
())
.
setScheduleId
(
this
.
getScheduleId
())
.
setBeginTime
(
this
.
getBeginTime
())
.
setBeginTime
(
this
.
getBeginTime
())
.
setEndTime
(
this
.
getEndTime
())
.
setEndTime
(
this
.
getEndTime
())
.
setCostItemId
(
this
.
getCostItem
())
.
setCostItemId
(
costItem1
.
getId
())
.
setCostItemNum
(
1
)
.
setCostItemNum
(
costItem1
.
getCount
())
.
setTenCostItemId
(
costItem10
.
getId
())
.
setTenCostItemNum
(
costItem10
.
getCount
())
.
setGachaPrefabPath
(
this
.
getPrefabPath
())
.
setGachaPrefabPath
(
this
.
getPrefabPath
())
.
setGachaPreviewPrefabPath
(
this
.
getPreviewPrefabPath
())
.
setGachaPreviewPrefabPath
(
this
.
getPreviewPrefabPath
())
.
setGachaProbUrl
(
details
)
.
setGachaProbUrl
(
details
)
.
setGachaProbUrlOversea
(
details
)
.
setGachaProbUrlOversea
(
details
)
.
setGachaRecordUrl
(
record
)
.
setGachaRecordUrl
(
record
)
.
setGachaRecordUrlOversea
(
record
)
.
setGachaRecordUrlOversea
(
record
)
.
setTenCostItemId
(
this
.
getCostItem
())
.
setTenCostItemNum
(
10
)
.
setLeftGachaTimes
(
Integer
.
MAX_VALUE
)
.
setLeftGachaTimes
(
Integer
.
MAX_VALUE
)
.
setGachaTimesLimit
(
Integer
.
MAX_VALUE
)
.
setGachaTimesLimit
(
Integer
.
MAX_VALUE
)
.
setGachaSortId
(
this
.
getSortId
());
.
setGachaSortId
(
this
.
getSortId
());
if
(
this
.
getTitlePath
()
!=
null
)
{
if
(
this
.
getTitlePath
()
!=
null
)
{
info
.
setGachaTitlePath
(
this
.
getTitlePath
());
info
.
setGachaTitlePath
(
this
.
getTitlePath
());
}
}
...
...
src/main/java/emu/grasscutter/game/gacha/GachaManager.java
View file @
420801b4
...
@@ -4,6 +4,7 @@ import java.io.File;
...
@@ -4,6 +4,7 @@ import java.io.File;
import
java.io.FileReader
;
import
java.io.FileReader
;
import
java.nio.file.*
;
import
java.nio.file.*
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.ThreadLocalRandom
;
import
java.util.concurrent.ThreadLocalRandom
;
...
@@ -46,6 +47,8 @@ public class GachaManager {
...
@@ -46,6 +47,8 @@ public class GachaManager {
private
static
final
int
starglitterId
=
221
;
private
static
final
int
starglitterId
=
221
;
private
static
final
int
stardustId
=
222
;
private
static
final
int
stardustId
=
222
;
private
int
[]
fallbackItems4Pool2Default
=
{
11401
,
11402
,
11403
,
11405
,
12401
,
12402
,
12403
,
12405
,
13401
,
13407
,
14401
,
14402
,
14403
,
14409
,
15401
,
15402
,
15403
,
15405
};
private
int
[]
fallbackItems5Pool2Default
=
{
11501
,
11502
,
12501
,
12502
,
13502
,
13505
,
14501
,
14502
,
15501
,
15502
};
public
GachaManager
(
GameServer
server
)
{
public
GachaManager
(
GameServer
server
)
{
this
.
server
=
server
;
this
.
server
=
server
;
...
@@ -156,16 +159,16 @@ public class GachaManager {
...
@@ -156,16 +159,16 @@ public class GachaManager {
// Simple weighted selection with an upper bound for the roll that cuts off trailing entries
// Simple weighted selection with an upper bound for the roll that cuts off trailing entries
// All weights must be >= 0
// All weights must be >= 0
int
total
=
0
;
int
total
=
0
;
for
(
int
i
:
weights
)
{
for
(
int
weight
:
weights
)
{
if
(
i
<
0
)
{
if
(
weight
<
0
)
{
throw
new
IllegalArgumentException
(
"Weights must be non-negative!"
);
throw
new
IllegalArgumentException
(
"Weights must be non-negative!"
);
}
}
total
+=
i
;
total
+=
weight
;
}
}
int
roll
=
ThreadLocalRandom
.
current
().
nextInt
((
total
<
cutoff
)?
total
:
cutoff
);
int
roll
=
ThreadLocalRandom
.
current
().
nextInt
((
total
<
cutoff
)?
total
:
cutoff
);
int
subTotal
=
0
;
int
subTotal
=
0
;
for
(
int
i
:
weights
)
{
for
(
int
i
=
0
;
i
<
weights
.
length
;
i
++
)
{
subTotal
+=
i
;
subTotal
+=
weights
[
i
]
;
if
(
roll
<
subTotal
)
{
if
(
roll
<
subTotal
)
{
return
i
;
return
i
;
}
}
...
@@ -176,16 +179,22 @@ public class GachaManager {
...
@@ -176,16 +179,22 @@ public class GachaManager {
private
synchronized
int
doRarePull
(
int
[]
featured
,
int
[]
fallback1
,
int
[]
fallback2
,
int
rarity
,
GachaBanner
banner
,
PlayerGachaBannerInfo
gachaInfo
)
{
private
synchronized
int
doRarePull
(
int
[]
featured
,
int
[]
fallback1
,
int
[]
fallback2
,
int
rarity
,
GachaBanner
banner
,
PlayerGachaBannerInfo
gachaInfo
)
{
int
itemId
=
0
;
int
itemId
=
0
;
if
(
(
featured
.
length
>
0
)
boolean
pullFeatured
=
(
gachaInfo
.
getFailedFeaturedItemPulls
(
rarity
)
>=
1
)
// Lost previous coinflip
&&
(
gachaInfo
.
getFailedFeaturedItemPulls
(
rarity
)
>=
1
)
||
(
this
.
randomRange
(
1
,
100
)
<=
banner
.
getEventChance
(
rarity
));
// Won this coinflip
||
(
this
.
randomRange
(
1
,
100
)
<=
banner
.
getEventChance
(
rarity
)
))
{
if
(
pullFeatured
&&
(
featured
.
length
>
0
))
{
itemId
=
getRandom
(
featured
);
itemId
=
getRandom
(
featured
);
gachaInfo
.
setFailedFeaturedItemPulls
(
rarity
,
0
);
gachaInfo
.
setFailedFeaturedItemPulls
(
rarity
,
0
);
}
else
{
}
else
{
gachaInfo
.
addFailedFeaturedItemPulls
(
rarity
,
1
);
gachaInfo
.
addFailedFeaturedItemPulls
(
rarity
,
1
);
if
(
fallback1
.
length
<
1
)
{
if
(
fallback1
.
length
<
1
)
{
itemId
=
getRandom
(
fallback2
);
// Don't ever run an empty fallback2 btw
if
(
fallback2
.
length
<
1
)
{
itemId
=
getRandom
((
rarity
==
5
)?
fallbackItems5Pool2Default
:
fallbackItems4Pool2Default
);
}
else
{
}
else
{
itemId
=
getRandom
(
fallback2
);
}
}
else
if
(
fallback2
.
length
<
1
)
{
itemId
=
getRandom
(
fallback1
);
}
else
{
// Both pools are possible, use the pool balancer
int
pityPool1
=
banner
.
getPoolBalanceWeight
(
rarity
,
gachaInfo
.
getPityPool
(
rarity
,
1
));
int
pityPool1
=
banner
.
getPoolBalanceWeight
(
rarity
,
gachaInfo
.
getPityPool
(
rarity
,
1
));
int
pityPool2
=
banner
.
getPoolBalanceWeight
(
rarity
,
gachaInfo
.
getPityPool
(
rarity
,
2
));
int
pityPool2
=
banner
.
getPoolBalanceWeight
(
rarity
,
gachaInfo
.
getPityPool
(
rarity
,
2
));
int
chosenPool
=
switch
((
pityPool1
>=
pityPool2
)?
1
:
0
)
{
// Larger weight must come first for the hard cutoff to function correctly
int
chosenPool
=
switch
((
pityPool1
>=
pityPool2
)?
1
:
0
)
{
// Larger weight must come first for the hard cutoff to function correctly
...
@@ -245,6 +254,7 @@ public class GachaManager {
...
@@ -245,6 +254,7 @@ public class GachaManager {
// Spend currency
// Spend currency
ItemParamData
cost
=
banner
.
getCost
(
times
);
ItemParamData
cost
=
banner
.
getCost
(
times
);
if
(
cost
.
getCount
()
>
0
&&
!
inventory
.
payItem
(
cost
))
{
if
(
cost
.
getCount
()
>
0
&&
!
inventory
.
payItem
(
cost
))
{
player
.
sendPacket
(
new
PacketDoGachaRsp
());
return
;
return
;
}
}
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketDoGachaRsp.java
View file @
420801b4
...
@@ -2,6 +2,7 @@ package emu.grasscutter.server.packet.send;
...
@@ -2,6 +2,7 @@ package emu.grasscutter.server.packet.send;
import
java.util.List
;
import
java.util.List
;
import
emu.grasscutter.data.common.ItemParamData
;
import
emu.grasscutter.game.gacha.GachaBanner
;
import
emu.grasscutter.game.gacha.GachaBanner
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
...
@@ -14,16 +15,18 @@ public class PacketDoGachaRsp extends BasePacket {
...
@@ -14,16 +15,18 @@ public class PacketDoGachaRsp extends BasePacket {
public
PacketDoGachaRsp
(
GachaBanner
banner
,
List
<
GachaItem
>
list
)
{
public
PacketDoGachaRsp
(
GachaBanner
banner
,
List
<
GachaItem
>
list
)
{
super
(
PacketOpcodes
.
DoGachaRsp
);
super
(
PacketOpcodes
.
DoGachaRsp
);
ItemParamData
costItem
=
banner
.
getCost
(
1
);
ItemParamData
costItem10
=
banner
.
getCost
(
10
);
DoGachaRsp
p
=
DoGachaRsp
.
newBuilder
()
DoGachaRsp
p
=
DoGachaRsp
.
newBuilder
()
.
setGachaType
(
banner
.
getGachaType
())
.
setGachaType
(
banner
.
getGachaType
())
.
setGachaScheduleId
(
banner
.
getScheduleId
())
.
setGachaScheduleId
(
banner
.
getScheduleId
())
.
setGachaTimes
(
list
.
size
())
.
setGachaTimes
(
list
.
size
())
.
setNewGachaRandom
(
12345
)
.
setNewGachaRandom
(
12345
)
.
setLeftGachaTimes
(
Integer
.
MAX_VALUE
)
.
setLeftGachaTimes
(
Integer
.
MAX_VALUE
)
.
setCostItemId
(
banner
.
getC
ostItem
())
.
setCostItemId
(
c
ostItem
.
getId
())
.
setCostItemNum
(
1
)
.
setCostItemNum
(
costItem
.
getCount
()
)
.
setTenCostItemId
(
banner
.
getCostItem
())
.
setTenCostItemId
(
costItem10
.
getId
())
.
setTenCostItemNum
(
10
)
.
setTenCostItemNum
(
costItem10
.
getCount
()
)
.
addAllGachaItemList
(
list
)
.
addAllGachaItemList
(
list
)
.
build
();
.
build
();
...
...
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