Compare commits
7 Commits
7588995c83
...
42e3a9b19e
| Author | SHA1 | Date |
|---|---|---|
|
|
42e3a9b19e | 1 month ago |
|
|
56b873153d | 1 month ago |
|
|
0ed54b458b | 1 month ago |
|
|
a5b5e8ba71 | 1 month ago |
|
|
a93e9a2520 | 1 month ago |
|
|
006bee5a5e | 1 month ago |
|
|
f0f610eb36 | 1 month ago |
Binary file not shown.
@ -0,0 +1,48 @@
|
||||
package changelog
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"sync"
|
||||
)
|
||||
|
||||
//go:embed data/changelog.json
|
||||
var embedded []byte
|
||||
|
||||
// Release is one curated release note block keyed by Version (must match internal/version.Version when you want it shown).
|
||||
type Release struct {
|
||||
Version string `json:"version"`
|
||||
Title string `json:"title"`
|
||||
Items []string `json:"items"`
|
||||
}
|
||||
|
||||
type fileShape struct {
|
||||
Releases []Release `json:"releases"`
|
||||
}
|
||||
|
||||
var (
|
||||
loadOnce sync.Once
|
||||
parsed fileShape
|
||||
loadErr error
|
||||
)
|
||||
|
||||
func load() {
|
||||
loadOnce.Do(func() {
|
||||
loadErr = json.Unmarshal(embedded, &parsed)
|
||||
})
|
||||
}
|
||||
|
||||
// ForVersion returns the release entry for the given server version, or nil if none (no modal).
|
||||
func ForVersion(serverVersion string) *Release {
|
||||
load()
|
||||
if loadErr != nil || serverVersion == "" {
|
||||
return nil
|
||||
}
|
||||
for i := range parsed.Releases {
|
||||
if parsed.Releases[i].Version == serverVersion {
|
||||
r := parsed.Releases[i]
|
||||
return &r
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
{
|
||||
"releases": [
|
||||
{
|
||||
"version": "0.1.1-dev",
|
||||
"title": "AutoHero — 0.1.1",
|
||||
"items": [
|
||||
"Changelog added",
|
||||
"Combat UI updated",
|
||||
"Dead screen no longer blocks the hero stats button",
|
||||
"Fixed floating damage numbers and evade / blocked / crit indicators",
|
||||
"Buff buttons: info is greyed out when the buff is not active",
|
||||
"Some other minor UI improvements",
|
||||
"Something else"
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "0.1.0-dev",
|
||||
"title": "AutoHero",
|
||||
"items": [
|
||||
"Добавлен экран «Что нового» после обновления сервера (наполняется вручную в changelog.json)."
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/denisovdennis/autohero/internal/model"
|
||||
"github.com/denisovdennis/autohero/internal/tuning"
|
||||
)
|
||||
|
||||
// ApplyVictoryRewards + GenerateLoot: gold only if gold roll succeeds; force chance 1.0 so the test is deterministic.
|
||||
func TestApplyVictoryRewards_awardsGoldFromLoot(t *testing.T) {
|
||||
v := tuning.DefaultValues()
|
||||
v.GoldDropChance = 1.0
|
||||
tuning.Set(v)
|
||||
t.Cleanup(func() { tuning.Set(tuning.DefaultValues()) })
|
||||
|
||||
hero := &model.Hero{
|
||||
ID: 1, Level: 1, Gold: 0, XP: 0,
|
||||
State: model.StateFighting,
|
||||
}
|
||||
enemy := &model.Enemy{
|
||||
Type: model.EnemyWolf, Name: "Wolf",
|
||||
MinLevel: 1, MaxLevel: 5,
|
||||
XPReward: 10,
|
||||
}
|
||||
beforeGold := hero.Gold
|
||||
drops := ApplyVictoryRewards(hero, enemy, time.Now(), VictoryRewardDeps{})
|
||||
if len(drops) < 1 {
|
||||
t.Fatal("expected at least one loot drop")
|
||||
}
|
||||
var hasGold bool
|
||||
for _, d := range drops {
|
||||
if d.ItemType == "gold" && d.GoldAmount > 0 {
|
||||
hasGold = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasGold {
|
||||
t.Fatalf("expected a gold entry in drops: %#v", drops)
|
||||
}
|
||||
if hero.Gold <= beforeGold {
|
||||
t.Fatalf("hero gold should increase (loot gold); before=%d after=%d", beforeGold, hero.Gold)
|
||||
}
|
||||
if model.SumGoldFromLootDrops(drops) <= 0 {
|
||||
t.Fatal("SumGoldFromLootDrops should be positive for victory drops")
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/denisovdennis/autohero/internal/tuning"
|
||||
)
|
||||
|
||||
// equipmentLootSlots must give every slot a positive share so that, with EquipmentDropBase > 0,
|
||||
// P(drop slot s | luck=1) = EquipmentDropBase * weight[s] > 0.
|
||||
func TestEquipmentLootSlotWeights_positiveAndSumToOne(t *testing.T) {
|
||||
var sum float64
|
||||
for _, row := range equipmentLootSlots {
|
||||
if row.weight <= 0 {
|
||||
t.Fatalf("slot %q: weight must be > 0", row.itemType)
|
||||
}
|
||||
sum += row.weight
|
||||
}
|
||||
if math.Abs(sum-1.0) > 1e-9 {
|
||||
t.Fatalf("equipmentLootSlots weights sum to %g, want 1.0", sum)
|
||||
}
|
||||
}
|
||||
|
||||
// User-facing slots: weapon, armor, necklace, ring, boots, pants, bracers, gloves
|
||||
// map to main_hand, chest, neck, finger, feet, legs, wrist, hands — all must appear with positive weight.
|
||||
func TestEquipmentLootSlotWeights_coversCoreSlots(t *testing.T) {
|
||||
want := []EquipmentSlot{
|
||||
SlotMainHand, SlotChest, SlotNeck, SlotFinger, SlotFeet, SlotLegs, SlotWrist, SlotHands,
|
||||
}
|
||||
seen := make(map[string]bool, len(equipmentLootSlots))
|
||||
for _, row := range equipmentLootSlots {
|
||||
seen[row.itemType] = true
|
||||
}
|
||||
for _, s := range want {
|
||||
if !seen[string(s)] {
|
||||
t.Fatalf("missing slot %q in equipmentLootSlots", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// With default tuning and luck 1.0, marginal probability of rolling a specific equipment slot
|
||||
// (equip roll succeeds, then slot roll) is EquipmentDropBase * weight > 0.
|
||||
func TestMarginalEquipmentDropChancePerSlot_nonZeroWithDefaults(t *testing.T) {
|
||||
cfg := tuning.DefaultValues()
|
||||
if cfg.EquipmentDropBase <= 0 {
|
||||
t.Fatal("default EquipmentDropBase must be > 0")
|
||||
}
|
||||
for _, row := range equipmentLootSlots {
|
||||
marginal := cfg.EquipmentDropBase * row.weight
|
||||
if marginal <= 0 {
|
||||
t.Fatalf("marginal chance for %q is %g", row.itemType, marginal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateLoot_goldLineWhenChanceSucceeds(t *testing.T) {
|
||||
v := tuning.DefaultValues()
|
||||
v.GoldDropChance = 1.0
|
||||
tuning.Set(v)
|
||||
t.Cleanup(func() { tuning.Set(tuning.DefaultValues()) })
|
||||
|
||||
drops := GenerateLootWithRNG(EnemyWolf, 1.0, nil)
|
||||
var gold *LootDrop
|
||||
for i := range drops {
|
||||
if drops[i].ItemType == "gold" {
|
||||
gold = &drops[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if gold == nil {
|
||||
t.Fatal("expected a gold LootDrop line when GoldDropChance is 1")
|
||||
}
|
||||
if gold.GoldAmount < 1 {
|
||||
t.Fatalf("gold amount should be >= 1, got %d", gold.GoldAmount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateLoot_noGoldWhenChanceZero(t *testing.T) {
|
||||
v := tuning.DefaultValues()
|
||||
v.GoldDropChance = 0
|
||||
tuning.Set(v)
|
||||
t.Cleanup(func() { tuning.Set(tuning.DefaultValues()) })
|
||||
|
||||
drops := GenerateLootWithRNG(EnemyWolf, 1.0, nil)
|
||||
for _, d := range drops {
|
||||
if d.ItemType == "gold" {
|
||||
t.Fatalf("unexpected gold line: %#v", drops)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateLoot_goldOmittedWhenFirstRollFails(t *testing.T) {
|
||||
v := tuning.DefaultValues()
|
||||
v.GoldDropChance = 0.5
|
||||
tuning.Set(v)
|
||||
t.Cleanup(func() { tuning.Set(tuning.DefaultValues()) })
|
||||
|
||||
// rng returns 0.99, 0.1, ... — first roll fails gold (< 0.5), second is potion check, etc.
|
||||
r := rand.New(rand.NewSource(1))
|
||||
drops := GenerateLootWithRNG(EnemyWolf, 1.0, r)
|
||||
for _, d := range drops {
|
||||
if d.ItemType == "gold" {
|
||||
t.Fatal("expected no gold when first float is high and chance is 0.5")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package model
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSumGoldFromLootDrops(t *testing.T) {
|
||||
drops := []LootDrop{
|
||||
{ItemType: "gold", GoldAmount: 30, Rarity: RarityCommon},
|
||||
{ItemType: "gold", GoldAmount: 12, Rarity: RarityCommon},
|
||||
{ItemType: "main_hand", ItemName: "Blade", Rarity: RarityRare},
|
||||
}
|
||||
if g := SumGoldFromLootDrops(drops); g != 42 {
|
||||
t.Fatalf("SumGoldFromLootDrops: want 42, got %d", g)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLootDropsToLootItems_skipsGold_includesGearAndPotion(t *testing.T) {
|
||||
drops := []LootDrop{
|
||||
{ItemType: "gold", GoldAmount: 99, Rarity: RarityCommon},
|
||||
{ItemType: "potion", Rarity: RarityCommon},
|
||||
{ItemType: "chest", ItemName: "Chainmail", Rarity: RarityUncommon},
|
||||
{ItemType: "head", ItemName: "", Rarity: RarityCommon}, // no name → omitted
|
||||
}
|
||||
items := LootDropsToLootItems(drops)
|
||||
if len(items) != 2 {
|
||||
t.Fatalf("want 2 loot lines (potion + chest), got %d: %+v", len(items), items)
|
||||
}
|
||||
if items[0].ItemType != "potion" || items[1].ItemType != "chest" || items[1].Name != "Chainmail" {
|
||||
t.Fatalf("unexpected items: %+v", items)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
// Package version holds the server release string exposed to clients and admin.
|
||||
// Bump this when you deploy a release that should drive the changelog gate.
|
||||
package version
|
||||
|
||||
// Version is the active server build id (shown in /hero/init and admin /info).
|
||||
const Version = "0.1.1-dev"
|
||||
@ -0,0 +1,3 @@
|
||||
-- Track which server version the player last acknowledged in the changelog UI.
|
||||
ALTER TABLE heroes
|
||||
ADD COLUMN IF NOT EXISTS changelog_ack_version TEXT NOT NULL DEFAULT '';
|
||||
@ -0,0 +1,9 @@
|
||||
-- Lower wandering merchant encounter weights (relative to monster weight).
|
||||
UPDATE runtime_config
|
||||
SET
|
||||
payload = payload || '{
|
||||
"merchantEncounterWeightBase": 0.02,
|
||||
"merchantEncounterWeightRoadBonus": 0.05
|
||||
}'::jsonb,
|
||||
updated_at = now()
|
||||
WHERE id = TRUE;
|
||||
@ -0,0 +1,103 @@
|
||||
import type { CSSProperties } from 'react';
|
||||
import { useT, t } from '../i18n';
|
||||
|
||||
export interface ChangelogModalProps {
|
||||
title: string;
|
||||
items: string[];
|
||||
serverVersion?: string;
|
||||
onDismiss: () => void;
|
||||
}
|
||||
|
||||
const overlayStyle: CSSProperties = {
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.72)',
|
||||
zIndex: 450,
|
||||
cursor: 'pointer',
|
||||
pointerEvents: 'auto',
|
||||
};
|
||||
|
||||
const cardStyle: CSSProperties = {
|
||||
backgroundColor: 'rgba(15, 15, 30, 0.97)',
|
||||
border: '1px solid rgba(120, 200, 255, 0.35)',
|
||||
borderRadius: 12,
|
||||
padding: '20px 22px',
|
||||
maxWidth: 340,
|
||||
width: 'calc(100vw - 40px)',
|
||||
maxHeight: 'min(70vh, 420px)',
|
||||
overflowY: 'auto',
|
||||
boxShadow: '0 0 32px rgba(60, 120, 220, 0.25)',
|
||||
cursor: 'default',
|
||||
};
|
||||
|
||||
const titleStyle: CSSProperties = {
|
||||
fontSize: 17,
|
||||
fontWeight: 700,
|
||||
color: '#e8f0ff',
|
||||
marginBottom: 6,
|
||||
textAlign: 'center',
|
||||
};
|
||||
|
||||
const versionStyle: CSSProperties = {
|
||||
fontSize: 11,
|
||||
color: 'rgba(180, 200, 230, 0.75)',
|
||||
textAlign: 'center',
|
||||
marginBottom: 14,
|
||||
};
|
||||
|
||||
const listStyle: CSSProperties = {
|
||||
margin: '0 0 16px 0',
|
||||
paddingLeft: 18,
|
||||
color: '#c8d8f0',
|
||||
fontSize: 13,
|
||||
lineHeight: 1.45,
|
||||
};
|
||||
|
||||
const buttonStyle: CSSProperties = {
|
||||
display: 'block',
|
||||
width: '100%',
|
||||
padding: '10px 16px',
|
||||
borderRadius: 8,
|
||||
border: 'none',
|
||||
background: 'linear-gradient(180deg, #4a8cff 0%, #2d5eb8 100%)',
|
||||
color: '#fff',
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
cursor: 'pointer',
|
||||
};
|
||||
|
||||
export function ChangelogModal({ title, items, serverVersion, onDismiss }: ChangelogModalProps) {
|
||||
const tr = useT();
|
||||
return (
|
||||
<div
|
||||
style={overlayStyle}
|
||||
role="dialog"
|
||||
aria-modal
|
||||
aria-labelledby="changelog-title"
|
||||
onClick={onDismiss}
|
||||
>
|
||||
<div style={cardStyle} onClick={(e) => e.stopPropagation()}>
|
||||
<div id="changelog-title" style={titleStyle}>
|
||||
{title}
|
||||
</div>
|
||||
{serverVersion ? (
|
||||
<div style={versionStyle}>{t(tr.changelogVersion, { version: serverVersion })}</div>
|
||||
) : null}
|
||||
<ul style={listStyle}>
|
||||
{items.map((line, i) => (
|
||||
<li key={i}>{line}</li>
|
||||
))}
|
||||
</ul>
|
||||
<button type="button" style={buttonStyle} onClick={onDismiss}>
|
||||
{tr.changelogOk}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue