mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-02 19:42:05 -04:00
141 lines
3.9 KiB
C#
141 lines
3.9 KiB
C#
/*
|
|
===========================================================================
|
|
Copyright (C) 2015-2019 Project Meteor Dev Team
|
|
|
|
This file is part of Project Meteor Server.
|
|
|
|
Project Meteor Server is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Project Meteor Server is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with Project Meteor Server. If not, see <https:www.gnu.org/licenses/>.
|
|
===========================================================================
|
|
*/
|
|
|
|
using Meteor.Map.lua;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Meteor.Map.Actors
|
|
{
|
|
class Scenario : Quest
|
|
{
|
|
private uint currentPhase = 0;
|
|
private uint questFlags = 0;
|
|
private Dictionary<string, object> questData = new Dictionary<string, object>();
|
|
|
|
public Scenario(uint actorID, string name)
|
|
: base(actorID, name)
|
|
{
|
|
actorName = name;
|
|
}
|
|
|
|
public Scenario(Quest staticQuest, Player owner, string questDataJson, uint questFlags, uint currentPhase)
|
|
: base(staticQuest, owner)
|
|
{
|
|
this.questFlags = questFlags;
|
|
|
|
if (questDataJson != null)
|
|
this.questData = JsonConvert.DeserializeObject<Dictionary<string, object>>(questDataJson);
|
|
else
|
|
questData = null;
|
|
|
|
if (questData == null)
|
|
questData = new Dictionary<string, object>();
|
|
|
|
this.currentPhase = currentPhase;
|
|
}
|
|
|
|
public void SetQuestData(string dataName, object data)
|
|
{
|
|
questData[dataName] = data;
|
|
|
|
//Inform update
|
|
}
|
|
|
|
public object GetQuestData(string dataName)
|
|
{
|
|
if (questData.ContainsKey(dataName))
|
|
return questData[dataName];
|
|
else
|
|
return null;
|
|
}
|
|
|
|
public void ClearQuestData()
|
|
{
|
|
questData.Clear();
|
|
}
|
|
|
|
public void ClearQuestFlags()
|
|
{
|
|
questFlags = 0;
|
|
}
|
|
|
|
public void SetQuestFlag(int bitIndex, bool value)
|
|
{
|
|
if (bitIndex >= 32)
|
|
{
|
|
Program.Log.Error("Tried to access bit flag >= 32 for questId: {0}", actorId);
|
|
return;
|
|
}
|
|
|
|
int mask = 1 << bitIndex;
|
|
|
|
if (value)
|
|
questFlags |= (uint)(1 << bitIndex);
|
|
else
|
|
questFlags &= (uint)~(1 << bitIndex);
|
|
|
|
DoCompletionCheck();
|
|
}
|
|
|
|
public bool GetQuestFlag(int bitIndex)
|
|
{
|
|
if (bitIndex >= 32)
|
|
{
|
|
Program.Log.Error("Tried to access bit flag >= 32 for questId: {0}", actorId);
|
|
return false;
|
|
}
|
|
else
|
|
return (questFlags & (1 << bitIndex)) == (1 << bitIndex);
|
|
}
|
|
|
|
public uint GetPhase()
|
|
{
|
|
return currentPhase;
|
|
}
|
|
|
|
public void NextPhase(uint phaseNumber)
|
|
{
|
|
currentPhase = phaseNumber;
|
|
owner.SendGameMessage(Server.GetWorldManager().GetActor(), 25116, 0x20, (object)GetQuestId());
|
|
SaveData();
|
|
|
|
DoCompletionCheck();
|
|
}
|
|
|
|
public uint GetQuestFlags()
|
|
{
|
|
return questFlags;
|
|
}
|
|
|
|
public override string GetSerializedQuestData()
|
|
{
|
|
return JsonConvert.SerializeObject(questData, Formatting.Indented);
|
|
}
|
|
|
|
public override void SaveData()
|
|
{
|
|
Database.SaveQuest(owner, this);
|
|
}
|
|
}
|
|
}
|