forked from SoDOff-Project/sodoff
support for importer
- XP import interface - allow overwrite dragon creation date for importer
This commit is contained in:
parent
99fe6cca02
commit
ada1fd5338
@ -66,6 +66,44 @@ public class AchievementController : Controller {
|
||||
return Ok(XmlUtil.ReadResourceXmlString("rewardmultiplier"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("AchievementWebService.asmx/SetDragonXP")] // used by dragonrescue-import
|
||||
public IActionResult SetDragonXP([FromForm] string apiToken, [FromForm] string dragonId, [FromForm] int value) {
|
||||
Viking? viking = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.Viking;
|
||||
if (viking is null) {
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
Dragon? dragon = viking.Dragons.FirstOrDefault(e => e.EntityId == dragonId);
|
||||
if (dragon is null) {
|
||||
return Conflict("Dragon not found");
|
||||
}
|
||||
|
||||
dragon.PetXP = value;
|
||||
ctx.SaveChanges();
|
||||
|
||||
return Ok("OK");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("AchievementWebService.asmx/SetPlayerXP")] // used by dragonrescue-import
|
||||
public IActionResult SetDragonXP([FromForm] string apiToken, [FromForm] int type, [FromForm] int value) {
|
||||
Viking? viking = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.Viking;
|
||||
if (viking is null) {
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (!Enum.IsDefined(typeof(AchievementPointTypes), type)) {
|
||||
return Conflict("Invalid XP type");
|
||||
}
|
||||
|
||||
AchievementPointTypes xpType = (AchievementPointTypes)type;
|
||||
// TODO: we allow set currencies here, do we want this?
|
||||
achievementService.SetAchievementPoints(viking, xpType, value);
|
||||
ctx.SaveChanges();
|
||||
return Ok("OK");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("AchievementWebService.asmx/GetAchievementsByUserID")]
|
||||
|
@ -451,7 +451,7 @@ public class ContentController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("v3/ContentWebService.asmx/SetRaisedPet")]
|
||||
public IActionResult SetRaisedPet([FromForm] string apiToken, [FromForm] string request) {
|
||||
public IActionResult SetRaisedPet([FromForm] string apiToken, [FromForm] string request, [FromForm] bool? import) {
|
||||
Viking? viking = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.Viking;
|
||||
if (viking is null) {
|
||||
// TODO: result for invalid session
|
||||
@ -468,7 +468,7 @@ public class ContentController : Controller {
|
||||
});
|
||||
}
|
||||
|
||||
dragon.RaisedPetData = XmlUtil.SerializeXml(UpdateDragon(dragon, raisedPetRequest.RaisedPetData));
|
||||
dragon.RaisedPetData = XmlUtil.SerializeXml(UpdateDragon(dragon, raisedPetRequest.RaisedPetData, import ?? false));
|
||||
ctx.Update(dragon);
|
||||
ctx.SaveChanges();
|
||||
|
||||
@ -997,7 +997,7 @@ public class ContentController : Controller {
|
||||
}
|
||||
|
||||
// Needs to merge newDragonData into dragonData
|
||||
private RaisedPetData UpdateDragon (Dragon dragon, RaisedPetData newDragonData) {
|
||||
private RaisedPetData UpdateDragon (Dragon dragon, RaisedPetData newDragonData, bool import = false) {
|
||||
RaisedPetData dragonData = XmlUtil.DeserializeXml<RaisedPetData>(dragon.RaisedPetData);
|
||||
|
||||
// The simple attributes
|
||||
@ -1018,11 +1018,13 @@ public class ContentController : Controller {
|
||||
if (newDragonData.Colors is not null) dragonData.Colors = newDragonData.Colors;
|
||||
if (newDragonData.Skills is not null) dragonData.Skills = newDragonData.Skills;
|
||||
if (newDragonData.States is not null) dragonData.States = newDragonData.States;
|
||||
|
||||
|
||||
dragonData.IsSelected = newDragonData.IsSelected;
|
||||
dragonData.IsReleased = newDragonData.IsReleased;
|
||||
dragonData.UpdateDate = newDragonData.UpdateDate;
|
||||
|
||||
if (import) dragonData.CreateDate = newDragonData.CreateDate;
|
||||
|
||||
// Attributes is special - the entire list isn't re-sent, so we need to manually update each
|
||||
if (dragonData.Attributes is null) dragonData.Attributes = new RaisedPetAttribute[] { };
|
||||
List<RaisedPetAttribute> attribs = dragonData.Attributes.ToList();
|
||||
|
@ -58,6 +58,21 @@ namespace sodoff.Services {
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAchievementPoints(Viking viking, AchievementPointTypes type, int value) {
|
||||
if (type == AchievementPointTypes.DragonXP) {
|
||||
viking.SelectedDragon.PetXP = value;
|
||||
} else if (type != null) {
|
||||
AchievementPoints xpPoints = viking.AchievementPoints.FirstOrDefault(a => a.Type == (int)type);
|
||||
if (xpPoints is null) {
|
||||
xpPoints = new AchievementPoints {
|
||||
Type = (int)type
|
||||
};
|
||||
viking.AchievementPoints.Add(xpPoints);
|
||||
}
|
||||
xpPoints.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddAchievementPoints(Viking viking, AchievementPointTypes? type, int? value) {
|
||||
if (type == AchievementPointTypes.DragonXP) {
|
||||
viking.SelectedDragon.PetXP = (viking.SelectedDragon.PetXP ?? 0) + (value ?? 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user