servuo/Scripts/Services/CommunityCollections/CommunityCollectionNPCs/BaseCollectionMobile.cs

405 lines
11 KiB
C#
Raw Permalink Normal View History

2013-10-28 07:09:42 +00:00
using Server.Engines.Quests;
using Server.Gumps;
using Server.Network;
2016-02-11 13:52:59 -06:00
using Server.Services.Community_Collections;
2020-04-14 14:04:34 -04:00
using System;
using System.Collections.Generic;
2013-10-28 07:09:42 +00:00
namespace Server.Mobiles
{
public abstract class BaseCollectionMobile : BaseVendor, IComunityCollection
2020-04-14 14:04:34 -04:00
{
2013-10-28 07:09:42 +00:00
private readonly List<SBInfo> m_SBInfos = new List<SBInfo>();
2020-04-16 20:21:33 -04:00
protected override List<SBInfo> SBInfos => m_SBInfos;
2013-10-28 07:09:42 +00:00
2020-04-16 20:21:33 -04:00
public override bool IsActiveVendor => false;
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
#region IComunityCollection
public abstract Collection CollectionID { get; }
public abstract int MaxTier { get; }
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
private List<CollectionItem> m_Donations;
private List<CollectionItem> m_Rewards;
2020-04-14 14:04:34 -04:00
2020-04-16 20:21:33 -04:00
public List<CollectionItem> Donations => m_Donations;
2020-04-14 14:04:34 -04:00
2020-04-16 20:21:33 -04:00
public List<CollectionItem> Rewards => m_Rewards;
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
private long m_Points;
private long m_StartTier;
private long m_NextTier;
private long m_DailyDecay;
private int m_Tier;
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
[CommandProperty(AccessLevel.GameMaster)]
public long Points
{
get
{
2018-01-15 09:27:58 -07:00
return m_Points;
2013-10-28 07:09:42 +00:00
}
set
2020-04-14 14:04:34 -04:00
{
m_Points = value;
2018-01-15 09:27:58 -07:00
if (m_Points < 0)
m_Points = 0;
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
while (m_Tier > 0 && m_Points < PreviousTier)
DecreaseTier();
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
while (m_Tier < MaxTier && m_Points > CurrentTier)
IncreaseTier();
2020-04-14 14:04:34 -04:00
InvalidateProperties();
2013-10-28 07:09:42 +00:00
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
[CommandProperty(AccessLevel.GameMaster)]
public long PreviousTier
{
get
{
2018-01-15 09:27:58 -07:00
if (m_Tier > 2)
2013-10-28 07:09:42 +00:00
{
2018-01-15 09:27:58 -07:00
long tier = m_StartTier * 2;
2020-04-14 14:04:34 -04:00
for (int i = 0; i < m_Tier - 2; i++)
tier += (i + 3) * m_NextTier;
return tier;
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
return m_StartTier * m_Tier;
2013-10-28 07:09:42 +00:00
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
[CommandProperty(AccessLevel.GameMaster)]
public long CurrentTier
{
get
{
2018-01-15 09:27:58 -07:00
if (m_Tier > 1)
return PreviousTier + (m_Tier + 1) * m_NextTier;
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
return m_StartTier + m_StartTier * m_Tier;
2013-10-28 07:09:42 +00:00
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
[CommandProperty(AccessLevel.GameMaster)]
public long StartTier
{
get
{
2018-01-15 09:27:58 -07:00
return m_StartTier;
2013-10-28 07:09:42 +00:00
}
set
{
2018-01-15 09:27:58 -07:00
m_StartTier = value;
InvalidateProperties();
2013-10-28 07:09:42 +00:00
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
[CommandProperty(AccessLevel.GameMaster)]
public long NextTier
{
get
{
2018-01-15 09:27:58 -07:00
return m_NextTier;
2013-10-28 07:09:42 +00:00
}
set
{
2018-01-15 09:27:58 -07:00
m_NextTier = value;
InvalidateProperties();
2013-10-28 07:09:42 +00:00
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
[CommandProperty(AccessLevel.GameMaster)]
public long DailyDecay
{
get
{
2018-01-15 09:27:58 -07:00
return m_DailyDecay;
2013-10-28 07:09:42 +00:00
}
set
{
2018-01-15 09:27:58 -07:00
m_DailyDecay = value;
InvalidateProperties();
2013-10-28 07:09:42 +00:00
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
[CommandProperty(AccessLevel.GameMaster)]
2020-04-16 20:21:33 -04:00
public int Tier => m_Tier;
2013-10-28 07:09:42 +00:00
#endregion
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
private List<List<object>> m_Tiers;
private object m_DonationTitle;
2020-04-14 14:04:34 -04:00
2020-04-16 20:21:33 -04:00
public List<List<object>> Tiers => m_Tiers;
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
[CommandProperty(AccessLevel.GameMaster)]
public int DonationLabel
{
get
{
2018-01-15 09:27:58 -07:00
return m_DonationTitle is int ? (int)m_DonationTitle : 0;
2013-10-28 07:09:42 +00:00
}
set
{
2018-01-15 09:27:58 -07:00
m_DonationTitle = value;
2013-10-28 07:09:42 +00:00
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
[CommandProperty(AccessLevel.GameMaster)]
public string DonationString
{
get
{
2018-01-15 09:27:58 -07:00
return m_DonationTitle is string ? (string)m_DonationTitle : null;
2013-10-28 07:09:42 +00:00
}
set
{
2018-01-15 09:27:58 -07:00
m_DonationTitle = value;
2013-10-28 07:09:42 +00:00
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public BaseCollectionMobile(string name, string title)
: base(title)
{
2018-01-15 09:27:58 -07:00
Name = name;
Frozen = true;
CantWalk = true;
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
Init();
2016-02-11 13:52:59 -06:00
2020-04-14 14:04:34 -04:00
CollectionsSystem.RegisterMobile(this);
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public BaseCollectionMobile(Serial serial)
: base(serial)
{
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public override void InitSBInfo()
2020-04-14 14:04:34 -04:00
{
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public override void OnDoubleClick(Mobile from)
{
if (from.Alive)
{
if (!MondainsLegacy.PublicDonations && (int)from.AccessLevel < (int)AccessLevel.GameMaster)
2013-10-28 07:09:42 +00:00
{
from.SendLocalizedMessage(1042753, "Public donations"); // ~1_SOMETHING~ has been temporarily disabled.
return;
}
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
if (from.InRange(Location, 2) && from is PlayerMobile && CanDonate((PlayerMobile)from))
2013-10-28 07:09:42 +00:00
{
from.CloseGump(typeof(CommunityCollectionGump));
2018-01-15 09:27:58 -07:00
from.SendGump(new CommunityCollectionGump((PlayerMobile)from, this, Location));
2013-10-28 07:09:42 +00:00
}
else
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that.
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public override void GetProperties(ObjectPropertyList list)
{
base.GetProperties(list);
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
list.Add(1072819, m_Tier.ToString()); // Current Tier: ~1_TIER~
list.Add(1072820, m_Points.ToString()); // Current Points: ~1_POINTS~
list.Add(1072821, m_Tier > MaxTier ? 0.ToString() : CurrentTier.ToString()); // Points until next tier: ~1_POINTS~
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
if (DonationLabel > 0)
list.Add(DonationLabel);
else if (DonationString != null)
list.Add(DonationString);
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
public CollectionData GetData()
{
CollectionData ret = new CollectionData
{
Collection = CollectionID,
Points = Points,
StartTier = StartTier,
NextTier = NextTier,
DailyDecay = DailyDecay,
Tier = Tier,
DonationTitle = m_DonationTitle,
Tiers = m_Tiers
};
2020-04-14 14:04:34 -04:00
return ret;
}
public void SetData(CollectionData data)
{
m_Points = data.Points;
2018-01-15 09:27:58 -07:00
m_StartTier = data.StartTier;
m_NextTier = data.NextTier;
m_DailyDecay = data.DailyDecay;
2020-04-14 14:04:34 -04:00
m_Tier = data.Tier;
m_DonationTitle = data.DonationTitle;
m_Tiers = data.Tiers;
}
2016-02-11 13:52:59 -06:00
2013-10-28 07:09:42 +00:00
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
2020-04-14 14:04:34 -04:00
writer.Write(1); // version
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
2020-04-14 14:04:34 -04:00
2016-02-11 13:52:59 -06:00
int version = reader.ReadInt();
2020-04-14 14:04:34 -04:00
Init();
2016-02-11 13:52:59 -06:00
2020-04-14 14:04:34 -04:00
if (version == 0)
{
m_Points = reader.ReadLong();
m_StartTier = reader.ReadLong();
m_NextTier = reader.ReadLong();
m_DailyDecay = reader.ReadLong();
m_Tier = reader.ReadInt();
2016-02-11 13:52:59 -06:00
2020-04-14 14:04:34 -04:00
m_DonationTitle = QuestReader.Object(reader);
2016-02-11 13:52:59 -06:00
2020-04-14 14:04:34 -04:00
for (int i = reader.ReadInt(); i > 0; i--)
{
List<object> list = new List<object>();
2016-02-11 13:52:59 -06:00
2020-04-14 14:04:34 -04:00
for (int j = reader.ReadInt(); j > 0; j--)
list.Add(QuestReader.Object(reader));
2016-02-11 13:52:59 -06:00
2020-04-14 14:04:34 -04:00
m_Tiers.Add(list);
}
CollectionsSystem.RegisterMobile(this);
}
2016-02-11 13:52:59 -06:00
2020-04-14 14:04:34 -04:00
if (CantWalk)
2018-01-15 09:27:58 -07:00
Frozen = true;
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
#region IComunityCollection
public virtual void Donate(PlayerMobile player, CollectionItem item, int amount)
{
int points = (int)Math.Round(amount * item.Points);
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
player.AddCollectionPoints(CollectionID, points);
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
player.SendLocalizedMessage(1072816); // Thank you for your donation!
player.SendLocalizedMessage(1072817, points.ToString()); // You have earned ~1_POINTS~ reward points for this donation.
player.SendLocalizedMessage(1072818, points.ToString()); // The Collection has been awarded ~1_POINTS~ points
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
Points += points;
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
InvalidateProperties();
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public virtual void Reward(PlayerMobile player, CollectionItem reward, int hue)
{
Item item = Loot.Construct(reward.Type);
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
if (item != null && player.AddToBackpack(item))
{
if (hue > 0)
item.Hue = hue;
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
player.AddCollectionPoints(CollectionID, (int)reward.Points * -1);
2013-10-28 07:09:42 +00:00
player.SendLocalizedMessage(1073621); // Your reward has been placed in your backpack.
player.PlaySound(0x5A7);
if (reward.QuestItem)
CollectionsObtainObjective.CheckReward(player, item);
reward.OnGiveReward(player, item, this, hue);
2013-10-28 07:09:42 +00:00
}
else if (item != null)
{
player.SendLocalizedMessage(1074361); // The reward could not be given. Make sure you have room in your pack.
item.Delete();
2020-04-14 14:04:34 -04:00
}
2018-01-15 09:27:58 -07:00
player.SendGump(new CommunityCollectionGump(player, this, Location));
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public virtual void DonatePet(PlayerMobile player, BaseCreature pet)
{
2020-04-14 14:04:34 -04:00
for (int i = 0; i < m_Donations.Count; i++)
2018-01-15 09:27:58 -07:00
if (m_Donations[i].Type == pet.GetType())
2013-10-28 07:09:42 +00:00
{
pet.Delete();
2018-01-15 09:27:58 -07:00
Donate(player, m_Donations[i], 1);
2013-10-28 07:09:42 +00:00
return;
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
player.SendLocalizedMessage(1073113); // This Collection is not accepting that type of creature.
}
#endregion
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public virtual void IncreaseTier()
2020-04-14 14:04:34 -04:00
{
2018-01-15 09:27:58 -07:00
m_Tier += 1;
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public virtual void DecreaseTier()
2020-04-14 14:04:34 -04:00
{
2018-01-15 09:27:58 -07:00
m_Tier -= 1;
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
if (m_Tiers != null && m_Tiers.Count > 0)
2013-10-28 07:09:42 +00:00
{
2020-04-14 14:04:34 -04:00
for (int i = 0; i < m_Tiers[m_Tiers.Count - 1].Count; i++)
2013-10-28 07:09:42 +00:00
{
2018-01-15 09:27:58 -07:00
if (m_Tiers[m_Tiers.Count - 1][i] is Item)
((Item)m_Tiers[m_Tiers.Count - 1][i]).Delete();
else if (m_Tiers[m_Tiers.Count - 1][i] is Mobile)
((Mobile)m_Tiers[m_Tiers.Count - 1][i]).Delete();
2013-10-28 07:09:42 +00:00
}
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
m_Tiers.RemoveAt(m_Tiers.Count - 1);
2013-10-28 07:09:42 +00:00
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public virtual void Init()
2020-04-14 14:04:34 -04:00
{
2018-01-15 09:27:58 -07:00
if (m_Donations == null)
m_Donations = new List<CollectionItem>();
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
if (m_Rewards == null)
m_Rewards = new List<CollectionItem>();
2020-04-14 14:04:34 -04:00
2018-01-15 09:27:58 -07:00
if (m_Tiers == null)
m_Tiers = new List<List<object>>();
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
// start decay timer
2018-01-15 09:27:58 -07:00
if (m_DailyDecay > 0)
2013-10-28 07:09:42 +00:00
{
DateTime today = DateTime.Today.AddDays(1);
2013-10-28 07:09:42 +00:00
new CollectionDecayTimer(this, today - DateTime.UtcNow);
}
}
2020-04-14 14:04:34 -04:00
2013-10-28 07:09:42 +00:00
public virtual bool CanDonate(PlayerMobile player)
{
return true;
}
2016-02-11 13:52:59 -06:00
2020-04-14 14:04:34 -04:00
public override void OnDelete()
{
base.OnDelete();
2016-02-11 13:52:59 -06:00
2020-04-14 14:04:34 -04:00
CollectionsSystem.UnregisterMobile(this);
}
}
}