#ifndef __INC_METIN_II_HIGH_RISK_H__
#define __INC_METIN_II_HIGH_RISK_H__

// High Risk -- an optional, permanently switchable free-PvP mode.
//
// A character that chose High Risk is free game TO OTHER CHARACTERS WHO ALSO
// CHOSE IT: any of them may attack and kill it, its own empire and its own guild
// included, and nobody is punished for doing so. Against a character that did
// NOT choose it there is no fight in either direction -- it cannot be killed by
// one and it cannot hunt one. The mode is a pool of people who consented, not a
// licence over people who did not. In exchange its members earn
// HIGH_RISK_EXP_BONUS_PCT more experience and find HIGH_RISK_DROP_BONUS_PCT more
// drops, and when one dies it drops items as a Cruel character does.
//
// Guild wars, castle sieges, duels and the arena are all settled in
// battle_is_attackable ABOVE CPVPManager::CanAttack, so they keep working
// between a High Risk and a No Risk player. Those are consensual by their own
// rules; this mode only governs the open world.
//
// The choice itself belongs to the player and lives in a quest flag written by
// share/locale/<lang>/quest/high_risk.quest. It is read here rather than
// mirrored onto CHARACTER because the quest flag is already the persistent,
// per-character, database-backed store for exactly this kind of decision --
// duplicating it would mean keeping two copies honest across login, logout,
// character deletion and the panel, for no gain.
//
// Everything below is inert on a server without that quest file: no character
// can set the flag, GetFlag returns 0 for every one of them, and every caller
// falls through to stock behaviour. That is deliberate -- this feature has to
// be removable without unpicking the core.
//
// The places that ask:
//
//   pvp.cpp          CPVPManager::CanAttack()       the pool rule: a High Risk
//                                                   and a No Risk character
//                                                   never fight, either way
//   char_battle.cpp  CHARACTER::UpdateKillerMode()  keeps the killer flag lit,
//                                                   which is what lets two of
//                                                   them reach each other and
//                                                   what MARKS them, server
//                                                   side, in every stock client
//   char_battle.cpp  CHARACTER::ItemDropPenalty()   the Cruel drop band, and
//                                                   the level-50 exemption
//   char_battle.cpp  the experience award           the experience bonus
//   item_manager.cpp ITEM_MANAGER::GetDropPct()     the drop bonus

#include "char.h"
#include "questmanager.h"

// Quest flags are namespaced by the quest they were written from:
// pc.setqf("mode", 1) inside `quest high_risk' stores "high_risk.mode"
// (questlua_pc.cpp writes GetCurrentQuestName() + "." + name). Renaming the
// quest file renames this flag, and the mode would silently switch itself off
// for every character that had it.
#define HIGH_RISK_QUEST_FLAG	"high_risk.mode"

enum EHighRisk
{
	// Both are percentages added on top of whatever the character had earned
	// anyway, not replacements for it.
	HIGH_RISK_EXP_BONUS_PCT		= 50,
	HIGH_RISK_DROP_BONUS_PCT	= 50,

	// The last row of aItemDropPenalty_kor in char_battle.cpp: the band a
	// character below -120000 alignment falls into -- Cruel. It is the harshest
	// row in the table and the one the mode borrows wholesale, so that the
	// quantities, the anti-drop item flags and the drop-everything-when-the-bags-
	// are-empty case all stay exactly as they are for a genuinely cruel player.
	HIGH_RISK_ALIGN_INDEX_CRUEL	= 8,

	// How often a death actually costs something. The Cruel band the mode
	// borrows is rolled as `pct >= number(1, 1000)' for the bags and
	// `pct >= number(1, 100)' for what is worn, so its shipped 100 and 20 mean
	// 10% and 20%. Those were judged too mild for a mode a player opts into for
	// a reward, so High Risk -- and ONLY High Risk -- uses the two below
	// instead. A genuinely Cruel character is untouched by this and still drops
	// on the shipped odds; the quantities (8 from the bags, 1 worn) come from
	// the Cruel row for both, because only the frequency was in question.
	HIGH_RISK_INVENTORY_PCT		= 500,	// of 1000 -> 50%
	HIGH_RISK_EQUIPMENT_PCT		= 10,	// of  100 -> 10%
};

inline bool IsHighRiskMode(LPCHARACTER ch)
{
	if (!ch || !ch->IsPC())
		return false;

	// GetPCForce and not GetPC: GetPC reassigns the quest manager's current PC
	// and current character as a side effect, which is fine from inside a quest
	// and ruinous from the middle of the combat code -- it would rewrite the
	// context of whatever quest happened to be running. GetPCForce is the
	// accessor that promises not to (questmanager.h).
	quest::PC * pPC = quest::CQuestManager::instance().GetPCForce(ch->GetPlayerID());

	if (!pPC)
		return false;

	return pPC->GetFlag(HIGH_RISK_QUEST_FLAG) != 0;
}

#endif
