thewar_server/Server/Service/UpdateStory.cs

97 lines
2.8 KiB
C#

using Server.System;
using Newtonsoft.Json;
using Server.SQL;
namespace Server.Service
{
public class UpdateStory : AbstractService
{
private UpdateStoryReq req;
private void SaveSQL()
{
Statics.storyProgressSQL.SaveChanges();
}
public override string Process()
{
User user = req.user;
List<StoryProgress> storyProgress = Statics.storyProgressSQL.SelectUid(user.id);
StoryProgress story = storyProgress.Find(n => n.story_data_id == req.story_id);
int chapter = 1;
//정상적인 진행인지 확인
if (req.chapter_id != 1 && (story == null || story.chapter_data_id + 1 < req.chapter_id))
{
throw new RuntimeException("over chapter id", Error.ErrorData);
}
if (req.is_clear)
{
if(story == null || story.chapter_data_id < req.chapter_id)
{
if (req.chapter_id == 1)
{
story = new StoryProgress();
story.user_id = user.id;
story.story_data_id = req.story_id;
story.chapter_data_id = req.chapter_id;
Statics.storyProgressSQL.Insert(story);
}
else
{
story.chapter_data_id++;
chapter = story.chapter_data_id;
Statics.storyProgressSQL.Update(story);
}
//보상 지급 추가할것.
}
//클리어 성공 로그용, 기본보상 지급할것
}
else
{
//클리어 실패 로그용
}
SaveSQL();
return makeResp(chapter);
}
public override Protocol ProtocolValue() => Protocol.UpdateStory;
public override Req Requst(string json)
{
req = JsonConvert.DeserializeObject<UpdateStoryReq>(json);
return req;
}
private string makeResp(int chapter)
{
UpdateStoryResp resp = new UpdateStoryResp();
resp.status = 200;
resp.chapter = chapter;
return resp.ToJson();
}
}
public class UpdateStoryReq : Req
{
public int story_id;
public int chapter_id;
public bool is_clear;
public override bool IsReceivedAllField()
{
if(uuid == string.Empty || story_id == 0 || chapter_id == 0)
return false;
return true;
}
}
public class UpdateStoryResp : Resp
{
public int chapter;
}
}