-
Notifications
You must be signed in to change notification settings - Fork 98
Initial Card System Support #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SalmanTKhan
wants to merge
2
commits into
NoCode-NoLife:master
Choose a base branch
from
SalmanTKhan:add/cards
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
CREATE TABLE IF NOT EXISTS `cards` ( | ||
`characterId` bigint(20) NOT NULL, | ||
`itemId` bigint(20) NOT NULL, | ||
`sort` int(11) NOT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
ALTER TABLE `cards` | ||
ADD PRIMARY KEY (`characterId`,`itemId`), | ||
ADD KEY `itemId` (`itemId`); | ||
|
||
ALTER TABLE `cards` | ||
ADD CONSTRAINT `cards_ibfk_1` FOREIGN KEY (`characterId`) REFERENCES `characters` (`characterId`) ON DELETE CASCADE ON UPDATE CASCADE, | ||
ADD CONSTRAINT `cards_ibfk_2` FOREIGN KEY (`itemId`) REFERENCES `items` (`itemUniqueId`) ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
CREATE TABLE IF NOT EXISTS `item_properties` ( | ||
`propertyId` bigint(20) NOT NULL, | ||
`itemId` bigint(20) NOT NULL, | ||
`name` varchar(64) NOT NULL, | ||
`type` varchar(1) NOT NULL, | ||
`value` varchar(255) NOT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
|
||
ALTER TABLE `item_properties` | ||
ADD PRIMARY KEY (`propertyId`), | ||
ADD KEY `itemId` (`itemId`); | ||
|
||
|
||
ALTER TABLE `item_properties` | ||
MODIFY `propertyId` bigint(20) NOT NULL AUTO_INCREMENT; | ||
|
||
ALTER TABLE `item_properties` | ||
ADD CONSTRAINT `item_properties_ibfk_1` FOREIGN KEY (`itemId`) REFERENCES `items` (`itemUniqueId`) ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Melia.Shared.Game.Const; | ||
using Newtonsoft.Json.Linq; | ||
using Yggdrasil.Data.JSON; | ||
|
||
namespace Melia.Shared.Data.Database | ||
{ | ||
[Serializable] | ||
public class ItemExpData | ||
{ | ||
public EquipExpGroup Group { get; set; } | ||
public int Level { get; set; } | ||
public int Exp { get; set; } | ||
public int GainExp { get; set; } | ||
public float PriceMultiplier { get; set; } = 1.0f; | ||
} | ||
|
||
/// <summary> | ||
/// Item Exp database. | ||
/// </summary> | ||
public class ItemExpDb : DatabaseJson<ItemExpData> | ||
{ | ||
private readonly List<ItemExpData> _itemExp = new(); | ||
|
||
public int GetGainExp(EquipExpGroup group, int level = 1) | ||
{ | ||
var exp = this.Entries.Find(a => a.Group == group && a.Level == 1)?.GainExp ?? 0; | ||
|
||
return exp; | ||
} | ||
|
||
/// <summary> | ||
/// Returns exp required to reach the next level after the | ||
/// given one. | ||
/// </summary> | ||
/// <remarks> | ||
/// Returns 0 if there's no data for the given level, | ||
/// i.e. if it's the last one or goes beyond. | ||
/// </remarks> | ||
/// <param name="level"></param> | ||
/// <returns></returns> | ||
/// <exception cref="ArgumentException">Thrown if level is invalid (< 1).</exception> | ||
public int GetNextExp(EquipExpGroup group, int level) | ||
{ | ||
if (level < 1) | ||
throw new ArgumentException("Invalid level (too low)."); | ||
|
||
if (level > _itemExp.Count) | ||
return 0; | ||
|
||
var index = level - 1; | ||
var exp = this.Entries.Where(a => a.Group == group).OrderBy(a => a.Level).ToList()[index]; | ||
|
||
return exp.Exp; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the EXP required to reach the given level. | ||
/// </summary> | ||
/// <param name="exp"></param> | ||
/// <returns></returns> | ||
public int GetLevel(EquipExpGroup group, int exp) | ||
{ | ||
var result = 1; | ||
var data = this.Entries.Where(a => a.Group == group && a.Exp <= exp).OrderBy(a => a.Level).LastOrDefault(); | ||
if (data != null) | ||
result = data.Level; | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the price multiplier at a certain level. | ||
/// </summary> | ||
/// <param name="level"></param> | ||
/// <returns></returns> | ||
public float GetPriceMultiplier(EquipExpGroup group, int level) | ||
{ | ||
var result = 1f; | ||
var data = this.Entries.Find(a => a.Level == level); | ||
if (data != null) | ||
result = data.PriceMultiplier; | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the EXP required to reach the given level. | ||
/// </summary> | ||
/// <param name="level"></param> | ||
/// <returns></returns> | ||
public int GetTotalExp(EquipExpGroup group, int level) | ||
{ | ||
var result = 0; | ||
for (var i = 1; i < level; ++i) | ||
result += this.GetNextExp(group, i); | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the max level. | ||
/// </summary> | ||
/// <returns></returns> | ||
public int GetMaxLevel(EquipExpGroup group) | ||
{ | ||
return _itemExp.Where(a => a.Group == group && a.Exp > 0).Max(a => a.Level); | ||
} | ||
|
||
/// <summary> | ||
/// Reads given entry and adds it to the database. | ||
/// </summary> | ||
/// <remarks> | ||
/// Uses the JSON database to be fed its entries, but doesn't | ||
/// adhere to the Entries format and uses custom lists instead. | ||
/// </remarks> | ||
/// <param name="entry"></param> | ||
protected override void ReadEntry(JObject entry) | ||
{ | ||
|
||
entry.AssertNotMissing("level", "exp"); | ||
|
||
var data = new ItemExpData(); | ||
|
||
data.Group = entry.ReadEnum("group", EquipExpGroup.None); | ||
data.Level = entry.ReadInt("level"); | ||
data.Exp = entry.ReadInt("exp"); | ||
data.GainExp = entry.ReadInt("gainExp"); | ||
|
||
this.Entries.Add(data); | ||
} | ||
|
||
protected override void AfterLoad() | ||
{ | ||
_itemExp.AddRange(this.Entries); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,38 @@ protected void SaveProperties(string databaseName, string idName, long id, Prope | |
} | ||
} | ||
|
||
/// <summary> | ||
/// Saves properties to the given database, with the id. | ||
/// </summary> | ||
/// <param name="databaseName"></param> | ||
/// <param name="idName"></param> | ||
/// <param name="id"></param> | ||
/// <param name="properties"></param> | ||
protected void SaveProperties(string databaseName, string idName, long id, Properties properties, MySqlConnection conn, MySqlTransaction trans) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the current |
||
{ | ||
using (var cmd = new MySqlCommand($"DELETE FROM `{databaseName}` WHERE `{idName}` = @id", conn, trans)) | ||
{ | ||
cmd.Parameters.AddWithValue("@id", id); | ||
cmd.ExecuteNonQuery(); | ||
} | ||
|
||
foreach (var property in properties.GetAll()) | ||
{ | ||
var typeStr = property is FloatProperty ? "f" : "s"; | ||
var valueStr = property.Serialize(); | ||
|
||
using (var cmd = new InsertCommand($"INSERT INTO `{databaseName}` {{0}}", conn, trans)) | ||
{ | ||
cmd.Set(idName, id); | ||
cmd.Set("name", property.Ident); | ||
cmd.Set("type", typeStr); | ||
cmd.Set("value", valueStr); | ||
|
||
cmd.Execute(); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Updates the login state of the given account. | ||
/// </summary> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.