113 lines
3.8 KiB
C#
113 lines
3.8 KiB
C#
using Server.System;
|
|
using Newtonsoft.Json;
|
|
using Server.SQL;
|
|
|
|
namespace Server.Service
|
|
{
|
|
public class DeckChange : AbstractService
|
|
{
|
|
private DeckChangeReq req;
|
|
|
|
private void SaveSQL()
|
|
{
|
|
Statics.deckInfoSQL.SaveChanges();
|
|
}
|
|
|
|
public override string Process()
|
|
{
|
|
User user = Statics.userSQL.SelectUuid(req.uuid);
|
|
List<DeckInfo> deckInfo = Statics.deckInfoSQL.SelectUid(user.id);
|
|
List<DeckUnitInfo> deckUnitInfo = Statics.deckUnitInfoSQL.SelectUid(user.id);
|
|
//실제 존재하는 유닛인지 확인
|
|
|
|
for(int n = 0; n < req.deck_unit.Length; n++)
|
|
{
|
|
if (req.deck_unit[n] == 0)
|
|
continue;
|
|
long unit_id = req.deck_unit[n];
|
|
if( deckUnitInfo.FindIndex(data => data.id == unit_id) == -1)
|
|
throw new RuntimeException("Not Unit", Error.NoData);
|
|
}
|
|
|
|
//존재하는 덱인지 검사
|
|
int deckindex = -1;
|
|
|
|
for (int n = 0; n < deckInfo.Count; n++)
|
|
{
|
|
if (deckInfo[n].id == req.deck_id)
|
|
{
|
|
deckindex = n;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(deckindex == -1)
|
|
throw new RuntimeException("Not Deck", Error.NoData);
|
|
|
|
//덱 검사
|
|
if (deckInfo[deckindex].deck_unit0_id == req.deck_unit[0] &&
|
|
deckInfo[deckindex].deck_unit1_id == req.deck_unit[1] &&
|
|
deckInfo[deckindex].deck_unit2_id == req.deck_unit[2] &&
|
|
deckInfo[deckindex].deck_unit3_id == req.deck_unit[3] &&
|
|
deckInfo[deckindex].deck_unit4_id == req.deck_unit[4] &&
|
|
deckInfo[deckindex].deck_unit5_id == req.deck_unit[5] &&
|
|
deckInfo[deckindex].deck_unit6_id == req.deck_unit[6] &&
|
|
deckInfo[deckindex].deck_unit7_id == req.deck_unit[7] &&
|
|
deckInfo[deckindex].deck_unit8_id == req.deck_unit[8])
|
|
{
|
|
//모든 정보가 같으면 업데이트 하지않음
|
|
return makeResp(deckInfo[deckindex]);
|
|
}
|
|
|
|
//덱 유닛 저장
|
|
|
|
deckInfo[deckindex].deck_unit0_id = req.deck_unit[0];
|
|
deckInfo[deckindex].deck_unit1_id = req.deck_unit[1];
|
|
deckInfo[deckindex].deck_unit2_id = req.deck_unit[2];
|
|
deckInfo[deckindex].deck_unit3_id = req.deck_unit[3];
|
|
deckInfo[deckindex].deck_unit4_id = req.deck_unit[4];
|
|
deckInfo[deckindex].deck_unit5_id = req.deck_unit[5];
|
|
deckInfo[deckindex].deck_unit6_id = req.deck_unit[6];
|
|
deckInfo[deckindex].deck_unit7_id = req.deck_unit[7];
|
|
deckInfo[deckindex].deck_unit8_id = req.deck_unit[8];
|
|
|
|
Statics.deckInfoSQL.Update(deckInfo[deckindex]);
|
|
SaveSQL();
|
|
return makeResp(deckInfo[deckindex]);
|
|
}
|
|
|
|
public override Protocol ProtocolValue() => Protocol.DeckChange;
|
|
|
|
public override Req Requst(string json)
|
|
{
|
|
req = JsonConvert.DeserializeObject<DeckChangeReq>(json);
|
|
return req;
|
|
}
|
|
|
|
private string makeResp(DeckInfo changeDeck)
|
|
{
|
|
DeckChangeResp resp = new DeckChangeResp();
|
|
resp.deck_info = changeDeck;
|
|
return resp.ToJson();
|
|
}
|
|
}
|
|
|
|
public class DeckChangeReq : Req
|
|
{
|
|
public long deck_id;
|
|
public long[] deck_unit;
|
|
public override bool IsReceivedAllField()
|
|
{
|
|
if(uuid == "" || deck_id == 0 || deck_unit.Length != 9)
|
|
return false;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public class DeckChangeResp : Resp
|
|
{
|
|
//덱정보 반환
|
|
public DeckInfo deck_info;
|
|
}
|
|
}
|