104 lines
3.1 KiB
C#
104 lines
3.1 KiB
C#
using Server.System;
|
|
using Newtonsoft.Json;
|
|
using Server.SQL;
|
|
|
|
namespace Server.Service
|
|
{
|
|
public class DeckChange : AbstractService
|
|
{
|
|
private DeckChangeReq req;
|
|
|
|
public 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.unit_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);
|
|
|
|
//덱 유닛 저장
|
|
|
|
DeckInfo changeDeck = new DeckInfo();
|
|
|
|
changeDeck.id = deckInfo[deckindex].id;
|
|
changeDeck.deck_type = deckInfo[deckindex].deck_type;
|
|
changeDeck.user_id = deckInfo[deckindex].user_id;
|
|
changeDeck.deck_unit0_id = req.deck_unit[0];
|
|
changeDeck.deck_unit1_id = req.deck_unit[1];
|
|
changeDeck.deck_unit2_id = req.deck_unit[2];
|
|
changeDeck.deck_unit3_id = req.deck_unit[3];
|
|
changeDeck.deck_unit4_id = req.deck_unit[4];
|
|
changeDeck.deck_unit5_id = req.deck_unit[5];
|
|
changeDeck.deck_unit6_id = req.deck_unit[6];
|
|
changeDeck.deck_unit7_id = req.deck_unit[7];
|
|
changeDeck.deck_unit8_id = req.deck_unit[8];
|
|
|
|
Statics.deckInfoSQL.Update(changeDeck);
|
|
return makeResp(changeDeck);
|
|
}
|
|
|
|
public override Protocol ProtocolValue() => Protocol.DeckChange;
|
|
|
|
public override Req Requst(string json)
|
|
{
|
|
req = JsonConvert.DeserializeObject<DeckChangeReq>(json);
|
|
return req;
|
|
}
|
|
|
|
private string makeResp(DeckInfo changeDeck)
|
|
{
|
|
SaveSQL();
|
|
DeckChangeResp resp = new DeckChangeResp();
|
|
resp.deck_info = changeDeck;
|
|
return resp.ToJson();
|
|
}
|
|
}
|
|
|
|
public class DeckChangeReq : Req
|
|
{
|
|
public string uuid;
|
|
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;
|
|
}
|
|
}
|