Skip to content

Commit

Permalink
InfectedRose.Interface:
Browse files Browse the repository at this point in the history
* An interface for adding npcs, missions, and zones.
* Emit SQL to run on your server.
* See README for InfectedRose.Interface for more info.
  • Loading branch information
Wincent01 committed Mar 8, 2020
1 parent f2e85df commit 078de11
Show file tree
Hide file tree
Showing 19 changed files with 600 additions and 278 deletions.
38 changes: 15 additions & 23 deletions InfectedRose.Builder/CharacterStyle.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
using System.Xml.Serialization;

namespace InfectedRose.Builder
{
[XmlRoot]
public class CharacterStyle
{
public int Chest { get; set; }

public int ChestDecal { get; set; }

public int EyeBrowStyle { get; set; }

public int EyesStyle { get; set; }

public int HairColor { get; set; }

public int HairStyle { get; set; }

public int Head { get; set; }

public int HeadColor { get; set; }

public int LeftHand { get; set; }

public int Legs { get; set; }

public int MouthStyle { get; set; }

public int RightHand { get; set; }
[XmlElement] public int Chest { get; set; } = 0;
[XmlElement] public int ChestDecal { get; set; } = 0;
[XmlElement] public int EyeBrowStyle { get; set; } = 0;
[XmlElement] public int EyesStyle { get; set; } = 0;
[XmlElement] public int HairColor { get; set; } = 0;
[XmlElement] public int HairStyle { get; set; } = 0;
[XmlElement] public int Head { get; set; } = 0;
[XmlElement] public int HeadColor { get; set; } = 0;
[XmlElement] public int LeftHand { get; set; } = 0;
[XmlElement] public int Legs { get; set; } = 0;
[XmlElement] public int MouthStyle { get; set; } = 0;
[XmlElement] public int RightHand { get; set; } = 0;
}
}
9 changes: 6 additions & 3 deletions InfectedRose.Builder/ItemReward.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Xml.Serialization;

namespace InfectedRose.Builder
{
[XmlRoot]
public class ItemReward
{
public int Lot { get; set; }
public int Count { get; set; }
[XmlElement] public int Lot { get; set; } = -1;

[XmlElement] public int Count { get; set; } = 0;
}
}
74 changes: 25 additions & 49 deletions InfectedRose.Builder/Mission.cs
Original file line number Diff line number Diff line change
@@ -1,83 +1,59 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using InfectedRose.Database;
using InfectedRose.Database.Concepts.Tables;
using InfectedRose.Database.Fdb;

namespace InfectedRose.Builder
{
[XmlRoot]
public class Mission
{
internal AccessDatabase Database { get; }
[XmlIgnore] public AccessDatabase Database { get; set; }

public int Id { get; }
[XmlElement] public int Id { get; set; }

public string Type { get; set; }
[XmlElement] public string Type { get; set; }

public string SubType { get; set; }
[XmlElement] public string SubType { get; set; }

public int UiSortOrder { get; set; }
[XmlElement] public int UiSortOrder { get; set; }

public int RewardCurrency { get; set; }
[XmlElement] public int RewardCurrency { get; set; }

public int RewardScore { get; set; }
[XmlElement] public int RewardScore { get; set; }

public bool IsMission { get; set; }
[XmlElement] public bool IsMission { get; set; }

public bool ChoiceRewards { get; set; }
[XmlElement] public bool ChoiceRewards { get; set; }

public ItemReward[] ItemRewards { get; set; } = new ItemReward[4];
[XmlElement("ItemReward")] public ItemReward[] ItemRewards { get; set; } = new ItemReward[4];

public ItemReward[] RepeatItemRewards { get; set; } = new ItemReward[4];
[XmlElement("RepeatItemReward")] public ItemReward[] RepeatItemRewards { get; set; } = new ItemReward[4];

public int[] EmoteRewards { get; set; } = new int[4];
[XmlElement("EmoteReward")] public int[] EmoteRewards { get; set; } = new int[4];

public int RewardMaxImagination { get; set; }
[XmlElement] public int RewardMaxImagination { get; set; }

public int RewardMaxHealth { get; set; }
[XmlElement] public int RewardMaxHealth { get; set; }

public int RewardMaxInventory { get; set; }
[XmlElement] public int RewardMaxInventory { get; set; }

public bool Repeatable { get; set; }
[XmlElement] public bool Repeatable { get; set; }

public int RepeatRewardCurrency { get; set; }
[XmlElement] public int RepeatRewardCurrency { get; set; }

public int MissionIconId { get; set; }
[XmlElement] public int MissionIconId { get; set; }

public string Prerequisites { get; set; }
[XmlElement] public string Prerequisites { get; set; }

public int OfferObject { get; set; }
[XmlElement] public int OfferObject { get; set; }

public int TargetObject { get; set; }
[XmlElement] public int TargetObject { get; set; }

public bool InMotd { get; set; }

public List<MissionTask> Tasks { get; set; }

public Mission(AccessDatabase database)
{
Database = database;
[XmlElement] public bool InMotd { get; set; }

var table = database["Missions"];

Id = table.ClaimKey(333);

for (var i = 0; i < 4; i++)
{
ItemRewards[i] = new ItemReward
{
Lot = -1,
Count = 0
};

RepeatItemRewards[i] = new ItemReward
{
Lot = -1,
Count = 0
};

EmoteRewards[i] = -1;
}
}
[XmlElement("Task")] public MissionTask[] Tasks { get; set; } = new MissionTask[1];

public int Build()
{
Expand Down
13 changes: 8 additions & 5 deletions InfectedRose.Builder/MissionEntry.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System.Xml.Serialization;

namespace InfectedRose.Builder
{
[XmlRoot]
public class MissionEntry
{
public int MissionId { get; set; }
public bool Offers { get; set; }
public bool Accepting { get; set; }
[XmlElement] public int MissionId { get; set; } = 300;

[XmlElement] public bool Offers { get; set; } = true;

[XmlElement] public bool Accepting { get; set; } = true;
}
}
18 changes: 10 additions & 8 deletions InfectedRose.Builder/MissionTask.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
using System.Linq;
using System.Xml.Serialization;
using InfectedRose.Database;
using InfectedRose.Database.Concepts.Tables;
using InfectedRose.Database.Generic;

namespace InfectedRose.Builder
{
[XmlRoot]
public class MissionTask
{
public int TaskType { get; set; }
[XmlElement] public int TaskType { get; set; }

public int Target { get; set; }
[XmlElement] public int Target { get; set; }

public string TargetGroup { get; set; }
[XmlElement] public string TargetGroup { get; set; }

public int TargetValue { get; set; }
[XmlElement] public int TargetValue { get; set; }

public string Parameters { get; set; }
[XmlElement] public string Parameters { get; set; }

public int IconId { get; set; }
[XmlElement] public int IconId { get; set; }

public string LargeIcon { get; set; }
[XmlElement] public string LargeIcon { get; set; }

public int LargeIconId { get; set; }
[XmlElement] public int LargeIconId { get; set; }

internal void Build(AccessDatabase database, int missionId)
{
Expand Down
41 changes: 14 additions & 27 deletions InfectedRose.Builder/Npc.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using InfectedRose.Database;
using InfectedRose.Database.Concepts;

namespace InfectedRose.Builder
{
[XmlRoot]
public class Npc
{
internal AccessDatabase Database { get; }

internal int Source { get; }

public int Lot { get; }

public string Name { get; set; }

public int InteractDistance { get; set; }

public CharacterStyle Style { get; set; } = new CharacterStyle();

public List<int> Items { get; set; } = new List<int>();

public List<MissionEntry> Missions { get; set; } = new List<MissionEntry>();
[XmlIgnore] public AccessDatabase Database { get; set; }

public Npc(AccessDatabase database, int source = 12261)
{
Database = database;
Source = source;
[XmlElement] public int Lot { get; set; } = 20000;

var table = database["Objects"];
[XmlElement] public string Name { get; set; } = "npc";

Lot = table.ClaimKey(20000);
}
[XmlElement] public int InteractDistance { get; set; } = 5;

[XmlElement] public CharacterStyle Style { get; set; } = new CharacterStyle();

[XmlElement("Item")] public int[] Items { get; set; } = new int[1];

[XmlElement("Mission")] public MissionEntry[] Missions { get; set; } = new MissionEntry[1];

public int Build()
public void Build()
{
var concept = Database.CopyObject(Source, Lot);
var concept = Database.CopyObject(12261, Lot);

concept.Row["name"].Value = Name;
concept.Row["interactionDistance"].Value = InteractDistance;
Expand Down Expand Up @@ -67,8 +56,6 @@ public int Build()
{
BuildRender(render.Row);
}

return concept.Row.Key;
}

private void BuildCharacterStyle(Column row)
Expand Down
3 changes: 3 additions & 0 deletions InfectedRose.Database/Fdb/FdbRowData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public override void Compile(HashMap map)
var b = (bool) Fields[i].value;
map += b ? 1 : 0;
break;
case DataType.Nothing:
map += 0;
break;
default:
map += Fields[i].value;
break;
Expand Down
54 changes: 46 additions & 8 deletions InfectedRose.Database/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,42 @@ public Column Create(object key, object values = null)
{
var type = Info.Data.Fields[i].type;

column.DataHeader.Data.Fields[i] = (type, GetDefault(type));
DataType newType;

switch (type)
{
case DataType.Nothing:
newType = DataType.Nothing;
break;
case DataType.Integer:
newType = DataType.Integer;
break;
case DataType.Unknown1:
newType = DataType.Integer;
break;
case DataType.Float:
newType = DataType.Float;
break;
case DataType.Text:
newType = DataType.Nothing;
break;
case DataType.Boolean:
newType = DataType.Boolean;
break;
case DataType.Bigint:
newType = DataType.Nothing;
break;
case DataType.Unknown2:
newType = DataType.Integer;
break;
case DataType.Varchar:
newType = DataType.Nothing;
break;
default:
throw new ArgumentOutOfRangeException();
}

column.DataHeader.Data.Fields[i] = (newType, GetDefault(type));
}

var primaryKey = GetKey(key) % (list.Count > 0 ? list.Count : 1);
Expand Down Expand Up @@ -340,11 +375,14 @@ public void Recalculate(int bucketSize)

var data = this.ToArray();

var sorter = data.ToList();

sorter.Sort((column, column1) => column.Key - column1.Key);
if (bucketSize == 1)
{
var sorter = data.ToList();

data = sorter.ToArray();
sorter.Sort((column, column1) => column.Key - column1.Key);

data = sorter.ToArray();
}

foreach (var column in data) column.Data.Linked = default;

Expand Down Expand Up @@ -466,9 +504,9 @@ private object GetDefault(DataType type)
DataType.Float => 0,
DataType.Boolean => false,
DataType.Unknown2 => 0,
DataType.Varchar => new FdbString(),
DataType.Text => new FdbString(),
DataType.Bigint => new FdbBitInt(),
DataType.Varchar => null,
DataType.Text => null,
DataType.Bigint => null,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
}
Expand Down
Loading

0 comments on commit 078de11

Please sign in to comment.