Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions src/boost/stones.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,12 @@ func applyIdealStoneMix(as *artifactSet, layingRate, shippingRate, everyoneDefle
bestI := 0
var bestLR, bestSR float64
for i := 0; i <= as.stones; i++ {
stoneLayRate := layingRate
stoneLayRate := layingRate * math.Pow(stoneBonusIncrease, float64(i))
stoneShipRate := shippingRate * math.Pow(stoneBonusIncrease, float64(as.stones-i))
if !privateFarm {
stoneLayRate *= (1 + (everyoneDeflectorPercent-as.deflector.percent)/100.0)
stoneLayRate *= (1 + (everyoneDeflectorPercent-as.deflector.percent)/100.0) * as.colleggBuffs.ELR
stoneShipRate *= as.colleggBuffs.SR
}
stoneLayRate *= math.Pow(stoneBonusIncrease, float64(i)) * as.colleggBuffs.ELR * as.colleggBuffs.Hab

stoneShipRate := shippingRate * math.Pow(stoneBonusIncrease, float64((as.stones-i))) * as.colleggBuffs.SR

bestMin := min(stoneLayRate, stoneShipRate)
if bestMin > bestTotal {
Expand All @@ -284,13 +283,12 @@ func applyIdealStoneMix(as *artifactSet, layingRate, shippingRate, everyoneDefle
chosenSR := bestSR

if tStones >= 0 && tStones <= as.stones && bestTotal > 0 {
stoneLayRate := layingRate
stoneLayRate := layingRate * math.Pow(stoneBonusIncrease, float64(tStones))
stoneShipRate := shippingRate * math.Pow(stoneBonusIncrease, float64(as.stones-tStones))
if !privateFarm {
stoneLayRate *= (1 + (everyoneDeflectorPercent-as.deflector.percent)/100.0)
stoneLayRate *= (1 + (everyoneDeflectorPercent-as.deflector.percent)/100.0) * as.colleggBuffs.ELR
stoneShipRate *= as.colleggBuffs.SR
}
stoneLayRate *= math.Pow(stoneBonusIncrease, float64(tStones)) * as.colleggBuffs.ELR * as.colleggBuffs.Hab

stoneShipRate := shippingRate * math.Pow(stoneBonusIncrease, float64((as.stones-tStones))) * as.colleggBuffs.SR

playerMin := min(stoneLayRate, stoneShipRate)
// Check if player's mix is within 1e-7 relative difference of the maximum rate
Expand Down Expand Up @@ -798,21 +796,27 @@ func renderCoopStatusStones(channelID string, contractID string, coopStatus *ei.
continue
}
isDeparted := as.name == "[departed]" || as.nameRaw == "[departed]"
// need to reduce the farm population by the gusset percent
unmodifiedPop := as.farmPopulation / (1 + as.gusset.percent/100.0)
as.baseLayingRate = as.userLayRate * min(unmodifiedPop, as.baseHab) * 3600.0 / 1e15
if as.baseHab > 0 {
as.baseLayingRate = as.userLayRate * as.farmPopulation * 3600.0 / 1e15
} else {
as.baseLayingRate = 0
}

layingRate := (as.baseLayingRate) * (1 + as.metronome.percent/100.0) * (1 + as.gusset.percent/100.0) * eiContract.Grade[grade].ModifierELR
layingRate := as.baseLayingRate * (1 + as.metronome.percent/100.0) * eiContract.Grade[grade].ModifierELR
shippingRate := (as.baseShippingRate) * (1 + as.compass.percent/100.0) * eiContract.Grade[grade].ModifierSR

privateFarm := false
// Determine Colleggtible Increase
if as.fallbackCollegg {
collegHab := as.farmCapacity / (as.baseHab * (1 + as.gusset.percent/100.0))
if collegHab < 1.00 {
collegHab = 1.00
if as.baseHab > 0.0 {
collegHab := as.farmCapacity / (as.baseHab * (1 + as.gusset.percent/100.0))
if collegHab < 1.00 {
collegHab = 1.00
}
as.colleggBuffs.Hab = math.Round(collegHab*precisionConst) / precisionConst
} else {
as.colleggBuffs.Hab = 1.0
}
as.colleggBuffs.Hab = math.Round(collegHab*precisionConst) / precisionConst
}
if maxColleggtibleHab > 1.0 {
roundedCollegHab := math.Round(as.colleggBuffs.Hab*precisionConst) / precisionConst
Expand All @@ -833,7 +837,7 @@ func renderCoopStatusStones(channelID string, contractID string, coopStatus *ei.
stoneLayRateNow *= math.Pow(1.02, float64(as.tachStones[ei.ArtifactSpec_INFERIOR]))
stoneLayRateNow *= math.Pow(1.04, float64(as.tachStones[ei.ArtifactSpec_LESSER]))
stoneLayRateNow *= math.Pow(1.05, float64(as.tachStones[ei.ArtifactSpec_NORMAL]))
chickELR := as.elr * as.farmPopulation * eiContract.Grade[grade].ModifierHabCap * 3600.0 / 1e15
chickELR := as.elr * as.farmPopulation * 3600.0 / 1e15

if stoneLayRateNow == 0.0 {
privateFarm = true
Expand All @@ -842,8 +846,8 @@ func renderCoopStatusStones(channelID string, contractID string, coopStatus *ei.
layingRate = stoneLayRateNow
}
if as.fallbackCollegg {
if stoneLayRateNow > 0.0 && as.colleggBuffs.Hab > 0.0 {
collegELR := chickELR / (stoneLayRateNow * as.colleggBuffs.Hab)
if stoneLayRateNow > 0.0 {
collegELR := chickELR / stoneLayRateNow
as.colleggBuffs.ELR = math.Round(collegELR*precisionConst) / precisionConst
} else {
as.colleggBuffs.ELR = 1.0
Expand Down Expand Up @@ -904,10 +908,12 @@ func renderCoopStatusStones(channelID string, contractID string, coopStatus *ei.
stoneBonusIncrease := applyIdealStoneMix(&as, layingRate, shippingRate, everyoneDeflectorPercent, privateFarm, artifactPercentLevels)

for i := 0; i <= as.stones; i++ {
stoneLayRate := layingRate * (1 + (everyoneDeflectorPercent-as.deflector.percent)/100.0)
stoneLayRate = stoneLayRate * math.Pow(1.05, float64(i)) * as.colleggBuffs.ELR * as.colleggBuffs.Hab

stoneShipRate := shippingRate * math.Pow(1.05, float64((as.stones-i))) * as.colleggBuffs.SR
stoneLayRate := layingRate * math.Pow(1.05, float64(i))
stoneShipRate := shippingRate * math.Pow(1.05, float64(as.stones-i))
if !privateFarm {
stoneLayRate *= (1 + (everyoneDeflectorPercent-as.deflector.percent)/100.0) * as.colleggBuffs.ELR
stoneShipRate *= as.colleggBuffs.SR
}

soloData := []string{
bottools.FitString(as.name, 12, bottools.StringAlignRight),
Expand Down
210 changes: 210 additions & 0 deletions src/boost/stones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,213 @@ func TestRenderCoopStatusStones_StoneSwapLegend(t *testing.T) {
t.Fatalf("expected result to contain %q, but got:\n%s", expectedLegendPart, result)
}
}

func TestRenderCoopStatusStones_PartialAndFullHabsWithColleggtibles(t *testing.T) {
// Ensure research definitions exist for hab capacity / lay rate / shipping rate calculations.
origResearches := ei.EggIncResearchesMap
ei.EggIncResearchesMap = map[string]ei.EggResearches{
"comfy_nests": {ID: "comfy_nests", Levels: 50, PerLevel: 0.10},
"epic_egg_laying": {ID: "epic_egg_laying", Levels: 20, PerLevel: 0.05},
"leafsprings": {ID: "leafsprings", Levels: 30, PerLevel: 0.05},
"hab_capacity1": {ID: "hab_capacity1", Levels: 8, PerLevel: 0.05},
"wormhole_dampening": {ID: "wormhole_dampening", Levels: 25, PerLevel: 0.02},
}
defer func() { ei.EggIncResearchesMap = origResearches }()

contractID := "test-stones-partial-hab-contract"
grades := make([]ei.ContractGrade, 6)
grades[int(ei.Contract_GRADE_AAA)] = ei.ContractGrade{
ModifierELR: 1.0,
ModifierSR: 1.0,
ModifierHabCap: 1.0,
TargetAmount: []float64{1e15},
LengthInSeconds: 86400,
}
if ei.EggIncContractsAll == nil {
ei.EggIncContractsAll = make(map[string]ei.EggIncContract)
}
ei.EggIncContractsAll[contractID] = ei.EggIncContract{
ID: contractID,
MinutesPerToken: 60,
ModifierELR: 1.0,
ModifierSR: 1.0,
ModifierHabCap: 1.0,
Grade: grades,
}

// Calculate exact expected LR and SR using the same research/vehicle helpers,
// and set ModifierELR / ModifierSR so PartialFarm's true LR (~4.082q) is just
// below SR (~4.217q), while inflating LR by colleggBuffs.Hab (1.05x) would
// push it above SR (~4.287q) and falsely report SR as the delivery rate.
vehicles := make([]uint32, 17)
trainLen := make([]uint32, 17)
for i := range vehicles {
vehicles[i] = 11
trainLen[i] = 10
}
commonRes := []*ei.Backup_ResearchItem{
{Id: proto.String("comfy_nests"), Level: proto.Uint32(50)},
{Id: proto.String("leafsprings"), Level: proto.Uint32(30)},
{Id: proto.String("hab_capacity1"), Level: proto.Uint32(8)},
{Id: proto.String("wormhole_dampening"), Level: proto.Uint32(25)},
}
epicRes := []*ei.Backup_ResearchItem{
{Id: proto.String("epic_egg_laying"), Level: proto.Uint32(20)},
}

userLayRate := (1.0 / 30.0) * ei.GetCommonResearchLayRate(commonRes) * ei.GetEpicResearchLayRate(epicRes)
// Choose ModifierELR so PartialFarm (pop = 2e9) has exact LR = 4.0824q/hr
// with T4L Metronome (+35%) and ELR Colleggtible (1.05).
partialPop := 2e9
fullPop := 6.615e9
modELR := 4.0824 / (userLayRate * partialPop * 3600.0 / 1e15 * 1.35 * 1.05)

univShip := ei.GetCommonResearchShippingRate(commonRes) * ei.GetEpicResearchShippingRate(epicRes)
hoverShip := ei.GetCommonResearchHoverOnlyMultiplier(commonRes)
hyperShip := ei.GetCommonResearchHyperloopOnlyMultiplier(commonRes)
baseShipCap, _ := ei.GetVehiclesShippingCapacity(vehicles, trainLen, univShip, hoverShip, hyperShip)
// Choose ModifierSR so SR = 4.2170q/hr with T4L Compass (+50%) and SR Colleggtible (1.05).
modSR := 4.2170 / (baseShipCap * 60.0 / 1e15 * 1.50 * 1.05)

grades[int(ei.Contract_GRADE_AAA)].ModifierELR = modELR
grades[int(ei.Contract_GRADE_AAA)].ModifierSR = modSR
ei.EggIncContractsAll[contractID] = ei.EggIncContract{
ID: contractID,
MinutesPerToken: 60,
ModifierELR: modELR,
ModifierSR: modSR,
ModifierHabCap: 1.0,
Grade: grades,
}

makeArtifacts := func() []*ei.CompleteArtifact {
return []*ei.CompleteArtifact{
{
Spec: &ei.ArtifactSpec{
Name: ei.ArtifactSpec_QUANTUM_METRONOME.Enum(),
Level: ei.ArtifactSpec_GREATER.Enum(),
Rarity: ei.ArtifactSpec_LEGENDARY.Enum(),
},
},
{
Spec: &ei.ArtifactSpec{
Name: ei.ArtifactSpec_INTERSTELLAR_COMPASS.Enum(),
Level: ei.ArtifactSpec_GREATER.Enum(),
Rarity: ei.ArtifactSpec_LEGENDARY.Enum(),
},
},
{
Spec: &ei.ArtifactSpec{
Name: ei.ArtifactSpec_ORNATE_GUSSET.Enum(),
Level: ei.ArtifactSpec_GREATER.Enum(),
Rarity: ei.ArtifactSpec_LEGENDARY.Enum(),
},
},
}
}

makeCollegg := func() *ei.PlayerColleggtibleInfo {
return &ei.PlayerColleggtibleInfo{
Buffs: []*ei.GameModifier{
{Dimension: ei.GameModifier_HAB_CAPACITY.Enum(), Value: proto.Float64(1.05)},
{Dimension: ei.GameModifier_EGG_LAYING_RATE.Enum(), Value: proto.Float64(1.05)},
{Dimension: ei.GameModifier_SHIPPING_CAPACITY.Enum(), Value: proto.Float64(1.05)},
},
}
}

coopStatus := &ei.ContractCoopStatusResponse{
ContractIdentifier: proto.String(contractID),
CoopIdentifier: proto.String("partial-hab-coop"),
ResponseStatus: ei.ContractCoopStatusResponse_NO_ERROR.Enum(),
Grade: ei.Contract_GRADE_AAA.Enum(),
Contributors: []*ei.ContractCoopStatusResponse_ContributionInfo{
{
UserId: proto.String("EI1000000000000001"),
UserName: proto.String("PartialFarm"),
ContributionAmount: proto.Float64(2e12),
ColleggtibleInfo: makeCollegg(),
FarmInfo: &ei.PlayerFarmInfo{
Habs: []uint32{18, 18, 18, 18},
Vehicles: vehicles,
TrainLength: trainLen,
CommonResearch: commonRes,
EpicResearch: epicRes,
EquippedArtifacts: makeArtifacts(),
},
ProductionParams: &ei.FarmProductionParams{
FarmPopulation: proto.Float64(partialPop),
FarmCapacity: proto.Float64(fullPop),
Elr: proto.Float64(4.0824e15 / (partialPop * 3600.0)),
Sr: proto.Float64(4.2170e15 / 3600.0),
},
},
{
UserId: proto.String("EI1000000000000002"),
UserName: proto.String("FullFarm"),
ContributionAmount: proto.Float64(3e12),
ColleggtibleInfo: makeCollegg(),
FarmInfo: &ei.PlayerFarmInfo{
Habs: []uint32{18, 18, 18, 18},
Vehicles: vehicles,
TrainLength: trainLen,
CommonResearch: commonRes,
EpicResearch: epicRes,
EquippedArtifacts: makeArtifacts(),
},
ProductionParams: &ei.FarmProductionParams{
FarmPopulation: proto.Float64(fullPop),
FarmCapacity: proto.Float64(fullPop),
Elr: proto.Float64(4.0824e15 / (partialPop * 3600.0)),
Sr: proto.Float64(4.2170e15 / 3600.0),
},
},
{
UserId: proto.String("EI1000000000000003"),
UserName: proto.String("PrivateFarm"),
ContributionAmount: proto.Float64(1e12),
ColleggtibleInfo: makeCollegg(),
FarmInfo: &ei.PlayerFarmInfo{},
ProductionParams: &ei.FarmProductionParams{
FarmPopulation: proto.Float64(4180839017),
FarmCapacity: proto.Float64(14883750000),
Elr: proto.Float64(4.906e15 / (4180839017.0 * 3600.0)),
Sr: proto.Float64(5.055e15 / 3600.0),
},
},
},
}

findTableRow := func(out, name string) string {
for _, line := range strings.Split(out, "\n") {
if strings.HasPrefix(line, "`") && !strings.HasPrefix(line, "```") && strings.Contains(line, name) {
return line
}
}
return ""
}

// Non-detailed view: ELR column should show true delivery rate min(LR, SR).
summaryOut, _, _ := renderCoopStatusStones("chan-test", contractID, coopStatus, false, "", false, "")
if row := findTableRow(summaryOut, "PartialFarm"); !strings.Contains(row, "4.082") {
t.Errorf("PartialFarm expected delivery rate 4.082 (not inflated by hab colleggtible to SR 4.217), got: %s", row)
}
if row := findTableRow(summaryOut, "FullFarm"); !strings.Contains(row, "4.217") {
t.Errorf("FullFarm expected delivery rate 4.217 (SR-capped), got: %s", row)
}
if row := findTableRow(summaryOut, "PrivateFarm"); !strings.Contains(row, "4.906") {
t.Errorf("PrivateFarm expected delivery rate 4.906 (not double-counted by colleggtibles), got: %s", row)
}

// Detailed view: LR column should show exact LR for partial, full, and private farms.
detailsOut, _, _ := renderCoopStatusStones("chan-test", contractID, coopStatus, true, "", false, "")
if row := findTableRow(detailsOut, "PartialFarm"); !strings.Contains(row, "4.082") || !strings.Contains(row, "4.217") {
t.Errorf("PartialFarm details expected LR 4.082 and SR 4.217, got: %s", row)
}
if row := findTableRow(detailsOut, "FullFarm"); !strings.Contains(row, "13.503") || !strings.Contains(row, "4.217") {
t.Errorf("FullFarm details expected LR 13.503 and SR 4.217, got: %s", row)
}
if row := findTableRow(detailsOut, "PrivateFarm"); !strings.Contains(row, "4.906") || !strings.Contains(row, "5.055") {
t.Errorf("PrivateFarm details expected LR 4.906 and SR 5.055, got: %s", row)
}
}
Loading