diff --git a/twe/func_diplomacy.php b/twe/func_diplomacy.php new file mode 100644 index 00000000..e33ee47f --- /dev/null +++ b/twe/func_diplomacy.php @@ -0,0 +1,221 @@ +queryFirstRow('SELECT `level`, `scout` FROM `nation` WHERE `nation` = %i', $nationID); + + $realNationID = $srcGeneral['nation']; + + + + if($general['level'] == 12) { + return [false, "군주입니다."]; + } + if(!$srcNation || $srcNation['level'] == 0) { + return [false, "없는 국가이거나 방랑군입니다."]; + } + if($realNationID != $nationID){ + return [false, "권유자의 소속이 바뀌었습니다."]; + } + if($srcNation['scout'] != 0) { + return [false, "임관 금지중입니다."]; + } + if($year < $startyear+3) { + return [false, "초반 제한중입니다."]; + } + if(strpos($general['nations'], ",{$nationID},") > 0) { + return [false, "이미 임관했었던 국가입니다."]; + } + + return [true, null]; + +} + +function acceptScout($messageInfo, $general, $msgResponse){ + $me = $general; + $you = getDB()->queryFirstRow('SELECT `no`, `name`, `nation` FROM `general` WHERE `no` = %i', $messageInfo['src']['id']); + + list($startyear, $year, $month, $killturn) = dictToArray(getDB()->queryFirstRow('SELECT `startyear`, `year`, `month`, `killturn` FROM `game` LIMIT 1'), ['startyear', 'year', 'month', `killturn`]); + + list($avaliableScout, $reason) = checkScoutAvailable($messageInfo, $general, $you, $startyear, $year); + + if(!$msgResponse || !$avaliableScout){ + return declineScout($messageInfo, $reason); + } + + $nation = getNationStaticInfo($messageInfo['src']['nationID']); + $generalID = $me['no']; + $nationID = $nation['nation']; + $nationName = $nation['name']; + $myName = $me['name']; + + $mylog = []; + $youlog = []; + $alllog = []; + + $youlog[] = "{$myName} 등용에 성공했습니다."; + $alllog[] = "●{$month}월:{$myName}(이)가 {$nationName}(으)로 망명하였습니다."; + $mylog[] = "{$nationName}(으)로 망명하여 수도로 이동합니다."; + addHistory($you, "●{$year}년 {$month}월:{$myName} 등용에 성공"); + addHistory($me, "●{$year}년 {$month}월:{$nationName}(으)로 망명"); + + $me['nations'] .= "{$nationID},"; + + $updateMe = [ + 'belong'=>1, + 'nation'=>$nationID, + 'level'=>1, + 'city'=>$nation['capital'], + 'troop'=>0 + ]; + + + //처리가 조금 다름. + + $db = getDB(); + + + if($me['level'] > 0){ + $updateOldNation = [ + 'totaltech' => $db->sqleval('`tech`*greatest(10, `gennum`-1)'), + 'gennum' => $db->sqleval('greatest(10, `gennum`-1)') + ]; + + if($me['gold'] > 1000){ + $updateOldNation['gold'] = $db->sqleval('`gold` + %i', $me['gold'] - 1000); + $updateMe['gold'] = 1000; + } + if($me['rice'] > 1000){ + $updateOldNation['rice'] = $db->sqleval('`rice` + %i', $me['rice'] - 1000); + $updateMe['rice'] = 1000; + } + + $updateMe['betray'] = $db->sqleval('`betray` + 1'); + $updateMe['dedication'] = $db->sqleval('dedication*(1-0.1*betray)'); + $updateMe['experience'] = $db->sqleval('experience*(1-0.1*betray)'); + + $db->update('nation', $updateOldNation, 'nation = %i', $messageInfo['dest']['nationID']); + } + else{ + $updateMe['dedication'] = $db->sqleval('dedication + 100'); + $updateMe['experience'] = $db->sqleval('experience + 100'); + } + + if($me['npc'] < 2){ + $updateMe['killturn'] = $killturn; + } + + $db->update('general', $updateMe, 'no = %i', $generalID); + + $db->query('UPDATE nation set '. + 'gennum = greatest(10, (SELECT count(`id`) from general where `nation` = %i_nation)), '. + 'totaltech = tech * greatest(10, (SELECT count(`id`) from general where `nation` = %i_nation)) '. + 'where nation=%i_nation', ['nation'=>$nationID]); + + //태수 군사 시중 해제 + switch($me['level']) { + case 4: + $db->query('update city set gen1=0 where gen1=%i', $generalID); + break; + case 3: + $db->query('update city set gen3=0 where gen2=%i', $generalID); + break; + case 2: + $db->query('update city set gen3=0 where gen2=%i', $generalID); + break; + } + + $db->query('UPDATE general left join troop on troop.troop = general.troop set general.troop = 0 where troop.no = %i', $generalID); + $db->query('delete from troop where no = %i', $generalID); + + $db->query('UPDATE `message` SET `valid_until`=\'1234-11-22 11:22:33\' WHERE `id` = %i', $messageInfo['id']); + $msg = "{$nationName}(으)로 등용 제의 수락"; + sendRawMessage('private', false, $general['no'], $messageInfo['src'], $messageInfo['dest'], $msg, null, null, ['parent'=>$messageInfo['id']]); + + pushGenLog($me, $mylog); + pushGenLog($you, $youlog); + pushAllLog($alllog); + pushHistory($alllog); + + return [true, 'success']; +} + +function declineScout($messageInfo, $reason=null){ + $me = [ + 'no'=>$messageInfo['dest']['id'], + 'name'=>$messageInfo['dest']['name'] + ]; + $you = ['no'=>$messageInfo['src']['id']]; + + $mylog = []; + $youlog = []; + + + $nationName = $messageInfo['src']['nation']; + if($reason){ + $mylog[] = "●{$reason} 등용 수락 불가."; + $msg = "{$nationName}(으)로 등용 제의 수락 불가"; + } + else{ + $youlog[] = "{$me['name']}(이)가 등용을 거부했습니다."; + $mylog[] = "{$nationName}(으)로 망명을 거부했습니다."; + $msg = "{$nationName}(으)로 등용 제의 거부"; + } + + $db = getDB(); + $db->query('UPDATE `message` SET `valid_until`=\'1234-11-22 11:22:33\' WHERE `id` = %i', $messageInfo['id']); + + sendRawMessage('private', false, $general['no'], $messageInfo['src'], $messageInfo['dest'], $msg, null, null, ['parent'=>$messageInfo['id']]); + + pushGenLog($me, $mylog); + pushGenLog($you, $youlog); + + return [true, 'success']; +} + +function acceptAlly($messageInfo, $general){ + +} + +function declineAlly($messageInfo, $general){ + +} + +function acceptBreakAlly($messageInfo, $general){ + +} + +function declineBreakAlly($messageInfo, $general){ + +} + +function acceptStopWar($messageInfo, $general){ + +} + +function declineStopWar($messageInfo, $general){ + +} + + +function acceptMergeNations($messageInfo, $general){ + +} + +function declineMergeNations($messageInfo, $general){ + +} + + +function acceptSurrender($messageInfo, $general){ + +} + +function declineSurrender($messageInfo, $general){ + +} \ No newline at end of file diff --git a/twe/j_msg_decide_opt.php b/twe/j_msg_decide_opt.php index 53965000..554a908d 100644 --- a/twe/j_msg_decide_opt.php +++ b/twe/j_msg_decide_opt.php @@ -30,7 +30,15 @@ if ($msgID === null || !is_bool($msgResponse)) { } -$result = getSingleMessage($msgID, $generalID); +$general = getDB()->queryFirstRow('select `no`, `name`, `nation`, `nations`, `level`, `npc`, `gold`, `rice`, `troop` from `general` where `no` = %i', $generalID); +if(!$general){ + returnJson([ + 'result'=>false, + 'reason'=>'존재하지 않는 장수' + ]); +} + +$result = getSingleMessage($msgID, $general); if (!$result[0]) { returnJson([ @@ -77,19 +85,12 @@ if ($msgType == 'diplomacy' && $msgSrc['nation_id'] != $msgDest['nation_id']) { } if($msgType == 'diplomacy'){ - if(!getNationStaticInfo($msgSrc['nation_id'])){ + if($general['level'] < 6){ returnJson([ 'result'=>false, - 'reason'=>'발신 국가 없음' + 'reason'=>'외교 권한 없음' ]); - } - - if(!getNationStaticInfo($msgDest['nation_id'])){ - returnJson([ - 'result'=>false, - 'reason'=>'수신 국가 없음' - ]); - } + } if($general['nation'] != $msgDest['nation_id']){ returnJson([ @@ -97,41 +98,15 @@ if($msgType == 'diplomacy'){ 'reason'=>'올바르지 않은 소속 국가' ]); } - - if($general['level'] < 6){ - returnJson([ - 'result'=>false, - 'reason'=>'외교 권한 없음' - ]); - } -} - -if(!$msgResponse){ - switch($msgAction){ - case 'scout': - $result = declineScout($messageInfo); - break; - case 'ally': - $result = declineAlly($messageInfo); - break; - //TODO:기타 등등 - default: - $result = [false, '처리 대상 아님']; - } - - returnJson([ - 'result' => $result[0], - 'reason' => $result[1] - ]); } switch ($msgAction) { case 'scout': //TODO: 등용장 받음. 함수 호출 - $result = acceptScout($messageInfo); + $result = acceptScout($messageInfo, $general, $msgResponse); break; case 'ally': - $result = acceptAlly($messageInfo); + $result = acceptAlly($messageInfo, $general, $msgResponse); break; //TODO:기타 등등 case '':