|
|
|
@ -1312,6 +1312,149 @@ func (h *AdminHandler) ResetBuffCharges(w http.ResponseWriter, r *http.Request)
|
|
|
|
writeJSON(w, http.StatusOK, hero)
|
|
|
|
writeJSON(w, http.StatusOK, hero)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type applyBuffAdminRequest struct {
|
|
|
|
|
|
|
|
BuffType string `json:"buffType"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ApplyHeroBuff applies a buff from the catalog without consuming free-charge quota (admin/testing).
|
|
|
|
|
|
|
|
// POST /admin/heroes/{heroId}/apply-buff
|
|
|
|
|
|
|
|
func (h *AdminHandler) ApplyHeroBuff(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
heroID, err := parseHeroID(r)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusBadRequest, map[string]string{
|
|
|
|
|
|
|
|
"error": "invalid heroId: " + err.Error(),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if h.isHeroInCombat(w, heroID) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var req applyBuffAdminRequest
|
|
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusBadRequest, map[string]string{
|
|
|
|
|
|
|
|
"error": "invalid request body: " + err.Error(),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bt, ok := model.ValidBuffType(req.BuffType)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusBadRequest, map[string]string{
|
|
|
|
|
|
|
|
"error": "invalid buffType: " + req.BuffType,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hero, err := h.store.GetByID(r.Context(), heroID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
h.logger.Error("admin: get hero for apply-buff", "hero_id", heroID, "error", err)
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusInternalServerError, map[string]string{
|
|
|
|
|
|
|
|
"error": "failed to load hero",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if hero == nil {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusNotFound, map[string]string{
|
|
|
|
|
|
|
|
"error": "hero not found",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
if game.ApplyBuff(hero, bt, now) == nil {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusBadRequest, map[string]string{
|
|
|
|
|
|
|
|
"error": "buff could not be applied (unknown catalog entry)",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := h.store.Save(r.Context(), hero); err != nil {
|
|
|
|
|
|
|
|
h.logger.Error("admin: save hero after apply-buff", "hero_id", heroID, "error", err)
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusInternalServerError, map[string]string{
|
|
|
|
|
|
|
|
"error": "failed to save hero",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h.logger.Info("admin: buff applied", "hero_id", heroID, "buff_type", bt)
|
|
|
|
|
|
|
|
hero.EnsureGearMap()
|
|
|
|
|
|
|
|
hero.RefreshDerivedCombatStats(now)
|
|
|
|
|
|
|
|
h.engine.ApplyAdminHeroSnapshot(hero)
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusOK, hero)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type applyDebuffAdminRequest struct {
|
|
|
|
|
|
|
|
DebuffType string `json:"debuffType"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ApplyHeroDebuff applies a debuff from the catalog (admin/testing).
|
|
|
|
|
|
|
|
// POST /admin/heroes/{heroId}/apply-debuff
|
|
|
|
|
|
|
|
func (h *AdminHandler) ApplyHeroDebuff(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
heroID, err := parseHeroID(r)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusBadRequest, map[string]string{
|
|
|
|
|
|
|
|
"error": "invalid heroId: " + err.Error(),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if h.isHeroInCombat(w, heroID) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var req applyDebuffAdminRequest
|
|
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusBadRequest, map[string]string{
|
|
|
|
|
|
|
|
"error": "invalid request body: " + err.Error(),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dt, ok := model.ValidDebuffType(req.DebuffType)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusBadRequest, map[string]string{
|
|
|
|
|
|
|
|
"error": "invalid debuffType: " + req.DebuffType,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hero, err := h.store.GetByID(r.Context(), heroID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
h.logger.Error("admin: get hero for apply-debuff", "hero_id", heroID, "error", err)
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusInternalServerError, map[string]string{
|
|
|
|
|
|
|
|
"error": "failed to load hero",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if hero == nil {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusNotFound, map[string]string{
|
|
|
|
|
|
|
|
"error": "hero not found",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
if _, defOk := model.DebuffDefinition(dt); !defOk {
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusBadRequest, map[string]string{
|
|
|
|
|
|
|
|
"error": "debuff not in catalog: " + req.DebuffType,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
game.ApplyDebuff(hero, dt, now)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := h.store.Save(r.Context(), hero); err != nil {
|
|
|
|
|
|
|
|
h.logger.Error("admin: save hero after apply-debuff", "hero_id", heroID, "error", err)
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusInternalServerError, map[string]string{
|
|
|
|
|
|
|
|
"error": "failed to save hero",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h.logger.Info("admin: debuff applied", "hero_id", heroID, "debuff_type", dt)
|
|
|
|
|
|
|
|
hero.EnsureGearMap()
|
|
|
|
|
|
|
|
hero.RefreshDerivedCombatStats(now)
|
|
|
|
|
|
|
|
h.engine.ApplyAdminHeroSnapshot(hero)
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusOK, hero)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DeleteHero permanently removes a hero from the database.
|
|
|
|
// DeleteHero permanently removes a hero from the database.
|
|
|
|
// DELETE /admin/heroes/{heroId}
|
|
|
|
// DELETE /admin/heroes/{heroId}
|
|
|
|
func (h *AdminHandler) DeleteHero(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func (h *AdminHandler) DeleteHero(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|