forked from SoDOff-Project/sodoff
Add Parties System (WoJS)
- Add Placeholder For GetActiveParties - Add Proper Placeholder For GetActiveParties - Attempt Party Implementation - Return Null When Party Time Is Not One Hour - Do Not Buy Party If It Already Exists - Remove Coins From User After Buying Party - Fix Parties Not Getting Removed After One Hour - db model fixes - Make Party ID key an integer - Add ``GetPartiesByUserId`` - Fixes Parties Not Having Decorations - Add All Other Party Durations And Types - Fix Mistake In ``GetActiveParties``
This commit is contained in:
parent
93361c5e84
commit
8d236ef8d3
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using sodoff.Attributes;
|
using sodoff.Attributes;
|
||||||
using sodoff.Model;
|
using sodoff.Model;
|
||||||
using sodoff.Schema;
|
using sodoff.Schema;
|
||||||
@ -1380,6 +1381,185 @@ public class ContentController : Controller {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Produces("application/xml")]
|
||||||
|
[Route("ContentWebService.asmx/GetActiveParties")] // used by World Of Jumpstart
|
||||||
|
public IActionResult GetActiveParties()
|
||||||
|
{
|
||||||
|
List<Party> allParties = ctx.Parties.ToList();
|
||||||
|
List<UserParty> userParties = new List<UserParty>();
|
||||||
|
|
||||||
|
foreach(var party in allParties)
|
||||||
|
{
|
||||||
|
if(DateTime.UtcNow >= party.ExpirationDate)
|
||||||
|
{
|
||||||
|
ctx.Parties.Remove(party);
|
||||||
|
ctx.SaveChanges();
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Viking viking = ctx.Vikings.FirstOrDefault(e => e.Id == party.VikingId);
|
||||||
|
AvatarData avatarData = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized);
|
||||||
|
UserParty userParty = new UserParty
|
||||||
|
{
|
||||||
|
DisplayName = avatarData.DisplayName,
|
||||||
|
UserName = avatarData.DisplayName,
|
||||||
|
ExpirationDate = party.ExpirationDate,
|
||||||
|
Icon = party.LocationIconAsset,
|
||||||
|
Location = party.Location,
|
||||||
|
PrivateParty = party.PrivateParty!.Value,
|
||||||
|
UserID = viking.Uid
|
||||||
|
};
|
||||||
|
|
||||||
|
if (party.Location == "MyNeighborhood") userParty.DisplayName = $"{userParty.UserName}'s Block Party";
|
||||||
|
if (party.Location == "MyVIPRoomInt") userParty.DisplayName = $"{userParty.UserName}'s VIP Party";
|
||||||
|
|
||||||
|
userParties.Add(userParty);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(new UserPartyData { NonBuddyParties = userParties.ToArray() });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Produces("application/xml")]
|
||||||
|
[Route("ContentWebService.asmx/GetPartiesByUserID")] // used by World Of Jumpstart
|
||||||
|
public IActionResult GetPartiesByUserID([FromForm] Guid userId)
|
||||||
|
{
|
||||||
|
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == userId);
|
||||||
|
List<UserPartyComplete> parties = new List<UserPartyComplete>();
|
||||||
|
if(viking != null)
|
||||||
|
{
|
||||||
|
foreach(var party in ctx.Parties)
|
||||||
|
{
|
||||||
|
if (DateTime.UtcNow >= party.ExpirationDate)
|
||||||
|
{
|
||||||
|
ctx.Parties.Remove(party);
|
||||||
|
ctx.SaveChanges();
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
AvatarData avatarData = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized);
|
||||||
|
if(party.Location == "MyNeighborhood")
|
||||||
|
{
|
||||||
|
UserPartyComplete userPartyComplete = new UserPartyComplete
|
||||||
|
{
|
||||||
|
DisplayName = avatarData.DisplayName,
|
||||||
|
UserName = avatarData.DisplayName,
|
||||||
|
ExpirationDate = party.ExpirationDate,
|
||||||
|
Icon = party.LocationIconAsset,
|
||||||
|
Location = party.Location,
|
||||||
|
PrivateParty = party.PrivateParty!.Value,
|
||||||
|
UserID = viking.Uid,
|
||||||
|
AssetBundle = "RS_DATA/PfMyNeighborhoodParty.unity3d/PfMyNeighborhoodParty"
|
||||||
|
};
|
||||||
|
parties.Add(userPartyComplete);
|
||||||
|
} else if (party.Location == "MyVIPRoomInt")
|
||||||
|
{
|
||||||
|
UserPartyComplete userPartyComplete = new UserPartyComplete
|
||||||
|
{
|
||||||
|
DisplayName = avatarData.DisplayName,
|
||||||
|
UserName = avatarData.DisplayName,
|
||||||
|
ExpirationDate = party.ExpirationDate,
|
||||||
|
Icon = party.LocationIconAsset,
|
||||||
|
Location = party.Location,
|
||||||
|
PrivateParty = party.PrivateParty!.Value,
|
||||||
|
UserID = viking.Uid,
|
||||||
|
AssetBundle = "RS_DATA/PfMyVIPRoomIntPartyGroup.unity3d/PfMyVIPRoomIntPartyGroup"
|
||||||
|
};
|
||||||
|
parties.Add(userPartyComplete);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(new ArrayOfUserPartyComplete { UserPartyComplete = parties.ToArray() });
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
return Ok(new ArrayOfUserPartyComplete());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Produces("application/xml")]
|
||||||
|
[Route("ContentWebService.asmx/PurchaseParty")] // used by World Of Jumpstart
|
||||||
|
[VikingSession]
|
||||||
|
public IActionResult PurchaseParty(Viking viking, [FromForm] int itemId)
|
||||||
|
{
|
||||||
|
// create a party based on bought itemid
|
||||||
|
|
||||||
|
Party party = new Party
|
||||||
|
{
|
||||||
|
VikingId = viking.Id,
|
||||||
|
PrivateParty = false
|
||||||
|
};
|
||||||
|
|
||||||
|
int coinTakeaway = 0;
|
||||||
|
|
||||||
|
switch (itemId)
|
||||||
|
{
|
||||||
|
case 2761:
|
||||||
|
party.Location = "MyNeighborhood";
|
||||||
|
party.LocationIconAsset = "RS_DATA/PfUiPartiesList.unity3d/IcoPartyLocationMyNeighborhood";
|
||||||
|
party.ExpirationDate = DateTime.UtcNow.AddMinutes(30);
|
||||||
|
coinTakeaway = 30;
|
||||||
|
break;
|
||||||
|
case 6259:
|
||||||
|
party.Location = "MyNeighborhood";
|
||||||
|
party.LocationIconAsset = "RS_DATA/PfUiPartiesList.unity3d/IcoPartyLocationMyNeighborhood";
|
||||||
|
party.ExpirationDate = DateTime.UtcNow.AddHours(1);
|
||||||
|
coinTakeaway = 60;
|
||||||
|
break;
|
||||||
|
case 6260:
|
||||||
|
party.Location = "MyNeighborhood";
|
||||||
|
party.LocationIconAsset = "RS_DATA/PfUiPartiesList.unity3d/IcoPartyLocationMyNeighborhood";
|
||||||
|
party.ExpirationDate = DateTime.UtcNow.AddHours(4);
|
||||||
|
coinTakeaway = 80;
|
||||||
|
break;
|
||||||
|
case 6261:
|
||||||
|
party.Location = "MyNeighborhood";
|
||||||
|
party.LocationIconAsset = "RS_DATA/PfUiPartiesList.unity3d/IcoPartyLocationMyNeighborhood";
|
||||||
|
party.ExpirationDate = DateTime.UtcNow.AddHours(8);
|
||||||
|
coinTakeaway = 100;
|
||||||
|
break;
|
||||||
|
case 6263:
|
||||||
|
party.Location = "MyVIPRoomInt";
|
||||||
|
party.LocationIconAsset = "RS_DATA/PfUiPartiesList.unity3d/IcoPartyDefault";
|
||||||
|
party.ExpirationDate = DateTime.UtcNow.AddMinutes(30);
|
||||||
|
coinTakeaway = 30;
|
||||||
|
break;
|
||||||
|
case 6264:
|
||||||
|
party.Location = "MyVIPRoomInt";
|
||||||
|
party.LocationIconAsset = "RS_DATA/PfUiPartiesList.unity3d/IcoPartyDefault";
|
||||||
|
party.ExpirationDate = DateTime.UtcNow.AddHours(1);
|
||||||
|
coinTakeaway = 60;
|
||||||
|
break;
|
||||||
|
case 6265:
|
||||||
|
party.Location = "MyVIPRoomInt";
|
||||||
|
party.LocationIconAsset = "RS_DATA/PfUiPartiesList.unity3d/IcoPartyDefault";
|
||||||
|
party.ExpirationDate = DateTime.UtcNow.AddHours(4);
|
||||||
|
coinTakeaway = 80;
|
||||||
|
break;
|
||||||
|
case 6266:
|
||||||
|
party.Location = "MyVIPRoomInt";
|
||||||
|
party.LocationIconAsset = "RS_DATA/PfUiPartiesList.unity3d/IcoPartyDefault";
|
||||||
|
party.ExpirationDate = DateTime.UtcNow.AddHours(8);
|
||||||
|
coinTakeaway = 100;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if party already exists
|
||||||
|
|
||||||
|
if (ctx.Parties.Where(e => e.Location == party.Location).FirstOrDefault(e => e.VikingId == viking.Id) != null) return Ok(null);
|
||||||
|
|
||||||
|
// take away coins
|
||||||
|
viking.AchievementPoints.FirstOrDefault(e => e.Type == (int)AchievementPointTypes.GameCurrency)!.Value -= coinTakeaway;
|
||||||
|
|
||||||
|
ctx.Parties.Add(party);
|
||||||
|
ctx.SaveChanges();
|
||||||
|
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("ContentWebService.asmx/GetUserActivityByUserID")]
|
[Route("ContentWebService.asmx/GetUserActivityByUserID")]
|
||||||
|
@ -20,6 +20,7 @@ public class DBContext : DbContext {
|
|||||||
public DbSet<GameDataPair> GameDataPairs { get; set; } = null!;
|
public DbSet<GameDataPair> GameDataPairs { get; set; } = null!;
|
||||||
public DbSet<AchievementPoints> AchievementPoints { get; set; } = null!;
|
public DbSet<AchievementPoints> AchievementPoints { get; set; } = null!;
|
||||||
public DbSet<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
public DbSet<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
||||||
|
public DbSet<Party> Parties { get; set; } = null!;
|
||||||
private readonly IOptions<ApiServerConfig> config;
|
private readonly IOptions<ApiServerConfig> config;
|
||||||
|
|
||||||
public DBContext(IOptions<ApiServerConfig> config) {
|
public DBContext(IOptions<ApiServerConfig> config) {
|
||||||
@ -118,6 +119,9 @@ public class DBContext : DbContext {
|
|||||||
builder.Entity<Viking>().HasMany(v => v.ProfileAnswers)
|
builder.Entity<Viking>().HasMany(v => v.ProfileAnswers)
|
||||||
.WithOne(e => e.Viking);
|
.WithOne(e => e.Viking);
|
||||||
|
|
||||||
|
builder.Entity<Viking>().HasMany(v => v.Parties)
|
||||||
|
.WithOne(e => e.Viking);
|
||||||
|
|
||||||
// Dragons
|
// Dragons
|
||||||
builder.Entity<Dragon>().HasOne(d => d.Viking)
|
builder.Entity<Dragon>().HasOne(d => d.Viking)
|
||||||
.WithMany(e => e.Dragons)
|
.WithMany(e => e.Dragons)
|
||||||
@ -214,6 +218,9 @@ public class DBContext : DbContext {
|
|||||||
.WithMany(v => v.SavedData)
|
.WithMany(v => v.SavedData)
|
||||||
.HasForeignKey(e => e.VikingId);
|
.HasForeignKey(e => e.VikingId);
|
||||||
|
|
||||||
|
builder.Entity<Party>().HasOne(i => i.Viking)
|
||||||
|
.WithMany(i => i.Parties);
|
||||||
|
|
||||||
builder.Entity<ProfileAnswer>().HasOne(i => i.Viking)
|
builder.Entity<ProfileAnswer>().HasOne(i => i.Viking)
|
||||||
.WithMany(i => i.ProfileAnswers)
|
.WithMany(i => i.ProfileAnswers)
|
||||||
.HasForeignKey(e => e.VikingId);
|
.HasForeignKey(e => e.VikingId);
|
||||||
|
17
src/Model/Party.cs
Normal file
17
src/Model/Party.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace sodoff.Model
|
||||||
|
{
|
||||||
|
public class Party
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Location { get; set; } = null!;
|
||||||
|
public int VikingId { get; set; }
|
||||||
|
public DateTime ExpirationDate { get; set; } = DateTime.UtcNow;
|
||||||
|
public bool? PrivateParty { get; set; }
|
||||||
|
public string LocationIconAsset { get; set; } = null!;
|
||||||
|
public virtual Viking? Viking { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -33,5 +33,6 @@ public class Viking {
|
|||||||
public virtual ICollection<GameData> GameData { get; set; } = null!;
|
public virtual ICollection<GameData> GameData { get; set; } = null!;
|
||||||
public virtual ICollection<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
public virtual ICollection<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
||||||
public virtual ICollection<SavedData> SavedData { get; set; } = null!;
|
public virtual ICollection<SavedData> SavedData { get; set; } = null!;
|
||||||
|
public virtual ICollection<Party> Parties { get; set; } = null!;
|
||||||
public virtual Dragon? SelectedDragon { get; set; }
|
public virtual Dragon? SelectedDragon { get; set; }
|
||||||
}
|
}
|
||||||
|
10
src/Schema/ArrayOfUserPartyComplete.cs
Normal file
10
src/Schema/ArrayOfUserPartyComplete.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
[XmlRoot(ElementName = "ArrayOfUserPartyComplete", Namespace = "http://api.jumpstart.com/")]
|
||||||
|
[Serializable]
|
||||||
|
public class ArrayOfUserPartyComplete
|
||||||
|
{
|
||||||
|
[XmlElement(ElementName = "UserPartyComplete")]
|
||||||
|
public UserPartyComplete[] UserPartyComplete;
|
||||||
|
}
|
33
src/Schema/UserParty.cs
Normal file
33
src/Schema/UserParty.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
namespace sodoff.Schema
|
||||||
|
{
|
||||||
|
[XmlRoot(ElementName = "Party", Namespace = "")]
|
||||||
|
[Serializable]
|
||||||
|
public class UserParty
|
||||||
|
{
|
||||||
|
[XmlElement(ElementName = "UID")]
|
||||||
|
public Guid UserID;
|
||||||
|
|
||||||
|
[XmlElement(ElementName = "UserName")]
|
||||||
|
public string UserName;
|
||||||
|
|
||||||
|
[XmlElement(ElementName = "Name")]
|
||||||
|
public string DisplayName;
|
||||||
|
|
||||||
|
[XmlElement(ElementName = "Icon")]
|
||||||
|
public string Icon;
|
||||||
|
|
||||||
|
[XmlElement(ElementName = "Loc")]
|
||||||
|
public string Location;
|
||||||
|
|
||||||
|
[XmlElement(ElementName = "LocIcon")]
|
||||||
|
public string LocationIcon;
|
||||||
|
|
||||||
|
[XmlElement(ElementName = "ExpDate")]
|
||||||
|
public DateTime ExpirationDate;
|
||||||
|
|
||||||
|
[XmlElement(ElementName = "Pvt")]
|
||||||
|
public bool PrivateParty;
|
||||||
|
}
|
||||||
|
}
|
11
src/Schema/UserPartyComplete.cs
Normal file
11
src/Schema/UserPartyComplete.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using sodoff.Schema;
|
||||||
|
using System;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
[XmlRoot(ElementName = "PartyComplete", Namespace = "")]
|
||||||
|
[Serializable]
|
||||||
|
public class UserPartyComplete : UserParty
|
||||||
|
{
|
||||||
|
[XmlElement(ElementName = "Asset")]
|
||||||
|
public string AssetBundle;
|
||||||
|
}
|
15
src/Schema/UserPartyData.cs
Normal file
15
src/Schema/UserPartyData.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
namespace sodoff.Schema
|
||||||
|
{
|
||||||
|
[XmlRoot(ElementName = "Party", Namespace = "")]
|
||||||
|
[Serializable]
|
||||||
|
public class UserPartyData
|
||||||
|
{
|
||||||
|
[XmlElement(ElementName = "BuddyParties")]
|
||||||
|
public UserParty[] BuddyParties;
|
||||||
|
|
||||||
|
[XmlElement(ElementName = "NonBuddyParties")]
|
||||||
|
public UserParty[] NonBuddyParties;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user