using System;
using ACE.Entity;
using ACE.Entity.Enum;
using ACE.Entity.Enum.Properties;
using ACE.Entity.Models;
using ACE.Server.Entity;
using ACE.Server.Entity.Actions;
using ACE.Server.Network.GameEvent.Events;
using ACE.Server.Network.GameMessages.Messages;
namespace ACE.Server.WorldObjects
{
public class Bindstone : WorldObject
{
///
/// A new biota be created taking all of its values from weenie.
///
public Bindstone(Weenie weenie, ObjectGuid guid) : base(weenie, guid)
{
SetEphemeralValues();
}
///
/// Restore a WorldObject from the database.
///
public Bindstone(Biota biota) : base(biota)
{
SetEphemeralValues();
}
private void SetEphemeralValues()
{
ObjectDescriptionFlags |= ObjectDescriptionFlag.BindStone;
SetProperty(PropertyInt.ShowableOnRadar, (int)ACE.Entity.Enum.RadarBehavior.ShowAlways);
SetProperty(PropertyInt.RadarBlipColor, (int)ACE.Entity.Enum.RadarColor.LifeStone);
}
///
/// This is raised by Player.HandleActionUseItem.
/// The item does not exist in the players possession.
/// If the item was outside of range, the player will have been commanded to move using DoMoveTo before ActOnUse is called.
/// When this is called, it should be assumed that the player is within range.
///
public override void ActOnUse(WorldObject worldObject)
{
if (!(worldObject is Player player))
return;
// check if player is in an allegiance
if (player.Allegiance == null)
{
player.Session.Network.EnqueueSend(new GameEventWeenieError(player.Session, WeenieError.YouAreNotInAllegiance));
return;
}
if (player.AllegiancePermissionLevel < AllegiancePermissionLevel.Seneschal)
{
player.Session.Network.EnqueueSend(new GameEventWeenieError(player.Session, WeenieError.YouDoNotHaveAuthorityInAllegiance));
return;
}
var actionChain = new ActionChain();
if (player.CombatMode != CombatMode.NonCombat)
{
var stanceTime = player.SetCombatMode(CombatMode.NonCombat);
actionChain.AddDelaySeconds(stanceTime);
player.LastUseTime += stanceTime;
}
actionChain.AddAction(this, () => EnqueueBroadcastMotion(new Motion(MotionStance.NonCombat, MotionCommand.Twitch1)));
// player animation?
player.LastUseTime += player.EnqueueMotion(actionChain, MotionCommand.Sanctuary);
actionChain.AddAction(this, () =>
{
if (player.IsWithinUseRadiusOf(this))
{
player.Allegiance.Sanctuary = new Position(player.Location);
player.Allegiance.SaveBiotaToDatabase();
player.Session.Network.EnqueueSend(new GameMessageSystemChat(GetProperty(PropertyString.UseMessage), ChatMessageType.Magic));
}
else
player.Session.Network.EnqueueSend(new GameEventWeenieError(player.Session, WeenieError.YouHaveMovedTooFar));
});
actionChain.EnqueueChain();
}
}
}