mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-05-20 08:26:59 -04:00
Finished the crafting start window system. Added PassiveGuildleveQuests and refactors the Quest object. Cleaned up how zone music is handled.
This commit is contained in:
139
Map Server/Actors/Quest/PassiveGuildleve.cs
Normal file
139
Map Server/Actors/Quest/PassiveGuildleve.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
===========================================================================
|
||||
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.dataobjects;
|
||||
using Meteor.Map.DataObjects;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Meteor.Map.Actors
|
||||
{
|
||||
class PassiveGuildleve : Quest
|
||||
{
|
||||
private Recipe targetRecipe;
|
||||
|
||||
private byte currentDifficulty;
|
||||
private short numSuccesses;
|
||||
private short currentAttempt;
|
||||
|
||||
private bool hasMaterials;
|
||||
|
||||
private PassiveGuildleveData passiveGLData;
|
||||
|
||||
public PassiveGuildleve(Quest staticQuest, Player owner, byte currentDifficulty)
|
||||
: base(staticQuest, owner)
|
||||
{
|
||||
passiveGLData = Server.GetPassiveGLGamedata(GetQuestId());
|
||||
targetRecipe = Server.ResolveRecipe().GetRecipeByItemID(passiveGLData.objectiveItemId[currentDifficulty]);
|
||||
this.currentDifficulty = currentDifficulty;
|
||||
currentAttempt = 0;
|
||||
numSuccesses = 0;
|
||||
hasMaterials = false;
|
||||
}
|
||||
|
||||
public PassiveGuildleve(Quest staticQuest, Player owner, string questDataJson) : base(staticQuest, owner)
|
||||
{
|
||||
passiveGLData = Server.GetPassiveGLGamedata(GetQuestId());
|
||||
|
||||
Dictionary<string, object> questData = null;
|
||||
|
||||
if (questDataJson != null)
|
||||
questData = JsonConvert.DeserializeObject<Dictionary<string, object>>(questDataJson);
|
||||
|
||||
if (questData == null)
|
||||
questData = new Dictionary<string, object>();
|
||||
|
||||
currentDifficulty = questData.ContainsKey("currentDifficulty") ? (byte)questData["currentDifficulty"] : (byte)0;
|
||||
currentAttempt = questData.ContainsKey("currentAttempt") ? (short)questData["currentAttempt"] : (short)0;
|
||||
numSuccesses = questData.ContainsKey("numSuccesses") ? (short)questData["numSuccesses"] : (short)0;
|
||||
hasMaterials = questData.ContainsKey("hasMaterials") ? (bool)questData["hasMaterials"] : false;
|
||||
|
||||
targetRecipe = Server.ResolveRecipe().GetRecipeByItemID(passiveGLData.objectiveItemId[currentDifficulty]);
|
||||
}
|
||||
|
||||
public void CraftSuccess()
|
||||
{
|
||||
numSuccesses++;
|
||||
currentAttempt++;
|
||||
}
|
||||
|
||||
public void CraftFail()
|
||||
{
|
||||
currentAttempt++;
|
||||
}
|
||||
|
||||
public Recipe GetRecipe()
|
||||
{
|
||||
return targetRecipe;
|
||||
}
|
||||
|
||||
public int GetNumberOfSuccesses()
|
||||
{
|
||||
return numSuccesses;
|
||||
}
|
||||
|
||||
public int GetRemainingMaterials()
|
||||
{
|
||||
return passiveGLData.numberOfAttempts[currentDifficulty] - currentAttempt;
|
||||
}
|
||||
public int GetCurrentAttempt()
|
||||
{
|
||||
return currentAttempt;
|
||||
}
|
||||
|
||||
public int GetMaxAttempts()
|
||||
{
|
||||
return passiveGLData.numberOfAttempts[currentDifficulty];
|
||||
}
|
||||
|
||||
public byte GetCurrentDifficulty()
|
||||
{
|
||||
return currentDifficulty;
|
||||
}
|
||||
|
||||
public bool HasMaterials()
|
||||
{
|
||||
return hasMaterials;
|
||||
}
|
||||
|
||||
public PassiveGuildleveData GetPassiveGLData()
|
||||
{
|
||||
return passiveGLData;
|
||||
}
|
||||
|
||||
public override void SaveData()
|
||||
{
|
||||
Database.SaveQuest(owner, this);
|
||||
}
|
||||
|
||||
public override string GetSerializedQuestData()
|
||||
{
|
||||
Dictionary<string, object> questData = new Dictionary<string, object>
|
||||
{
|
||||
{ "currentDifficulty", currentDifficulty },
|
||||
{ "currentAttempt", currentAttempt },
|
||||
{ "itemsCompleted", numSuccesses },
|
||||
{ "hasMaterials", hasMaterials }
|
||||
};
|
||||
return JsonConvert.SerializeObject(questData, Formatting.Indented);
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ along with Project Meteor Server. If not, see <https:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Meteor.Map.lua;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -28,40 +29,18 @@ namespace Meteor.Map.Actors
|
||||
{
|
||||
class Quest : Actor
|
||||
{
|
||||
private Player owner;
|
||||
private uint currentPhase = 0;
|
||||
private uint questFlags = 0;
|
||||
private Dictionary<string, Object> questData = new Dictionary<string, object>();
|
||||
protected Player owner;
|
||||
|
||||
public Quest(uint actorID, string name)
|
||||
: base(actorID)
|
||||
{
|
||||
actorName = name;
|
||||
actorName = name;
|
||||
}
|
||||
|
||||
public Quest(Player owner, uint actorID, string name, string questDataJson, uint questFlags, uint currentPhase)
|
||||
: base(actorID)
|
||||
public Quest(Quest staticQuest, Player owner) : base(staticQuest.actorId)
|
||||
{
|
||||
this.owner = owner;
|
||||
actorName = name;
|
||||
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
|
||||
actorName = staticQuest.actorName;
|
||||
}
|
||||
|
||||
public uint GetQuestId()
|
||||
@@ -69,81 +48,8 @@ namespace Meteor.Map.Actors
|
||||
return actorId & 0xFFFFF;
|
||||
}
|
||||
|
||||
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 string GetSerializedQuestData()
|
||||
{
|
||||
return JsonConvert.SerializeObject(questData, Formatting.Indented);
|
||||
}
|
||||
|
||||
public void SaveData()
|
||||
{
|
||||
Database.SaveQuest(owner, this);
|
||||
}
|
||||
public virtual void SaveData() { }
|
||||
public virtual string GetSerializedQuestData() { return null; }
|
||||
|
||||
public void DoCompletionCheck()
|
||||
{
|
||||
@@ -161,5 +67,45 @@ namespace Meteor.Map.Actors
|
||||
owner.SendGameMessage(owner, Server.GetWorldManager().GetActor(), 25236, 0x20, (object)GetQuestId());
|
||||
}
|
||||
|
||||
public static Quest LoadQuestDB(Player player, MySqlDataReader reader)
|
||||
{
|
||||
uint questID = 0xA0F00000 | reader.GetUInt32("questId");
|
||||
Quest staticQuest = Server.GetStaticActors(questID) as Quest;
|
||||
string questData = null;
|
||||
|
||||
if (!reader.IsDBNull(reader.GetOrdinal("questData")))
|
||||
questData = reader.GetString("questData");
|
||||
else
|
||||
questData = "{}";
|
||||
|
||||
if (staticQuest.IsScenario())
|
||||
{
|
||||
uint questFlags = 0;
|
||||
uint currentPhase = 0;
|
||||
|
||||
if (!reader.IsDBNull(reader.GetOrdinal("questFlags")))
|
||||
questFlags = reader.GetUInt32("questFlags");
|
||||
|
||||
if (!reader.IsDBNull(reader.GetOrdinal("currentPhase")))
|
||||
currentPhase = reader.GetUInt32("currentPhase");
|
||||
|
||||
return new Scenario(staticQuest, player, questData, questFlags, currentPhase);
|
||||
}
|
||||
else if (staticQuest.IsCraftPassiveGuildleve())
|
||||
{
|
||||
return new PassiveGuildleve(staticQuest, player, questData);
|
||||
}
|
||||
throw new NotImplementedException("Unknown quest type added");
|
||||
}
|
||||
|
||||
public bool IsScenario()
|
||||
{
|
||||
return !IsCraftPassiveGuildleve();
|
||||
}
|
||||
|
||||
public bool IsCraftPassiveGuildleve()
|
||||
{
|
||||
return GetQuestId() > 120000 && GetQuestId() < 121024;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
140
Map Server/Actors/Quest/Scenario.cs
Normal file
140
Map Server/Actors/Quest/Scenario.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
===========================================================================
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user