/*
 * Copyright (c) 2013 L2jMobius
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
 * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.l2jmobius.gameserver.managers;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

import org.l2jmobius.gameserver.entity.Location;

/**
 * Runtime state of one headless bot: identity from the seed, timers of the
 * social/economy layers, the combat memory of the brain and the activity
 * counters that prove the bot really farms, trades and fights (see
 * {@link FakePlayerTelemetry}).
 * @author Mobius SPP
 */
public class FakePlayerBotState
{
	// --- identity (seed) ---
	public int seedId;
	public String personality = "neutral";
	public String race = "";
	public String zone = "";
	public Location spot; // Centre of the current farming spot.

	// --- level / gear ---
	public int lastLevel = 1;
	public long lastExp = 0;
	public long nextGearCheck = 0;
	public int gearTier = -1;
	public long nextProfessionCheck = 0;

	// --- combat ---
	public int forcedTargetId = 0;
	public long forcedUntil = 0;
	public int lastPvpTargetId = 0;
	public long lastHelpCall = 0;
	public final FakePlayerBrain.CombatState combat = new FakePlayerBrain.CombatState();

	// --- social ---
	public long lastChat = 0;
	public long lastHelpCredit = 0;
	public long partyCooldown = 0;
	public long nextBotTalk = 0; // Bot to bot small talk.
	public long nextGossip = 0;
	public long nextLfp = 0;
	public int companionPlayerId = 0;
	public long companionUntil = 0;
	public int pendingInvitePlayerId = 0;
	public long pendingInviteUntil = 0;
	public long nextSlotRefresh = 0;
	public String lastDrop = "";
	/** Bots met recently (objectId - time), to greet each one only now and then. */
	public final ConcurrentHashMap<Integer, Long> met = new ConcurrentHashMap<>();

	// --- economy ---
	public long nextTradeAt = 0;
	public long tradeUntil = 0;
	public long nextShoppingAt = 0;
	public long lastTownVisit = 0;
	public boolean giftedStock = false;

	// --- siege ---
	public byte siegeSide = 0; // 0 none, 1 attacker, 2 defender.
	public int siegeCastleId = 0;
	public long siegeNextThink = 0;

	// --- telemetry ---
	public final AtomicLong kills = new AtomicLong();
	public final AtomicLong expGained = new AtomicLong();
	public final AtomicLong deaths = new AtomicLong();
	public final AtomicLong pvpKills = new AtomicLong();
	public final AtomicLong lootPicked = new AtomicLong();
	public final AtomicLong itemsSold = new AtomicLong();
	public final AtomicLong adenaEarned = new AtomicLong();
	public final AtomicLong adenaSpent = new AtomicLong();
	public final AtomicLong storesOpened = new AtomicLong();
	public final AtomicLong linesSaid = new AtomicLong();
	public final AtomicLong repliesGiven = new AtomicLong();
	public final AtomicLong skillsCast = new AtomicLong();
	public final AtomicLong rests = new AtomicLong();
	public final AtomicLong siegesJoined = new AtomicLong();
	public final AtomicLong migrations = new AtomicLong();
	public final AtomicLong professions = new AtomicLong();
	public final AtomicLong partiesJoined = new AtomicLong();
	public volatile String lastAction = "spawn";
	public volatile long lastActionAt = System.currentTimeMillis();

	/**
	 * Records what the bot is doing right now (visible on the dashboard and in do=stats).
	 * @param action short action name.
	 */
	public void action(String action)
	{
		lastAction = action;
		lastActionAt = System.currentTimeMillis();
	}
}
