mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 08:18:49 -07:00
data model improvements
This commit is contained in:
parent
eb3f163fda
commit
fd831058c6
@ -22,15 +22,15 @@ public class VikingSession : Attribute, IAsyncActionFilter {
|
||||
return;
|
||||
}
|
||||
|
||||
Session? session = ctx.Sessions.FirstOrDefault(x => x.ApiToken == context.HttpContext.Request.Form[ApiToken].ToString());
|
||||
Session? session = ctx.Sessions.FirstOrDefault(x => x.ApiToken == Guid.Parse(context.HttpContext.Request.Form[ApiToken].ToString()));
|
||||
|
||||
// get viking / user id from session
|
||||
|
||||
string? userVikingId = null;
|
||||
if (Mode == Modes.VIKING || (Mode == Modes.VIKING_OR_USER && session?.UserId is null) ) {
|
||||
userVikingId = session?.VikingId;
|
||||
userVikingId = session?.VikingId?.ToString();
|
||||
} else {
|
||||
userVikingId = session?.UserId;
|
||||
userVikingId = session?.UserId?.ToString();
|
||||
}
|
||||
|
||||
if (userVikingId is null) {
|
||||
|
@ -23,7 +23,7 @@ public class AchievementController : Controller {
|
||||
public IActionResult GetPetAchievementsByUserID([FromForm] string userId) {
|
||||
// NOTE: this is public info (for mmo) - no session check
|
||||
List<UserAchievementInfo> dragonsAchievement = new List<UserAchievementInfo>();
|
||||
foreach (Dragon dragon in ctx.Dragons.Where(d => d.VikingId == userId)) {
|
||||
foreach (Dragon dragon in ctx.Dragons.Where(d => d.Viking.Uid == Guid.Parse(userId))) {
|
||||
dragonsAchievement.Add(
|
||||
achievementService.CreateUserAchievementInfo(dragon.EntityId, dragon.PetXP, AchievementPointTypes.DragonXP)
|
||||
);
|
||||
@ -64,7 +64,7 @@ public class AchievementController : Controller {
|
||||
[Route("AchievementWebService.asmx/SetDragonXP")] // used by dragonrescue-import
|
||||
[VikingSession]
|
||||
public IActionResult SetDragonXP(Viking viking, [FromForm] string dragonId, [FromForm] int value) {
|
||||
Dragon? dragon = viking.Dragons.FirstOrDefault(e => e.EntityId == dragonId);
|
||||
Dragon? dragon = viking.Dragons.FirstOrDefault(e => e.EntityId == Guid.Parse(dragonId));
|
||||
if (dragon is null) {
|
||||
return Conflict("Dragon not found");
|
||||
}
|
||||
@ -95,7 +95,7 @@ public class AchievementController : Controller {
|
||||
[Route("AchievementWebService.asmx/GetAchievementsByUserID")]
|
||||
public IActionResult GetAchievementsByUserID([FromForm] string userId) {
|
||||
// NOTE: this is public info (for mmo) - no session check
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == userId);
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == Guid.Parse(userId));
|
||||
if (viking != null) {
|
||||
return Ok(new ArrayOfUserAchievementInfo {
|
||||
UserAchievementInfo = new UserAchievementInfo[]{
|
||||
@ -107,7 +107,7 @@ public class AchievementController : Controller {
|
||||
});
|
||||
}
|
||||
|
||||
Dragon? dragon = ctx.Dragons.FirstOrDefault(e => e.EntityId == userId);
|
||||
Dragon? dragon = ctx.Dragons.FirstOrDefault(e => e.EntityId == Guid.Parse(userId));
|
||||
if (dragon != null) {
|
||||
return Ok(new ArrayOfUserAchievementInfo {
|
||||
UserAchievementInfo = new UserAchievementInfo[]{
|
||||
@ -127,8 +127,8 @@ public class AchievementController : Controller {
|
||||
ArrayOfUserAchievementInfo arrAchievements = new ArrayOfUserAchievementInfo {
|
||||
UserAchievementInfo = new UserAchievementInfo[]{
|
||||
achievementService.CreateUserAchievementInfo(viking, AchievementPointTypes.PlayerXP),
|
||||
achievementService.CreateUserAchievementInfo(viking.Id, 60000, AchievementPointTypes.PlayerFarmingXP), // TODO: placeholder until there is no leveling for farm XP
|
||||
achievementService.CreateUserAchievementInfo(viking.Id, 20000, AchievementPointTypes.PlayerFishingXP), // TODO: placeholder until there is no leveling for fishing XP
|
||||
achievementService.CreateUserAchievementInfo(viking.Uid, 60000, AchievementPointTypes.PlayerFarmingXP), // TODO: placeholder until there is no leveling for farm XP
|
||||
achievementService.CreateUserAchievementInfo(viking.Uid, 20000, AchievementPointTypes.PlayerFishingXP), // TODO: placeholder until there is no leveling for fishing XP
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class AuthenticationController : Controller {
|
||||
// Create session
|
||||
Session session = new Session {
|
||||
User = user,
|
||||
ApiToken = Guid.NewGuid().ToString(),
|
||||
ApiToken = Guid.NewGuid(),
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
|
||||
@ -55,8 +55,8 @@ public class AuthenticationController : Controller {
|
||||
var response = new ParentLoginInfo {
|
||||
UserName = user.Username,
|
||||
Email = user.Email,
|
||||
ApiToken = session.ApiToken,
|
||||
UserID = user.Id,
|
||||
ApiToken = session.ApiToken.ToString(),
|
||||
UserID = user.Id.ToString(),
|
||||
Status = MembershipUserStatus.Success,
|
||||
SendActivationReminder = false,
|
||||
UnAuthorized = false
|
||||
@ -86,12 +86,12 @@ public class AuthenticationController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("AuthenticationWebService.asmx/GetUserInfoByApiToken")]
|
||||
public IActionResult GetUserInfoByApiToken([FromForm] string apiToken, [FromForm] string apiKey) {
|
||||
public IActionResult GetUserInfoByApiToken([FromForm] Guid apiToken, [FromForm] string apiKey) {
|
||||
// First check if this is a user session
|
||||
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User;
|
||||
if (user is not null) {
|
||||
return Ok(new UserInfo {
|
||||
UserID = user.Id,
|
||||
UserID = user.Id.ToString(),
|
||||
Username = user.Username,
|
||||
MembershipID = "ef84db9-59c6-4950-b8ea-bbc1521f899b", // placeholder
|
||||
FacebookUserID = 0,
|
||||
@ -107,7 +107,7 @@ public class AuthenticationController : Controller {
|
||||
if (viking is not null)
|
||||
{
|
||||
return Ok(new UserInfo {
|
||||
UserID = viking.Id,
|
||||
UserID = viking.Uid.ToString(),
|
||||
Username = viking.Name,
|
||||
FacebookUserID = 0,
|
||||
MultiplayerEnabled = (apiKey != "a1a13a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a2a09a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a3a12a0a-7c6e-4e9b-b0f7-22034d799013"),
|
||||
@ -124,7 +124,7 @@ public class AuthenticationController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("AuthenticationWebService.asmx/IsValidApiToken_V2")]
|
||||
public IActionResult IsValidApiToken([FromForm] string apiToken) {
|
||||
public IActionResult IsValidApiToken([FromForm] Guid apiToken) {
|
||||
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User;
|
||||
Viking? viking = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.Viking;
|
||||
if (user is null && viking is null)
|
||||
@ -136,7 +136,7 @@ public class AuthenticationController : Controller {
|
||||
[Route("AuthenticationWebService.asmx/LoginChild")]
|
||||
[DecryptRequest("childUserID")]
|
||||
[EncryptResponse]
|
||||
public IActionResult LoginChild([FromForm] string parentApiToken) {
|
||||
public IActionResult LoginChild([FromForm] Guid parentApiToken) {
|
||||
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == parentApiToken)?.User;
|
||||
if (user is null) {
|
||||
return Unauthorized();
|
||||
@ -144,7 +144,7 @@ public class AuthenticationController : Controller {
|
||||
|
||||
// Find the viking
|
||||
string? childUserID = Request.Form["childUserID"];
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == childUserID);
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == Guid.Parse(childUserID));
|
||||
if (viking is null) {
|
||||
return Unauthorized();
|
||||
}
|
||||
@ -157,20 +157,20 @@ public class AuthenticationController : Controller {
|
||||
// Create session
|
||||
Session session = new Session {
|
||||
Viking = viking,
|
||||
ApiToken = Guid.NewGuid().ToString(),
|
||||
ApiToken = Guid.NewGuid(),
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
ctx.Sessions.Add(session);
|
||||
ctx.SaveChanges();
|
||||
|
||||
// Return back the api token
|
||||
return Ok(session.ApiToken);
|
||||
return Ok(session.ApiToken.ToString());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("AuthenticationWebService.asmx/DeleteAccountNotification")]
|
||||
public IActionResult DeleteAccountNotification([FromForm] string apiToken) {
|
||||
public IActionResult DeleteAccountNotification([FromForm] Guid apiToken) {
|
||||
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User;
|
||||
if (user is null)
|
||||
return Ok(MembershipUserStatus.ValidationError);
|
||||
|
@ -134,7 +134,7 @@ public class ContentController : Controller {
|
||||
} else {
|
||||
// TODO: placeholder - return 8 viking slot items
|
||||
return Ok(new CommonInventoryData {
|
||||
UserID = Guid.Parse(user.Id),
|
||||
UserID = user.Id,
|
||||
Item = new UserItemData[] {
|
||||
new UserItemData {
|
||||
UserInventoryID = 0,
|
||||
@ -168,7 +168,7 @@ public class ContentController : Controller {
|
||||
// SetCommonInventory can remove any number of items from the inventory, this checks if it's possible
|
||||
foreach (var req in request) {
|
||||
if (req.Quantity >= 0) continue;
|
||||
int inventorySum = viking.Inventory.InventoryItems.Sum(e => {if (e.ItemId == req.ItemID) return e.Quantity; return 0;});
|
||||
int inventorySum = viking.InventoryItems.Sum(e => {if (e.ItemId == req.ItemID) return e.Quantity; return 0;});
|
||||
if (inventorySum < -req.Quantity)
|
||||
return Ok(new CommonInventoryResponse { Success = false });
|
||||
}
|
||||
@ -180,7 +180,7 @@ public class ContentController : Controller {
|
||||
if (inventoryService.ItemNeedUniqueInventorySlot((int)req.ItemID)) {
|
||||
// if req.Quantity < 0 remove unique items
|
||||
for (int i=req.Quantity; i<0; ++i) {
|
||||
InventoryItem? item = viking.Inventory.InventoryItems.FirstOrDefault(e => e.ItemId == req.ItemID && e.Quantity>0);
|
||||
InventoryItem? item = viking.InventoryItems.FirstOrDefault(e => e.ItemId == req.ItemID && e.Quantity>0);
|
||||
item.Quantity--;
|
||||
}
|
||||
// if req.Quantity > 0 add unique items
|
||||
@ -211,7 +211,7 @@ public class ContentController : Controller {
|
||||
[Route("ContentWebService.asmx/UseInventory")]
|
||||
[VikingSession]
|
||||
public IActionResult UseInventory(Viking viking, [FromForm] int userInventoryId, [FromForm] int numberOfUses) {
|
||||
InventoryItem? item = viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == userInventoryId);
|
||||
InventoryItem? item = viking.InventoryItems.FirstOrDefault(e => e.Id == userInventoryId);
|
||||
if (item is null)
|
||||
return Ok(false);
|
||||
if (item.Quantity < numberOfUses)
|
||||
@ -278,7 +278,7 @@ public class ContentController : Controller {
|
||||
// TODO: Investigate SetAsSelectedPet and UnSelectOtherPets - they don't seem to do anything
|
||||
|
||||
// Update the RaisedPetData with the info
|
||||
String dragonId = Guid.NewGuid().ToString();
|
||||
string dragonId = Guid.NewGuid().ToString();
|
||||
raisedPetRequest.RaisedPetData.IsPetCreated = true;
|
||||
raisedPetRequest.RaisedPetData.RaisedPetID = 0; // Initially make zero, so the db auto-fills
|
||||
raisedPetRequest.RaisedPetData.EntityID = Guid.Parse(dragonId);
|
||||
@ -297,7 +297,7 @@ public class ContentController : Controller {
|
||||
};
|
||||
// Save the dragon in the db
|
||||
Dragon dragon = new Dragon {
|
||||
EntityId = Guid.NewGuid().ToString(),
|
||||
EntityId = Guid.NewGuid(),
|
||||
Viking = viking,
|
||||
RaisedPetData = XmlUtil.SerializeXml(raisedPetRequest.RaisedPetData),
|
||||
};
|
||||
@ -312,7 +312,7 @@ public class ContentController : Controller {
|
||||
|
||||
if (raisedPetRequest.CommonInventoryRequests is not null) {
|
||||
foreach (var req in raisedPetRequest.CommonInventoryRequests) {
|
||||
InventoryItem? item = viking.Inventory.InventoryItems.FirstOrDefault(e => e.ItemId == req.ItemID);
|
||||
InventoryItem? item = viking.InventoryItems.FirstOrDefault(e => e.ItemId == req.ItemID);
|
||||
|
||||
//Does the item exist in the user's inventory?
|
||||
if (item is null) continue; //If not, skip it.
|
||||
@ -404,14 +404,14 @@ public class ContentController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("V2/ContentWebService.asmx/GetAllActivePetsByuserId")]
|
||||
public RaisedPetData[]? GetAllActivePetsByuserId([FromForm] string userId, [FromForm] bool active) {
|
||||
public RaisedPetData[]? GetAllActivePetsByuserId([FromForm] Guid userId, [FromForm] bool active) {
|
||||
// NOTE: this is public info (for mmo) - no session check
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == userId);
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == userId);
|
||||
if (viking is null)
|
||||
return null;
|
||||
|
||||
RaisedPetData[] dragons = ctx.Dragons
|
||||
.Where(d => d.VikingId == userId && d.RaisedPetData != null)
|
||||
.Where(d => d.VikingId == viking.Id && d.RaisedPetData != null)
|
||||
.Select(d => GetRaisedPetDataFromDragon(d, viking.SelectedDragonId))
|
||||
.ToArray();
|
||||
|
||||
@ -509,9 +509,9 @@ public class ContentController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/GetImageByUserId")]
|
||||
public ImageData? GetImageByUserId([FromForm] string userId, [FromForm] string ImageType, [FromForm] int ImageSlot) {
|
||||
public ImageData? GetImageByUserId([FromForm] Guid userId, [FromForm] string ImageType, [FromForm] int ImageSlot) {
|
||||
// NOTE: this is public info (for mmo) - no session check
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == userId);
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == userId);
|
||||
if (viking is null || viking.Images is null) {
|
||||
return null;
|
||||
}
|
||||
@ -522,8 +522,8 @@ public class ContentController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("V2/ContentWebService.asmx/GetUserUpcomingMissionState")]
|
||||
public IActionResult GetUserUpcomingMissionState([FromForm] string apiToken, [FromForm] string userId, [FromForm] string apiKey) {
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Id == userId);
|
||||
public IActionResult GetUserUpcomingMissionState([FromForm] Guid apiToken, [FromForm] Guid userId, [FromForm] string apiKey) {
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Uid == userId);
|
||||
if (viking is null)
|
||||
return Ok("error");
|
||||
|
||||
@ -531,15 +531,15 @@ public class ContentController : Controller {
|
||||
foreach (var mission in viking.MissionStates.Where(x => x.MissionStatus == MissionStatus.Upcoming))
|
||||
result.Missions.Add(missionService.GetMissionWithProgress(mission.MissionId, viking.Id, apiKey));
|
||||
|
||||
result.UserID = Guid.Parse(viking.Id);
|
||||
result.UserID = viking.Uid;
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("V2/ContentWebService.asmx/GetUserActiveMissionState")]
|
||||
public IActionResult GetUserActiveMissionState([FromForm] string apiToken, [FromForm] string userId, [FromForm] string apiKey) {
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Id == userId);
|
||||
public IActionResult GetUserActiveMissionState([FromForm] Guid apiToken, [FromForm] Guid userId, [FromForm] string apiKey) {
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Uid == userId);
|
||||
if (viking is null)
|
||||
return Ok("error");
|
||||
|
||||
@ -551,15 +551,15 @@ public class ContentController : Controller {
|
||||
result.Missions.Add(updatedMission);
|
||||
}
|
||||
|
||||
result.UserID = Guid.Parse(viking.Id);
|
||||
result.UserID = viking.Uid;
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("V2/ContentWebService.asmx/GetUserCompletedMissionState")]
|
||||
public IActionResult GetUserCompletedMissionState([FromForm] string apiToken, [FromForm] string userId, [FromForm] string apiKey) {
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Id == userId);
|
||||
public IActionResult GetUserCompletedMissionState([FromForm] Guid apiToken, [FromForm] Guid userId, [FromForm] string apiKey) {
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Uid == userId);
|
||||
if (viking is null)
|
||||
return Ok("error");
|
||||
|
||||
@ -567,7 +567,7 @@ public class ContentController : Controller {
|
||||
foreach (var mission in viking.MissionStates.Where(x => x.MissionStatus == MissionStatus.Completed))
|
||||
result.Missions.Add(missionService.GetMissionWithProgress(mission.MissionId, viking.Id, apiKey));
|
||||
|
||||
result.UserID = Guid.Parse(viking.Id);
|
||||
result.UserID = viking.Uid;
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -575,8 +575,8 @@ public class ContentController : Controller {
|
||||
[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/AcceptMission")]
|
||||
[VikingSession]
|
||||
public IActionResult AcceptMission(Viking viking, [FromForm] string userId, [FromForm] int missionId) {
|
||||
if (viking.Id != userId)
|
||||
public IActionResult AcceptMission(Viking viking, [FromForm] Guid userId, [FromForm] int missionId) {
|
||||
if (viking.Uid != userId)
|
||||
return Unauthorized("Can't accept not owned mission");
|
||||
|
||||
MissionState? missionState = viking.MissionStates.FirstOrDefault(x => x.MissionId == missionId);
|
||||
@ -592,8 +592,8 @@ public class ContentController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/GetUserMissionState")] // used by SoD 1.13
|
||||
public IActionResult GetUserMissionStatev1([FromForm] string userId, [FromForm] string filter, [FromForm] string apiKey) {
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Id == userId);
|
||||
public IActionResult GetUserMissionStatev1([FromForm] Guid userId, [FromForm] string filter, [FromForm] string apiKey) {
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Uid == userId);
|
||||
if (viking is null)
|
||||
return Ok("error");
|
||||
|
||||
@ -615,7 +615,7 @@ public class ContentController : Controller {
|
||||
result.Missions.Add(updatedMission);
|
||||
}
|
||||
|
||||
result.UserID = Guid.Parse(viking.Id);
|
||||
result.UserID = viking.Uid;
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -623,9 +623,9 @@ public class ContentController : Controller {
|
||||
[Produces("application/xml")]
|
||||
[Route("V2/ContentWebService.asmx/GetUserMissionState")]
|
||||
//[VikingSession(UseLock=false)]
|
||||
public IActionResult GetUserMissionState([FromForm] string userId, [FromForm] string filter, [FromForm] string apiKey) {
|
||||
public IActionResult GetUserMissionState([FromForm] Guid userId, [FromForm] string filter, [FromForm] string apiKey) {
|
||||
MissionRequestFilterV2 filterV2 = XmlUtil.DeserializeXml<MissionRequestFilterV2>(filter);
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Id == userId);
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(x => x.Uid == userId);
|
||||
if (viking is null)
|
||||
return Ok("error");
|
||||
|
||||
@ -634,7 +634,7 @@ public class ContentController : Controller {
|
||||
foreach (var m in filterV2.MissionPair)
|
||||
if (m.MissionID != null)
|
||||
result.Missions.Add(missionService.GetMissionWithProgress((int)m.MissionID, viking.Id, apiKey));
|
||||
// TODO: probably should also check for msiion based on filterV2.ProductGroupID vs mission.GroupID
|
||||
// TODO: probably should also check for mission based on filterV2.ProductGroupID vs mission.GroupID
|
||||
} else {
|
||||
if (filterV2.GetCompletedMission ?? false) {
|
||||
foreach (var mission in viking.MissionStates.Where(x => x.MissionStatus == MissionStatus.Completed))
|
||||
@ -645,7 +645,7 @@ public class ContentController : Controller {
|
||||
}
|
||||
}
|
||||
|
||||
result.UserID = Guid.Parse(viking.Id);
|
||||
result.UserID = viking.Uid;
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -653,11 +653,11 @@ public class ContentController : Controller {
|
||||
[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/SetTaskState")] // used by SoD 1.13
|
||||
[VikingSession(UseLock=true)]
|
||||
public IActionResult SetTaskStatev1(Viking viking, [FromForm] string userId, [FromForm] int missionId, [FromForm] int taskId, [FromForm] bool completed, [FromForm] string xmlPayload, [FromForm] string apiKey) {
|
||||
if (viking.Id != userId)
|
||||
public IActionResult SetTaskStatev1(Viking viking, [FromForm] Guid userId, [FromForm] int missionId, [FromForm] int taskId, [FromForm] bool completed, [FromForm] string xmlPayload, [FromForm] string apiKey) {
|
||||
if (viking.Uid != userId)
|
||||
return Unauthorized("Can't set not owned task");
|
||||
|
||||
List<MissionCompletedResult> results = missionService.UpdateTaskProgress(missionId, taskId, userId, completed, xmlPayload, apiKey);
|
||||
List<MissionCompletedResult> results = missionService.UpdateTaskProgress(missionId, taskId, viking.Id, completed, xmlPayload, apiKey);
|
||||
|
||||
SetTaskStateResult taskResult = new SetTaskStateResult {
|
||||
Success = true,
|
||||
@ -674,11 +674,11 @@ public class ContentController : Controller {
|
||||
[Produces("application/xml")]
|
||||
[Route("V2/ContentWebService.asmx/SetTaskState")]
|
||||
[VikingSession]
|
||||
public IActionResult SetTaskState(Viking viking, [FromForm] string userId, [FromForm] int missionId, [FromForm] int taskId, [FromForm] bool completed, [FromForm] string xmlPayload, [FromForm] string apiKey) {
|
||||
if (viking.Id != userId)
|
||||
public IActionResult SetTaskState(Viking viking, [FromForm] Guid userId, [FromForm] int missionId, [FromForm] int taskId, [FromForm] bool completed, [FromForm] string xmlPayload, [FromForm] string apiKey) {
|
||||
if (viking.Uid != userId)
|
||||
return Unauthorized("Can't set not owned task");
|
||||
|
||||
List<MissionCompletedResult> results = missionService.UpdateTaskProgress(missionId, taskId, userId, completed, xmlPayload, apiKey);
|
||||
List<MissionCompletedResult> results = missionService.UpdateTaskProgress(missionId, taskId, viking.Id, completed, xmlPayload, apiKey);
|
||||
|
||||
SetTaskStateResult taskResult = new SetTaskStateResult {
|
||||
Success = true,
|
||||
@ -707,7 +707,7 @@ public class ContentController : Controller {
|
||||
var req = XmlUtil.DeserializeXml<RedeemRequest>(request);
|
||||
|
||||
// get and reduce quantity of box item
|
||||
InventoryItem? invItem = viking.Inventory.InventoryItems.FirstOrDefault(e => e.ItemId == req.ItemID);
|
||||
InventoryItem? invItem = viking.InventoryItems.FirstOrDefault(e => e.ItemId == req.ItemID);
|
||||
if (invItem is null || invItem.Quantity < 1) {
|
||||
return Ok(new CommonInventoryResponse{ Success = false });
|
||||
}
|
||||
@ -804,9 +804,9 @@ public class ContentController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/GetUserRoomItemPositions")]
|
||||
public IActionResult GetUserRoomItemPositions([FromForm] string userId, [FromForm] string roomID) {
|
||||
public IActionResult GetUserRoomItemPositions([FromForm] Guid userId, [FromForm] string roomID) {
|
||||
// NOTE: this is public info (for mmo) - no session check
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == userId);
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == userId);
|
||||
|
||||
if (roomID is null)
|
||||
roomID = "";
|
||||
@ -862,7 +862,7 @@ public class ContentController : Controller {
|
||||
// NOTE: this is public info (for mmo) - no session check
|
||||
// TODO: Categories are not supported
|
||||
UserRoomGetRequest userRoomRequest = XmlUtil.DeserializeXml<UserRoomGetRequest>(request);
|
||||
ICollection<Room>? rooms = ctx.Vikings.FirstOrDefault(x => x.Id == userRoomRequest.UserID.ToString())?.Rooms;
|
||||
ICollection<Room>? rooms = ctx.Vikings.FirstOrDefault(x => x.Uid == userRoomRequest.UserID)?.Rooms;
|
||||
UserRoomResponse response = new UserRoomResponse { UserRoomList = new List<UserRoom>() };
|
||||
if (rooms is null)
|
||||
return Ok(response);
|
||||
@ -873,7 +873,7 @@ public class ContentController : Controller {
|
||||
if (room.RoomId != "") {
|
||||
// farm expansion room: RoomId is Id for expansion item
|
||||
if (Int32.TryParse(room.RoomId, out int inventoryItemId)) {
|
||||
InventoryItem? item = room.Viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == inventoryItemId);
|
||||
InventoryItem? item = room.Viking.InventoryItems.FirstOrDefault(e => e.Id == inventoryItemId);
|
||||
if (item != null) {
|
||||
itemID = item.ItemId;
|
||||
}
|
||||
@ -966,7 +966,7 @@ public class ContentController : Controller {
|
||||
RollUserItemRequest req = XmlUtil.DeserializeXml<RollUserItemRequest>(request);
|
||||
|
||||
// get item
|
||||
InventoryItem? invItem = viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == req.UserInventoryID);
|
||||
InventoryItem? invItem = viking.InventoryItems.FirstOrDefault(e => e.Id == req.UserInventoryID);
|
||||
if (invItem is null)
|
||||
return Ok(new RollUserItemResponse { Status = Status.ItemNotFound });
|
||||
|
||||
@ -1061,7 +1061,7 @@ public class ContentController : Controller {
|
||||
try {
|
||||
if (req.BluePrintInventoryID != null) {
|
||||
blueprintItem = itemService.GetItem(
|
||||
viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == req.BluePrintInventoryID).ItemId
|
||||
viking.InventoryItems.FirstOrDefault(e => e.Id == req.BluePrintInventoryID).ItemId
|
||||
);
|
||||
} else {
|
||||
blueprintItem = itemService.GetItem(req.BluePrintItemID ?? -1);
|
||||
@ -1074,9 +1074,9 @@ public class ContentController : Controller {
|
||||
|
||||
// remove items from DeductibleItemInventoryMaps and BluePrintFuseItemMaps
|
||||
foreach (var item in req.DeductibleItemInventoryMaps) {
|
||||
InventoryItem? invItem = viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == item.UserInventoryID);
|
||||
InventoryItem? invItem = viking.InventoryItems.FirstOrDefault(e => e.Id == item.UserInventoryID);
|
||||
if (invItem is null) {
|
||||
invItem = viking.Inventory.InventoryItems.FirstOrDefault(e => e.ItemId == item.ItemID);
|
||||
invItem = viking.InventoryItems.FirstOrDefault(e => e.ItemId == item.ItemID);
|
||||
}
|
||||
if (invItem is null || invItem.Quantity < item.Quantity) {
|
||||
return Ok(new FuseItemsResponse { Status = Status.ItemNotFound });
|
||||
@ -1087,10 +1087,10 @@ public class ContentController : Controller {
|
||||
if (item.UserInventoryID < 0) {
|
||||
continue; // TODO: what we should do in this case?
|
||||
}
|
||||
InventoryItem? invItem = viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == item.UserInventoryID);
|
||||
InventoryItem? invItem = viking.InventoryItems.FirstOrDefault(e => e.Id == item.UserInventoryID);
|
||||
if (invItem is null)
|
||||
return Ok(new FuseItemsResponse { Status = Status.ItemNotFound });
|
||||
viking.Inventory.InventoryItems.Remove(invItem);
|
||||
viking.InventoryItems.Remove(invItem);
|
||||
}
|
||||
// NOTE: we haven't saved any changes so far ... so we can safely interrupt "fusing" by return in loops above
|
||||
|
||||
@ -1196,7 +1196,7 @@ public class ContentController : Controller {
|
||||
case ActionType.MoveToInventory:
|
||||
// item is in inventory in result of ApplyRewards ... only add to itemsAddedToInventory
|
||||
itemsAddedToInventory.Add (new CommonInventoryResponseRewardBinItem {
|
||||
ItemID = viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == actionMap.ID).ItemId,
|
||||
ItemID = viking.InventoryItems.FirstOrDefault(e => e.Id == actionMap.ID).ItemId,
|
||||
CommonInventoryID = actionMap.ID,
|
||||
Quantity = 0,
|
||||
UserItemStatsMapID = actionMap.ID
|
||||
@ -1333,7 +1333,7 @@ public class ContentController : Controller {
|
||||
selectedDragonId = dragon.Viking.SelectedDragonId;
|
||||
RaisedPetData data = XmlUtil.DeserializeXml<RaisedPetData>(dragon.RaisedPetData);
|
||||
data.RaisedPetID = dragon.Id;
|
||||
data.EntityID = Guid.Parse(dragon.EntityId);
|
||||
data.EntityID = dragon.EntityId;
|
||||
data.IsSelected = (selectedDragonId == dragon.Id);
|
||||
return data;
|
||||
}
|
||||
@ -1393,7 +1393,7 @@ public class ContentController : Controller {
|
||||
return null;
|
||||
}
|
||||
|
||||
string imageUrl = string.Format("{0}://{1}/RawImage/{2}/{3}/{4}.jpg", HttpContext.Request.Scheme, HttpContext.Request.Host, viking.Id, ImageType, ImageSlot);
|
||||
string imageUrl = string.Format("{0}://{1}/RawImage/{2}/{3}/{4}.jpg", HttpContext.Request.Scheme, HttpContext.Request.Host, viking.Uid, ImageType, ImageSlot);
|
||||
|
||||
return new ImageData {
|
||||
ImageURL = imageUrl,
|
||||
|
@ -21,8 +21,8 @@ public class ImageController : Controller {
|
||||
|
||||
[HttpGet]
|
||||
[Route("RawImage/{VikingId}/{ImageType}/{ImageSlot}.jpg")]
|
||||
public IActionResult RawImage(String VikingId, String ImageType, int ImageSlot) {
|
||||
Image? image = ctx.Images.FirstOrDefault(e => e.VikingId == VikingId && e.ImageType == ImageType && e.ImageSlot == ImageSlot);
|
||||
public IActionResult RawImage(string VikingId, string ImageType, int ImageSlot) {
|
||||
Image? image = ctx.Images.FirstOrDefault(e => e.Viking.Uid == Guid.Parse(VikingId) && e.ImageType == ImageType && e.ImageSlot == ImageSlot);
|
||||
if (image is null || image.ImageData is null) {
|
||||
return NotFound();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class MembershipController : Controller {
|
||||
return Ok();
|
||||
|
||||
ChildList profiles = new ChildList();
|
||||
profiles.strings = user.Vikings.Select(viking => viking.Id + ", " + viking.Name).ToArray();
|
||||
profiles.strings = user.Vikings.Select(viking => viking.Uid + ", " + viking.Name).ToArray();
|
||||
|
||||
return Ok(profiles);
|
||||
}
|
||||
|
@ -19,10 +19,10 @@ public class ProfileController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("ProfileWebService.asmx/GetUserProfileByUserID")]
|
||||
public IActionResult GetUserProfileByUserID([FromForm] string userId, [FromForm] string apiKey) {
|
||||
public IActionResult GetUserProfileByUserID([FromForm] Guid userId, [FromForm] string apiKey) {
|
||||
// NOTE: this is public info (for mmo) - no session check
|
||||
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == userId);
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == userId);
|
||||
if (viking is null) {
|
||||
return Ok(new UserProfileData());
|
||||
// NOTE: do not return `Conflict("Viking not found")` due to client side error handling
|
||||
@ -113,7 +113,7 @@ public class ProfileController : Controller {
|
||||
AvatarData avatarData = null;
|
||||
if (viking.AvatarSerialized is not null) {
|
||||
avatarData = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized);
|
||||
avatarData.Id = viking.Inventory.Id;
|
||||
avatarData.Id = viking.Id;
|
||||
}
|
||||
|
||||
if (avatarData != null && (apiKey == "a3a12a0a-7c6e-4e9b-b0f7-22034d799013")) {
|
||||
@ -135,8 +135,8 @@ public class ProfileController : Controller {
|
||||
AvatarData = avatarData,
|
||||
UserInfo = new UserInfo {
|
||||
MembershipID = "ef84db9-59c6-4950-b8ea-bbc1521f899b", // placeholder
|
||||
UserID = viking.Id,
|
||||
ParentUserID = viking.UserId,
|
||||
UserID = viking.Uid.ToString(),
|
||||
ParentUserID = viking.UserId.ToString(),
|
||||
Username = viking.Name,
|
||||
FirstName = viking.Name,
|
||||
MultiplayerEnabled = (apiKey != "a1a13a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a2a09a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a3a12a0a-7c6e-4e9b-b0f7-22034d799013"),
|
||||
@ -149,7 +149,7 @@ public class ProfileController : Controller {
|
||||
FacebookUserID = 0
|
||||
},
|
||||
UserSubscriptionInfo = new UserSubscriptionInfo {
|
||||
UserID = viking.UserId,
|
||||
UserID = viking.UserId.ToString(),
|
||||
MembershipID = 130687131, // placeholder
|
||||
SubscriptionTypeID = 1, // placeholder
|
||||
SubscriptionDisplayName = "Member", // placeholder
|
||||
@ -168,11 +168,11 @@ public class ProfileController : Controller {
|
||||
};
|
||||
|
||||
return new UserProfileData {
|
||||
ID = viking.Id,
|
||||
ID = viking.Uid.ToString(),
|
||||
AvatarInfo = avatar,
|
||||
AchievementCount = 0,
|
||||
MythieCount = 0,
|
||||
AnswerData = new UserAnswerData { UserID = viking.Id },
|
||||
AnswerData = new UserAnswerData { UserID = viking.Uid.ToString() },
|
||||
GameCurrency = 65536,
|
||||
CashCurrency = 65536,
|
||||
ActivityCount = 0,
|
||||
|
@ -27,13 +27,13 @@ public class RegistrationController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("v3/RegistrationWebService.asmx/DeleteProfile")]
|
||||
public IActionResult DeleteProfile([FromForm] string apiToken, [FromForm] string userID) {
|
||||
public IActionResult DeleteProfile([FromForm] Guid apiToken, [FromForm] Guid userID) {
|
||||
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User;
|
||||
if (user is null) {
|
||||
return Ok(DeleteProfileStatus.OWNER_ID_NOT_FOUND);
|
||||
}
|
||||
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == userID);
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == userID);
|
||||
if (viking is null) {
|
||||
return Ok(DeleteProfileStatus.PROFILE_NOT_FOUND);
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class RegistrationController : Controller {
|
||||
public IActionResult RegisterParent() {
|
||||
ParentRegistrationData data = XmlUtil.DeserializeXml<ParentRegistrationData>(Request.Form["parentRegistrationData"]);
|
||||
User u = new User {
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
Id = Guid.NewGuid(),
|
||||
Username = data.ChildList[0].ChildName,
|
||||
Password = new PasswordHasher<object>().HashPassword(null, data.Password),
|
||||
Email = data.Email
|
||||
@ -73,14 +73,14 @@ public class RegistrationController : Controller {
|
||||
ParentLoginInfo pli = new ParentLoginInfo {
|
||||
UserName = u.Username,
|
||||
ApiToken = Guid.NewGuid().ToString(),
|
||||
UserID = u.Id,
|
||||
UserID = u.Id.ToString(),
|
||||
Status = MembershipUserStatus.Success,
|
||||
UnAuthorized = false
|
||||
};
|
||||
|
||||
var response = new RegistrationResult {
|
||||
ParentLoginInfo = pli,
|
||||
UserID = u.Id,
|
||||
UserID = u.Id.ToString(),
|
||||
Status = MembershipUserStatus.Success,
|
||||
ApiToken = Guid.NewGuid().ToString()
|
||||
};
|
||||
@ -94,7 +94,7 @@ public class RegistrationController : Controller {
|
||||
[Route("V4/RegistrationWebService.asmx/RegisterChild")]
|
||||
[DecryptRequest("childRegistrationData")]
|
||||
[EncryptResponse]
|
||||
public IActionResult RegisterChild([FromForm] string parentApiToken, [FromForm] string apiKey) {
|
||||
public IActionResult RegisterChild([FromForm] Guid parentApiToken, [FromForm] string apiKey) {
|
||||
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == parentApiToken)?.User;
|
||||
if (user is null) {
|
||||
return Ok(new RegistrationResult{
|
||||
@ -113,14 +113,15 @@ public class RegistrationController : Controller {
|
||||
return Ok(new RegistrationResult { Status = MembershipUserStatus.DuplicateUserName });
|
||||
}
|
||||
|
||||
Inventory inv = new Inventory { InventoryItems = new List<InventoryItem>() };
|
||||
inv.InventoryItems.Add(new InventoryItem { ItemId = 8977, Quantity = 1 }); // DragonStableINTDO - Dragons Dragon Stable
|
||||
List<InventoryItem> items = new() {
|
||||
new InventoryItem { ItemId = 8977, Quantity = 1 } // DragonStableINTDO - Dragons Dragon Stable
|
||||
};
|
||||
|
||||
Viking v = new Viking {
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
Uid = Guid.NewGuid(),
|
||||
Name = data.ChildName,
|
||||
User = user,
|
||||
Inventory = inv,
|
||||
InventoryItems = items,
|
||||
AchievementPoints = new List<AchievementPoints>(),
|
||||
Rooms = new List<Room>()
|
||||
};
|
||||
@ -145,7 +146,7 @@ public class RegistrationController : Controller {
|
||||
roomService.CreateRoom(v, "MyRoomINT");
|
||||
|
||||
return Ok(new RegistrationResult {
|
||||
UserID = v.Id,
|
||||
UserID = v.Uid.ToString(),
|
||||
Status = MembershipUserStatus.Success
|
||||
});
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace sodoff.Model;
|
||||
public class AchievementPoints {
|
||||
public string VikingId { get; set; }
|
||||
public int VikingId { get; set; }
|
||||
|
||||
public int Type { get; set; }
|
||||
|
||||
|
@ -10,7 +10,6 @@ public class DBContext : DbContext {
|
||||
public DbSet<Pair> Pairs { get; set; } = null!;
|
||||
public DbSet<PairData> PairData { get; set; } = null!;
|
||||
public DbSet<TaskStatus> TaskStatuses { get; set; } = null!;
|
||||
public DbSet<Inventory> Inventories { get; set; } = null!;
|
||||
public DbSet<InventoryItem> InventoryItems { get; set; } = null!;
|
||||
public DbSet<MissionState> MissionStates { get; set; } = null!;
|
||||
public DbSet<Room> Rooms { get; set; } = null!;
|
||||
@ -70,10 +69,10 @@ public class DBContext : DbContext {
|
||||
builder.Entity<Viking>().HasMany(v => v.PairData)
|
||||
.WithOne(e => e.Viking);
|
||||
|
||||
builder.Entity<Viking>().HasOne(v => v.Inventory)
|
||||
builder.Entity<Viking>().HasMany(v => v.Images)
|
||||
.WithOne(e => e.Viking);
|
||||
|
||||
builder.Entity<Viking>().HasMany(v => v.Images)
|
||||
builder.Entity<Viking>().HasMany(v => v.TaskStatuses)
|
||||
.WithOne(e => e.Viking);
|
||||
|
||||
builder.Entity<Viking>().HasOne(v => v.SelectedDragon)
|
||||
@ -114,19 +113,14 @@ public class DBContext : DbContext {
|
||||
.HasPrincipalKey(e => e.Id);
|
||||
|
||||
// Inventory & InventoryItem
|
||||
builder.Entity<Inventory>()
|
||||
.HasOne(i => i.Viking)
|
||||
.WithOne(e => e.Inventory)
|
||||
.HasForeignKey<Inventory>(e => e.VikingId);
|
||||
|
||||
builder.Entity<Inventory>()
|
||||
.HasMany(i => i.InventoryItems)
|
||||
.WithOne(e => e.Inventory);
|
||||
builder.Entity<Viking>()
|
||||
.HasMany(v => v.InventoryItems)
|
||||
.WithOne(i => i.Viking);
|
||||
|
||||
builder.Entity<InventoryItem>()
|
||||
.HasOne(e => e.Inventory)
|
||||
.HasOne(e => e.Viking)
|
||||
.WithMany(e => e.InventoryItems)
|
||||
.HasForeignKey(e => e.InventoryId);
|
||||
.HasForeignKey(e => e.VikingId);
|
||||
|
||||
// Room & RoomItem
|
||||
builder.Entity<Room>().HasOne(r => r.Viking)
|
||||
@ -149,7 +143,8 @@ public class DBContext : DbContext {
|
||||
|
||||
builder.Entity<TaskStatus>()
|
||||
.HasOne(t => t.Viking)
|
||||
.WithMany();
|
||||
.WithMany(v => v.TaskStatuses)
|
||||
.HasForeignKey(t => t.VikingId);
|
||||
|
||||
builder.Entity<MissionState>().HasOne(m => m.Viking)
|
||||
.WithMany(e => e.MissionStates)
|
||||
|
@ -9,10 +9,9 @@ public class Dragon {
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string EntityId { get; set; } = null!;
|
||||
|
||||
public Guid EntityId { get; set; }
|
||||
[Required]
|
||||
public string VikingId { get; set; } = null!;
|
||||
public int VikingId { get; set; }
|
||||
|
||||
public string? RaisedPetData { get; set; }
|
||||
|
||||
|
@ -12,7 +12,7 @@ public class Image {
|
||||
public int ImageSlot { get; set; }
|
||||
|
||||
[Required]
|
||||
public string VikingId { get; set; } = null!;
|
||||
public int VikingId { get; set; }
|
||||
|
||||
public string? ImageData { get; set; }
|
||||
|
||||
|
@ -1,13 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace sodoff.Model;
|
||||
public class Inventory {
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string VikingId { get; set; }
|
||||
|
||||
public virtual Viking? Viking { get; set; }
|
||||
|
||||
public virtual ICollection<InventoryItem> InventoryItems { get; set; } = null!;
|
||||
}
|
@ -7,11 +7,11 @@ namespace sodoff.Model {
|
||||
|
||||
public int ItemId { get; set; }
|
||||
|
||||
public int InventoryId { get; set; }
|
||||
public int VikingId { get; set; }
|
||||
|
||||
public string? StatsSerialized { get; set; }
|
||||
|
||||
public virtual Inventory Inventory { get; set; }
|
||||
public virtual Viking Viking { get; set; } = null!;
|
||||
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ public class MissionState {
|
||||
|
||||
public int MissionId { get; set; }
|
||||
|
||||
public string VikingId { get; set; } = null!;
|
||||
public int VikingId { get; set; }
|
||||
|
||||
public virtual Viking? Viking { get; set; }
|
||||
|
||||
|
@ -8,11 +8,11 @@ public class Pair {
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Key { get; set; }
|
||||
public string Key { get; set; } = null!;
|
||||
|
||||
public string Value { get; set; }
|
||||
public string Value { get; set; } = null!;
|
||||
|
||||
public int MasterId { get; set; }
|
||||
|
||||
public virtual PairData PairData { get; set; }
|
||||
public virtual PairData PairData { get; set; } = null!;
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ public class PairData {
|
||||
|
||||
public int PairId { get; set; }
|
||||
|
||||
public string? UserId { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
|
||||
public string? VikingId { get; set; }
|
||||
public int? VikingId { get; set; }
|
||||
|
||||
public int? DragonId { get; set; }
|
||||
|
||||
|
@ -8,7 +8,7 @@ public class Room {
|
||||
|
||||
public string RoomId { get; set; }
|
||||
|
||||
public string VikingId { get; set; } = null!;
|
||||
public int VikingId { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
|
@ -3,11 +3,11 @@
|
||||
namespace sodoff.Model;
|
||||
public class Session {
|
||||
[Key]
|
||||
public string ApiToken { get; set; } = null!;
|
||||
public Guid ApiToken { get; set; }
|
||||
|
||||
public string? UserId { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
|
||||
public string? VikingId { get; set; }
|
||||
public int? VikingId { get; set; }
|
||||
|
||||
public DateTime? CreatedAt { get; set; }
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
public int MissionId { get; set; }
|
||||
|
||||
public string VikingId { get; set; } = null!;
|
||||
public int VikingId { get; set; }
|
||||
|
||||
public virtual Viking? Viking { get; set; }
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace sodoff.Model;
|
||||
public class User {
|
||||
[Key]
|
||||
public string Id { get; set; } = null!;
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Email { get; set; } = null!;
|
||||
|
@ -1,15 +1,20 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace sodoff.Model;
|
||||
|
||||
[Index(nameof(Uid))]
|
||||
public class Viking {
|
||||
[Key]
|
||||
public string Id { get; set; } = null!;
|
||||
public int Id { get; set; }
|
||||
|
||||
public Guid Uid { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[Required]
|
||||
public string UserId { get; set; } = null!;
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
public string? AvatarSerialized { get; set; }
|
||||
|
||||
@ -20,9 +25,10 @@ public class Viking {
|
||||
public virtual ICollection<Dragon> Dragons { get; set; } = null!;
|
||||
public virtual ICollection<Image> Images { get; set; } = null!;
|
||||
public virtual ICollection<MissionState> MissionStates { get; set; } = null!;
|
||||
public virtual ICollection<TaskStatus> TaskStatuses { get; set; } = null!;
|
||||
public virtual ICollection<Room> Rooms { get; set; } = null!;
|
||||
public virtual ICollection<AchievementPoints> AchievementPoints { get; set; } = null!;
|
||||
public virtual ICollection<PairData> PairData { get; set; } = null!;
|
||||
public virtual Inventory Inventory { get; set; } = null!;
|
||||
public virtual ICollection<InventoryItem> InventoryItems { get; set; } = null!;
|
||||
public virtual Dragon? SelectedDragon { get; set; }
|
||||
}
|
||||
|
@ -15,11 +15,11 @@ namespace sodoff.Services {
|
||||
this.inventoryService = inventoryService;
|
||||
}
|
||||
|
||||
public UserAchievementInfo CreateUserAchievementInfo(string userId, int? value, AchievementPointTypes type) {
|
||||
public UserAchievementInfo CreateUserAchievementInfo(Guid userId, int? value, AchievementPointTypes type) {
|
||||
if (value is null)
|
||||
value = 0;
|
||||
return new UserAchievementInfo {
|
||||
UserID = Guid.Parse(userId),
|
||||
UserID = userId,
|
||||
AchievementPointTotal = value,
|
||||
RankID = achievementStore.GetRankFromXP(value, type),
|
||||
PointTypeID = type
|
||||
@ -27,7 +27,7 @@ namespace sodoff.Services {
|
||||
}
|
||||
|
||||
public UserAchievementInfo CreateUserAchievementInfo(Viking viking, AchievementPointTypes type) {
|
||||
return CreateUserAchievementInfo(viking.Id, viking.AchievementPoints.FirstOrDefault(a => a.Type == (int)type)?.Value, type);
|
||||
return CreateUserAchievementInfo(viking.Uid, viking.AchievementPoints.FirstOrDefault(a => a.Type == (int)type)?.Value, type);
|
||||
}
|
||||
|
||||
public void DragonLevelUpOnAgeUp(Dragon dragon, RaisedPetGrowthState oldGrowthState, RaisedPetGrowthState newGrowthState) {
|
||||
@ -61,7 +61,7 @@ namespace sodoff.Services {
|
||||
|
||||
return new AchievementReward{
|
||||
// NOTE: RewardID and EntityTypeID are not used by client
|
||||
EntityID = Guid.Parse(dragon.EntityId),
|
||||
EntityID = dragon.EntityId,
|
||||
PointTypeID = AchievementPointTypes.DragonXP,
|
||||
Amount = value ?? 0
|
||||
};
|
||||
@ -87,7 +87,7 @@ namespace sodoff.Services {
|
||||
}
|
||||
|
||||
return new AchievementReward{
|
||||
EntityID = Guid.Parse(viking.Id),
|
||||
EntityID = viking.Uid,
|
||||
PointTypeID = type,
|
||||
Amount = value
|
||||
};
|
||||
@ -100,7 +100,7 @@ namespace sodoff.Services {
|
||||
inventoryService.AddItemToInventory(viking, reward.ItemID, (int)reward.Amount!);
|
||||
|
||||
AchievementReward grantedReward = reward.Clone();
|
||||
grantedReward.EntityID = Guid.Parse(viking.Id);
|
||||
grantedReward.EntityID = viking.Uid;
|
||||
return grantedReward;
|
||||
} else { // currencies, all types of player XP and dragon XP
|
||||
return AddAchievementPoints(viking, reward.PointTypeID, reward.Amount);
|
||||
@ -117,7 +117,7 @@ namespace sodoff.Services {
|
||||
double amountDouble = (reward.Amount ?? 0)/dragonsIDs.Length;
|
||||
int amount = (int)Math.Ceiling(amountDouble);
|
||||
foreach (Guid dragonID in dragonsIDs) {
|
||||
Dragon dragon = viking.Dragons.FirstOrDefault(e => e.EntityId == dragonID.ToString());
|
||||
Dragon dragon = viking.Dragons.FirstOrDefault(e => e.EntityId == dragonID);
|
||||
grantedRewards.Add(
|
||||
AddDragonAchievementPoints(dragon, amount)
|
||||
);
|
||||
@ -158,7 +158,7 @@ namespace sodoff.Services {
|
||||
CashCurrency = 65536,
|
||||
GameCurrency = 65536,
|
||||
UserGameCurrencyID = 1, // TODO: user's wallet ID?
|
||||
UserID = Guid.Parse(viking.Id)
|
||||
UserID = viking.Uid
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace sodoff.Services {
|
||||
public InventoryItem AddItemToInventory(Viking viking, int itemID, int quantity) {
|
||||
InventoryItem? item = null;
|
||||
if (!ItemNeedUniqueInventorySlot(itemID))
|
||||
item = viking.Inventory.InventoryItems.FirstOrDefault(e => e.ItemId == itemID);
|
||||
item = viking.InventoryItems.FirstOrDefault(e => e.ItemId == itemID);
|
||||
if (item is null) {
|
||||
ItemData itemData = itemService.GetItem(itemID);
|
||||
item = new InventoryItem {
|
||||
@ -36,7 +36,7 @@ namespace sodoff.Services {
|
||||
ItemStats = itemService.CreateItemStats(itemData.PossibleStatsMap, (int)itemData.ItemRarity, itemTier).ToArray()
|
||||
});
|
||||
}
|
||||
viking.Inventory.InventoryItems.Add(item);
|
||||
viking.InventoryItems.Add(item);
|
||||
}
|
||||
item.Quantity += quantity;
|
||||
return item;
|
||||
@ -71,7 +71,7 @@ namespace sodoff.Services {
|
||||
item.StatsSerialized = XmlUtil.SerializeXml(itemStatsMap);
|
||||
|
||||
// add to viking
|
||||
viking.Inventory.InventoryItems.Add(item);
|
||||
viking.InventoryItems.Add(item);
|
||||
ctx.SaveChanges(); // We need to get the ID of the newly created item
|
||||
|
||||
// return item with stats
|
||||
@ -84,7 +84,7 @@ namespace sodoff.Services {
|
||||
|
||||
public void SellInventoryItem(Viking viking, int invItemID, ref int gold, ref int shard) {
|
||||
// get item from inventory
|
||||
InventoryItem? item = viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == invItemID);
|
||||
InventoryItem? item = viking.InventoryItems.FirstOrDefault(e => e.Id == invItemID);
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
@ -110,11 +110,11 @@ namespace sodoff.Services {
|
||||
// TODO: calculate cash (gold) rewards
|
||||
|
||||
// remove item
|
||||
viking.Inventory.InventoryItems.Remove(item);
|
||||
viking.InventoryItems.Remove(item);
|
||||
}
|
||||
|
||||
public CommonInventoryData GetCommonInventoryData(Viking viking) {
|
||||
List<InventoryItem> items = viking.Inventory.InventoryItems.ToList();
|
||||
List<InventoryItem> items = viking.InventoryItems.ToList();
|
||||
|
||||
List<UserItemData> userItemData = new();
|
||||
foreach (InventoryItem item in items) {
|
||||
@ -140,7 +140,7 @@ namespace sodoff.Services {
|
||||
}
|
||||
|
||||
return new CommonInventoryData {
|
||||
UserID = Guid.Parse(viking.Id),
|
||||
UserID = viking.Uid,
|
||||
Item = userItemData.ToArray()
|
||||
};
|
||||
}
|
||||
|
@ -76,11 +76,12 @@ public class KeyValueService {
|
||||
|
||||
private Model.PairData? CheckOwnerAndGetPairData(ref User? user, ref Viking? viking, ref Dragon dragon, string? userId, int pairId) {
|
||||
if (userId != null) {
|
||||
Guid userIdGuid = Guid.Parse(userId);
|
||||
// find dragon
|
||||
dragon = viking?.Dragons.FirstOrDefault(e => e.EntityId == userId);
|
||||
dragon = viking?.Dragons.FirstOrDefault(e => e.EntityId == userIdGuid);
|
||||
|
||||
// if not dragon then try viking -> check ID
|
||||
if (dragon != null || viking?.Id != userId) {
|
||||
if (dragon != null || viking?.Uid != userIdGuid) {
|
||||
// if not viking and user not set, then try set user from viking
|
||||
if (user is null)
|
||||
user = viking?.User;
|
||||
@ -88,7 +89,7 @@ public class KeyValueService {
|
||||
}
|
||||
|
||||
// if not dragon nor viking then try user -> check ID
|
||||
if (viking != null || user?.Id != userId) user = null;
|
||||
if (viking != null || user?.Id != userIdGuid) user = null;
|
||||
}
|
||||
|
||||
// NOTE: only one of (dragon, viking, user) can be not null here
|
||||
|
@ -16,7 +16,7 @@ public class MissionService {
|
||||
this.achievementService = achievementService;
|
||||
}
|
||||
|
||||
public Mission GetMissionWithProgress(int missionId, string userId, string apiKey) {
|
||||
public Mission GetMissionWithProgress(int missionId, int userId, string apiKey) {
|
||||
Mission mission;
|
||||
if (missionId == 999 && apiKey == "a3a12a0a-7c6e-4e9b-b0f7-22034d799013") { // TODO This is not a pretty solution with hard-coded values.
|
||||
mission = missionStore.GetMission(10999);
|
||||
@ -34,7 +34,7 @@ public class MissionService {
|
||||
return mission;
|
||||
}
|
||||
|
||||
public List<MissionCompletedResult> UpdateTaskProgress(int missionId, int taskId, string userId, bool completed, string xmlPayload, string apiKey) {
|
||||
public List<MissionCompletedResult> UpdateTaskProgress(int missionId, int taskId, int userId, bool completed, string xmlPayload, string apiKey) {
|
||||
SetTaskProgressDB(missionId, taskId, userId, completed, xmlPayload);
|
||||
|
||||
// NOTE: This won't work if a mission can be completed by completing an inner mission
|
||||
@ -82,7 +82,7 @@ public class MissionService {
|
||||
return result;
|
||||
}
|
||||
|
||||
private void UpdateMissionRecursive(Mission mission, string userId) {
|
||||
private void UpdateMissionRecursive(Mission mission, int userId) {
|
||||
List<Model.TaskStatus> taskStatuses = ctx.TaskStatuses.Where(e => e.VikingId == userId && e.MissionId == mission.MissionID).ToList();
|
||||
|
||||
// Update mission rules and tasks
|
||||
@ -130,7 +130,7 @@ public class MissionService {
|
||||
}
|
||||
}
|
||||
|
||||
private void SetTaskProgressDB(int missionId, int taskId, string userId, bool completed, string xmlPayload) {
|
||||
private void SetTaskProgressDB(int missionId, int taskId, int userId, bool completed, string xmlPayload) {
|
||||
Model.TaskStatus? status = ctx.TaskStatuses.FirstOrDefault(task => task.Id == taskId && task.MissionId == missionId && task.VikingId == userId);
|
||||
|
||||
if (status is null) {
|
||||
|
@ -29,7 +29,7 @@ public class RoomService {
|
||||
List<UserItemState> states = new();
|
||||
foreach (var itemRequest in roomItemRequest) {
|
||||
// TODO: Remove item from inventory (using CommonInventoryID)
|
||||
InventoryItem? i = room.Viking?.Inventory.InventoryItems.FirstOrDefault(x => x.Id == itemRequest.UserInventoryCommonID);
|
||||
InventoryItem? i = room.Viking?.InventoryItems.FirstOrDefault(x => x.Id == itemRequest.UserInventoryCommonID);
|
||||
if (i != null) {
|
||||
i.Quantity--;
|
||||
if (itemRequest.Item is null) {
|
||||
@ -98,7 +98,7 @@ public class RoomService {
|
||||
if (ri is null) continue;
|
||||
UserItemPosition itemPosition = XmlUtil.DeserializeXml<UserItemPosition>(ri.RoomItemData);
|
||||
room.Items.Remove(ri);
|
||||
InventoryItem? invItem = room.Viking?.Inventory.InventoryItems.FirstOrDefault(x => x.Id == itemPosition.UserInventoryCommonID);
|
||||
InventoryItem? invItem = room.Viking?.InventoryItems.FirstOrDefault(x => x.Id == itemPosition.UserInventoryCommonID);
|
||||
if (invItem != null) invItem.Quantity++;
|
||||
}
|
||||
ctx.SaveChanges();
|
||||
@ -128,7 +128,7 @@ public class RoomService {
|
||||
|
||||
foreach (var consumable in consumables) {
|
||||
ItemStateCriteriaConsumable c = (ItemStateCriteriaConsumable)consumable;
|
||||
InventoryItem? invItem = item.Room.Viking?.Inventory.InventoryItems.FirstOrDefault(x => x.ItemId == c.ItemID);
|
||||
InventoryItem? invItem = item.Room.Viking?.InventoryItems.FirstOrDefault(x => x.ItemId == c.ItemID);
|
||||
if (invItem != null)
|
||||
invItem.Quantity = invItem.Quantity - c.Amount < 0 ? 0 : invItem.Quantity - c.Amount;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user