From 800c85dd0344788ae5a4c06d2c6900a245077039 Mon Sep 17 00:00:00 2001 From: hide_d Date: Tue, 12 May 2020 03:20:20 +0900 Subject: [PATCH] npc_control form --- e_lib/Sortable.min.js | 2 + e_lib/jquery-sortable.js | 76 ++++++++ hwe/b_npc_control.php | 271 +++++++++++++++++++++++++++++ hwe/css/main.css | 2 +- hwe/css/npc_control.css | 45 +++++ hwe/js/npc_control.js | 69 ++++++++ hwe/sammo/AutorunGeneralPolicy.php | 25 ++- hwe/sammo/AutorunNationPolicy.php | 66 +++++-- hwe/sammo/GeneralAI.php | 8 +- hwe/sammo/Scenario/NPC.php | 4 +- hwe/templates/commandButton.php | 9 +- src/sammo/Util.php | 4 +- 12 files changed, 554 insertions(+), 27 deletions(-) create mode 100644 e_lib/Sortable.min.js create mode 100644 e_lib/jquery-sortable.js create mode 100644 hwe/b_npc_control.php create mode 100644 hwe/css/npc_control.css create mode 100644 hwe/js/npc_control.js diff --git a/e_lib/Sortable.min.js b/e_lib/Sortable.min.js new file mode 100644 index 00000000..eba06149 --- /dev/null +++ b/e_lib/Sortable.min.js @@ -0,0 +1,2 @@ +/*! Sortable 1.10.2 - MIT | git://github.com/SortableJS/Sortable.git */ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Sortable=e()}(this,function(){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(){return(a=Object.assign||function(t){for(var e=1;e"===e[0]&&(e=e.substring(1)),t)try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch(t){return!1}return!1}}function P(t,e,n,o){if(t){n=n||document;do{if(null!=e&&(">"===e[0]?t.parentNode===n&&h(t,e):h(t,e))||o&&t===n)return t;if(t===n)break}while(t=(i=t).host&&i!==document&&i.host.nodeType?i.host:i.parentNode)}var i;return null}var f,p=/\s+/g;function k(t,e,n){if(t&&e)if(t.classList)t.classList[n?"add":"remove"](e);else{var o=(" "+t.className+" ").replace(p," ").replace(" "+e+" "," ");t.className=(o+(n?" "+e:"")).replace(p," ")}}function R(t,e,n){var o=t&&t.style;if(o){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];e in o||-1!==e.indexOf("webkit")||(e="-webkit-"+e),o[e]=n+("string"==typeof n?"":"px")}}function v(t,e){var n="";if("string"==typeof t)n=t;else do{var o=R(t,"transform");o&&"none"!==o&&(n=o+" "+n)}while(!e&&(t=t.parentNode));var i=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return i&&new i(n)}function g(t,e,n){if(t){var o=t.getElementsByTagName(e),i=0,r=o.length;if(n)for(;i=e.left-n&&r<=e.right+n,i=a>=e.top-n&&a<=e.bottom+n;return n&&o&&i?l=t:void 0}}),l}((t=t.touches?t.touches[0]:t).clientX,t.clientY);if(e){var n={};for(var o in t)t.hasOwnProperty(o)&&(n[o]=t[o]);n.target=n.rootEl=e,n.preventDefault=void 0,n.stopPropagation=void 0,e[j]._onDragOver(n)}}}function kt(t){z&&z.parentNode[j]._isOutsideThisEl(t.target)}function Rt(t,e){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));this.el=t,this.options=e=a({},e),t[j]=this;var n={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(t.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return Ot(t,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(t,e){t.setData("Text",e.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==Rt.supportPointer&&"PointerEvent"in window,emptyInsertThreshold:5};for(var o in O.initializePlugins(this,t,n),n)o in e||(e[o]=n[o]);for(var i in At(e),this)"_"===i.charAt(0)&&"function"==typeof this[i]&&(this[i]=this[i].bind(this));this.nativeDraggable=!e.forceFallback&&xt,this.nativeDraggable&&(this.options.touchStartThreshold=1),e.supportPointer?u(t,"pointerdown",this._onTapStart):(u(t,"mousedown",this._onTapStart),u(t,"touchstart",this._onTapStart)),this.nativeDraggable&&(u(t,"dragover",this),u(t,"dragenter",this)),bt.push(this.el),e.store&&e.store.get&&this.sort(e.store.get(this)||[]),a(this,T())}function Xt(t,e,n,o,i,r,a,l){var s,c,u=t[j],d=u.options.onMove;return!window.CustomEvent||w||E?(s=document.createEvent("Event")).initEvent("move",!0,!0):s=new CustomEvent("move",{bubbles:!0,cancelable:!0}),s.to=e,s.from=t,s.dragged=n,s.draggedRect=o,s.related=i||e,s.relatedRect=r||X(e),s.willInsertAfter=l,s.originalEvent=a,t.dispatchEvent(s),d&&(c=d.call(u,s,a)),c}function Yt(t){t.draggable=!1}function Bt(){Dt=!1}function Ft(t){for(var e=t.tagName+t.className+t.src+t.href+t.textContent,n=e.length,o=0;n--;)o+=e.charCodeAt(n);return o.toString(36)}function Ht(t){return setTimeout(t,0)}function Lt(t){return clearTimeout(t)}Rt.prototype={constructor:Rt,_isOutsideThisEl:function(t){this.el.contains(t)||t===this.el||(ht=null)},_getDirection:function(t,e){return"function"==typeof this.options.direction?this.options.direction.call(this,t,e,z):this.options.direction},_onTapStart:function(e){if(e.cancelable){var n=this,o=this.el,t=this.options,i=t.preventOnFilter,r=e.type,a=e.touches&&e.touches[0]||e.pointerType&&"touch"===e.pointerType&&e,l=(a||e).target,s=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||l,c=t.filter;if(function(t){St.length=0;var e=t.getElementsByTagName("input"),n=e.length;for(;n--;){var o=e[n];o.checked&&St.push(o)}}(o),!z&&!(/mousedown|pointerdown/.test(r)&&0!==e.button||t.disabled||s.isContentEditable||(l=P(l,t.draggable,o,!1))&&l.animated||Z===l)){if(J=F(l),et=F(l,t.draggable),"function"==typeof c){if(c.call(this,e,l,this))return W({sortable:n,rootEl:s,name:"filter",targetEl:l,toEl:o,fromEl:o}),K("filter",n,{evt:e}),void(i&&e.cancelable&&e.preventDefault())}else if(c&&(c=c.split(",").some(function(t){if(t=P(s,t.trim(),o,!1))return W({sortable:n,rootEl:t,name:"filter",targetEl:l,fromEl:o,toEl:o}),K("filter",n,{evt:e}),!0})))return void(i&&e.cancelable&&e.preventDefault());t.handle&&!P(s,t.handle,o,!1)||this._prepareDragStart(e,a,l)}}},_prepareDragStart:function(t,e,n){var o,i=this,r=i.el,a=i.options,l=r.ownerDocument;if(n&&!z&&n.parentNode===r){var s=X(n);if(q=r,G=(z=n).parentNode,V=z.nextSibling,Z=n,ot=a.group,rt={target:Rt.dragged=z,clientX:(e||t).clientX,clientY:(e||t).clientY},ct=rt.clientX-s.left,ut=rt.clientY-s.top,this._lastX=(e||t).clientX,this._lastY=(e||t).clientY,z.style["will-change"]="all",o=function(){K("delayEnded",i,{evt:t}),Rt.eventCanceled?i._onDrop():(i._disableDelayedDragEvents(),!c&&i.nativeDraggable&&(z.draggable=!0),i._triggerDragStart(t,e),W({sortable:i,name:"choose",originalEvent:t}),k(z,a.chosenClass,!0))},a.ignore.split(",").forEach(function(t){g(z,t.trim(),Yt)}),u(l,"dragover",Pt),u(l,"mousemove",Pt),u(l,"touchmove",Pt),u(l,"mouseup",i._onDrop),u(l,"touchend",i._onDrop),u(l,"touchcancel",i._onDrop),c&&this.nativeDraggable&&(this.options.touchStartThreshold=4,z.draggable=!0),K("delayStart",this,{evt:t}),!a.delay||a.delayOnTouchOnly&&!e||this.nativeDraggable&&(E||w))o();else{if(Rt.eventCanceled)return void this._onDrop();u(l,"mouseup",i._disableDelayedDrag),u(l,"touchend",i._disableDelayedDrag),u(l,"touchcancel",i._disableDelayedDrag),u(l,"mousemove",i._delayedDragTouchMoveHandler),u(l,"touchmove",i._delayedDragTouchMoveHandler),a.supportPointer&&u(l,"pointermove",i._delayedDragTouchMoveHandler),i._dragStartTimer=setTimeout(o,a.delay)}}},_delayedDragTouchMoveHandler:function(t){var e=t.touches?t.touches[0]:t;Math.max(Math.abs(e.clientX-this._lastX),Math.abs(e.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){z&&Yt(z),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var t=this.el.ownerDocument;d(t,"mouseup",this._disableDelayedDrag),d(t,"touchend",this._disableDelayedDrag),d(t,"touchcancel",this._disableDelayedDrag),d(t,"mousemove",this._delayedDragTouchMoveHandler),d(t,"touchmove",this._delayedDragTouchMoveHandler),d(t,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(t,e){e=e||"touch"==t.pointerType&&t,!this.nativeDraggable||e?this.options.supportPointer?u(document,"pointermove",this._onTouchMove):u(document,e?"touchmove":"mousemove",this._onTouchMove):(u(z,"dragend",this),u(q,"dragstart",this._onDragStart));try{document.selection?Ht(function(){document.selection.empty()}):window.getSelection().removeAllRanges()}catch(t){}},_dragStarted:function(t,e){if(vt=!1,q&&z){K("dragStarted",this,{evt:e}),this.nativeDraggable&&u(document,"dragover",kt);var n=this.options;t||k(z,n.dragClass,!1),k(z,n.ghostClass,!0),Rt.active=this,t&&this._appendGhost(),W({sortable:this,name:"start",originalEvent:e})}else this._nulling()},_emulateDragOver:function(){if(at){this._lastX=at.clientX,this._lastY=at.clientY,Nt();for(var t=document.elementFromPoint(at.clientX,at.clientY),e=t;t&&t.shadowRoot&&(t=t.shadowRoot.elementFromPoint(at.clientX,at.clientY))!==e;)e=t;if(z.parentNode[j]._isOutsideThisEl(t),e)do{if(e[j]){if(e[j]._onDragOver({clientX:at.clientX,clientY:at.clientY,target:t,rootEl:e})&&!this.options.dragoverBubble)break}t=e}while(e=e.parentNode);It()}},_onTouchMove:function(t){if(rt){var e=this.options,n=e.fallbackTolerance,o=e.fallbackOffset,i=t.touches?t.touches[0]:t,r=U&&v(U,!0),a=U&&r&&r.a,l=U&&r&&r.d,s=Ct&>&&b(gt),c=(i.clientX-rt.clientX+o.x)/(a||1)+(s?s[0]-Et[0]:0)/(a||1),u=(i.clientY-rt.clientY+o.y)/(l||1)+(s?s[1]-Et[1]:0)/(l||1);if(!Rt.active&&!vt){if(n&&Math.max(Math.abs(i.clientX-this._lastX),Math.abs(i.clientY-this._lastY))o.right+10||t.clientX<=o.right&&t.clientY>o.bottom&&t.clientX>=o.left:t.clientX>o.right&&t.clientY>o.top||t.clientX<=o.right&&t.clientY>o.bottom+10}(n,a,this)&&!g.animated){if(g===z)return A(!1);if(g&&l===n.target&&(s=g),s&&(i=X(s)),!1!==Xt(q,l,z,o,s,i,n,!!s))return O(),l.appendChild(z),G=l,N(),A(!0)}else if(s.parentNode===l){i=X(s);var v,m,b,y=z.parentNode!==l,w=!function(t,e,n){var o=n?t.left:t.top,i=n?t.right:t.bottom,r=n?t.width:t.height,a=n?e.left:e.top,l=n?e.right:e.bottom,s=n?e.width:e.height;return o===a||i===l||o+r/2===a+s/2}(z.animated&&z.toRect||o,s.animated&&s.toRect||i,a),E=a?"top":"left",D=Y(s,"top","top")||Y(z,"top","top"),S=D?D.scrollTop:void 0;if(ht!==s&&(m=i[E],yt=!1,wt=!w&&e.invertSwap||y),0!==(v=function(t,e,n,o,i,r,a,l){var s=o?t.clientY:t.clientX,c=o?n.height:n.width,u=o?n.top:n.left,d=o?n.bottom:n.right,h=!1;if(!a)if(l&&ptsetReadOnly(); +$userID = Session::getUserID(); + +$db = DB::db(); +$gameStor = KVStorage::getStorage($db, 'game_env'); + + +increaseRefresh("NPC 정책", 1); + + +$me = $db->queryFirstRow('SELECT no, npc, nation, city, officer_level, con, turntime, belong, permission, penalty FROM general WHERE owner=%i', $userID); + +$nationID = $me['nation']; +$nation = $db->queryFirstRow('SELECT nation,level,name,color,type,gold,rice,bill,rate,scout,war,secretlimit,capital FROM nation WHERE nation = %i', $nationID); + +$con = checkLimit($me['con']); +if ($con >= 2) { + printLimitMsg($me['turntime']); + exit(); +} + +$permission = checkSecretPermission($me); +if ($permission < 0) { + echo '국가에 소속되어있지 않습니다.'; + die(); +} else if ($permission < 1) { + echo "권한이 부족합니다. 수뇌부가 아니거나 사관년도가 부족합니다."; + die(); +} + + +$nationStor = KVStorage::getStorage($db, $nationID, 'nation_env'); +$nationStor->cacheValues(['npc_nation_policy', 'npc_general_policy']); +$gameStor->cacheAll(); + +$general = new General($me, null, null, $nation, $gameStor->year, $gameStor->month, false); + +$rawServerPolicy = $gameStor->getValue('npc_nation_policy') ?? []; +$rawNationPolicy = $nationStor->getValue('npc_nation_policy') ?? []; +$rawServerGeneralPolicy = $gameStor->getValue('npc_general_policy') ?? []; +$rawNationGeneralPolicy = $nationStor->getValue('npc_general_policy') ?? []; + +$defaultNationPolicy = ($rawServerPolicy['values'] ?? []) + AutorunNationPolicy::$defaultPolicy; +$currentNationPolicy = ($rawNationPolicy['values'] ?? []) + $defaultNationPolicy; + +$defaultNationPriority = $rawServerPolicy['priority'] ?? (AutorunNationPolicy::$defaultPriority); +$currentNationPriority = $rawNationPolicy['priority'] ?? $defaultNationPriority; + +$defaultGeneralActionPriority = $rawServerGeneralPolicy['priority'] ?? (AutorunGeneralPolicy::$default_priority); +$currentGeneralActionPriority = $rawNationGeneralPolicy['priority'] ?? $defaultGeneralActionPriority; + +?> + + + + + + + + <?= UniqueConst::$serverName ?>: 임시 NPC 정책 + + + + + + + + + + + + + + + + + +
+
임시 NPC 정책
+
+ +
국가 정책
+
+
+
+
+ +
+ +
+
+
이 보다 많으면 포상, 적으면 몰수합니다.(긴급포상 제외)
+
+ + +
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+ 전투 부대는 작업중입니다(json양식: {부대번호:[시작도시번호(아국),도착도시번호(적군)],...})
+ 후방 징병 부대는 작업중입니다(json양식: [부대번호,...])
+ 내정 부대는 작업중입니다(json양식: [부대번호,...]) + + + + +
+
+ +
+
+
+
+
NPC 사령턴 우선순위
+
+
+
+
비활성
+
+
비활성화1
+
비활성화2
+
+
+
+
활성
+
+
활성화1
+
활성화2
+
활성화3
+
활성화4
+
+
+
+
+ +
+
+
+
+
NPC 일반턴 우선순위
+
+
+
+
비활성
+
+
비활성화1
+
비활성화2
+
+
+
+
활성
+
+
활성화1
+
활성화2
+
활성화3
+
활성화4
+
+
+
+
+ +
+
+
+
+
+ + + \ No newline at end of file diff --git a/hwe/css/main.css b/hwe/css/main.css index 45dc08ef..600aea20 100644 --- a/hwe/css/main.css +++ b/hwe/css/main.css @@ -31,7 +31,7 @@ color:white; .commandButton { float:left; - width:111px; + width:100px; height:30px; font-weight:bold; font-size:13px; diff --git a/hwe/css/npc_control.css b/hwe/css/npc_control.css new file mode 100644 index 00000000..0939b991 --- /dev/null +++ b/hwe/css/npc_control.css @@ -0,0 +1,45 @@ +.section_bar{ + text-align:center; + border:0.5px solid #aaa; + padding-right:0; + padding-left:0; +} + +.sub_bar{ + text-align:center; + border:0.5px solid #aaa; + margin-left:-5px; + margin-right:-5px; +} + +.reset_btn{ + width:15ch; +} + +.submit_btn{ + margin-left:1em; + width:15ch; +} + +.control_bar{ + margin-top:8pt; + text-align:right; +} + +.col-form-label{ + text-align:right; + padding-right:2ch; +} + +.form_list{ + padding:8pt; +} + +.half_section_left{ + padding-right:0; + border-right:0.5px solid #aaa; +} +.half_section_right{ + padding-left:0; + +} \ No newline at end of file diff --git a/hwe/js/npc_control.js b/hwe/js/npc_control.js new file mode 100644 index 00000000..79f82f40 --- /dev/null +++ b/hwe/js/npc_control.js @@ -0,0 +1,69 @@ +jQuery(function($){ + +function initPriority(priorityKey, currentPriority, availablePriority){ + var $disabledList = $('#{0}Disabled'.format(priorityKey)); + var $enabledList = $('#{0}'.format(priorityKey)); + + $disabledList.empty(); + $enabledList.empty(); + + var usedKey = {}; + var itemFrame = '
{0}
'; + $.each(currentPriority, function(key, val){ + var $item = $(itemFrame.format(val)); + usedKey[val] = true; + $enabledList.append($item); + }) + + var $disabled = $(itemFrame.format('<비활성화 항목들>')).addClass('filtered'); + $disabledList.append($disabled); + + $.each(availablePriority, function(key, val){ + if(val in usedKey){ + return true; + } + var $item = $(itemFrame.format(val)); + $disabledList.append($item); + }) + + $disabledList.sortable({ + group: priorityKey, + filter: '.filtered', + animation: 150 + }); + + $enabledList.sortable({ + group: priorityKey, + filter: '.filtered', + animation: 150 + }); +} + +initPriority('generalPriority', currentGeneralActionPriority, availableGeneralActionPriorityItems); +initPriority('nationPriority', currentNationPriority, availableNationPriorityItems); + + +$.each(currentNationPolicy, function(key, val){ + var $obj = $('#{0}'.format(key)); + + if(!$obj.length){ + console.log('{0}가 없대!'.format(key)); + return true; + } + + var type=$obj.data('type'); + if(!$obj.is('input')){ + console.log('아니라고?'); + return true; + } + + if(type =='percent'){ + $obj.val(val*100); + } + else{ + $obj.val(val); + } + +}); + +}); \ No newline at end of file diff --git a/hwe/sammo/AutorunGeneralPolicy.php b/hwe/sammo/AutorunGeneralPolicy.php index 855d144a..75faf145 100644 --- a/hwe/sammo/AutorunGeneralPolicy.php +++ b/hwe/sammo/AutorunGeneralPolicy.php @@ -113,10 +113,31 @@ class AutorunGeneralPolicy{ } - function __construct(General $general, $aiOptions, array $nationPolicy, array $serverPolicy, array $nation, array $env){ - //TODO: 국가 정책을 받아와야함 + function __construct(General $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env){ $this->priority = static::$default_priority; + if($serverPolicy && key_exists('priority', $serverPolicy)){ + $priority = []; + foreach($serverPolicy['priority'] as $priorityItem){ + if(!property_exists($this, $priorityItem)){ + continue; + } + $priority[] = $priorityItem; + } + $this->priority = $priority; + } + + if($nationPolicy && key_exists('priority', $nationPolicy)){ + $priority = []; + foreach($nationPolicy['priority'] as $priorityItem){ + if(!property_exists($this, $priorityItem)){ + continue; + } + $priority[] = $priorityItem; + } + $this->priority = $priority; + } + if($general->getNPCType() >= 2){ $this->doNPCState($general); return; diff --git a/hwe/sammo/AutorunNationPolicy.php b/hwe/sammo/AutorunNationPolicy.php index e9f42ab5..880d7f25 100644 --- a/hwe/sammo/AutorunNationPolicy.php +++ b/hwe/sammo/AutorunNationPolicy.php @@ -140,22 +140,68 @@ class AutorunNationPolicy { public $safeRecruitCityPopulationRatio = 0.5; public $properWarTrainAtmos = 90; + ///이쪽의 값이 실제 초기화 값임 + public static $defaultPolicy = [ + 'reqNationGold'=>10000, + 'reqNationRice'=>12000, + 'CombatForce'=>[], + 'SupportForce'=>[], + 'DevelopForce'=>[], + 'reqHumanWarUrgentGold'=>0, + 'reqHumanWarUrgentRice'=>0, + 'reqHumanWarRecommandGold'=>0, + 'reqHumanWarRecommandRice'=>0, + 'reqHumanDevelGold'=>10000, + 'reqHumanDevelRice'=>10000, + 'reqNPCWarGold'=>0, + 'reqNPCWarRice'=>0, + 'reqNPCDevelGold'=>0, + 'reqNPCDevelRice'=>500, + + 'minimumResourceActionAmount'=>1000, + + 'minNPCWarLeadership'=>40, + 'minWarCrew'=>1500, + + 'allowNpcAttackCity'=>true, + 'minNPCRecruitCityPopulation'=>50000, + 'safeRecruitCityPopulationRatio'=>0.5, + 'properWarTrainAtmos'=>90, + ]; - function __construct(General $general, $aiOptions, array $nationPolicy, array $serverPolicy, array $nation, array $env) + function __construct(General $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env) { - foreach($serverPolicy as $policy=>$value){ - if(!property_exists($this, $policy)){ - continue; - } - $this->$policy = $value; + foreach(static::$defaultPolicy as $policy=>$value){ + $this->{$policy} = $value; } + + if($serverPolicy){ + foreach($serverPolicy['values']??[] as $policy=>$value){ + if(!property_exists($this, $policy)){ + continue; + } + $this->$policy = $value; + } - foreach($nationPolicy as $policy){ - if(!property_exists($this, $policy)){ - continue; + if(key_exists('priority', $serverPolicy)){ + $this->priority = $serverPolicy['priority']; } - $this->$policy = $value; } + + + if($nationPolicy){ + foreach($nationPolicy['values']??[] as $policy){ + if(!property_exists($this, $policy)){ + continue; + } + $this->$policy = $value; + } + + if(key_exists('priority', $nationPolicy)){ + $this->priority = $nationPolicy['priority']; + } + } + if(!$this->priority){ $this->priority = $this::$defaultPriority; diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 089ff3d5..acc577bb 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -113,11 +113,11 @@ class GeneralAI 'name' => '재야', ]; - $serverPolicy = KVStorage::getStorage($db, 'autorun_nation_policy_0'); - $nationPolicy = KVStorage::getStorage($db, "autorun_nation_policy_{$this->nation['nation']}"); + $gameStor = KVStorage::getStorage($db, 'game_env'); + $nationStor = KVStorage::getStorage($db, $this->nation['nation'], 'nation_env'); - $this->nationPolicy = new AutorunNationPolicy($general, $this->env['autorun_user']['options']??[], $nationPolicy->getAll(), $serverPolicy->getAll(), $this->nation, $this->env); - $this->generalPolicy = new AutorunGeneralPolicy($general, $this->env['autorun_user']['options']??[], $nationPolicy->getAll(), $serverPolicy->getAll(), $this->nation, $this->env); + $this->nationPolicy = new AutorunNationPolicy($general, $this->env['autorun_user']['options'], $nationStor->getValue('npc_general_policy'), $gameStor->getValue('npc_general_policy'), $this->nation, $this->env); + $this->generalPolicy = new AutorunGeneralPolicy($general, $this->env['autorun_user']['options'], $nationStor->getValue('npc_nation_policy'), $gameStor->getValue('npc_nation_policy'), $this->nation, $this->env); $this->nation['aux'] = Json::decode($this->nation['aux']??'{}'); diff --git a/hwe/sammo/Scenario/NPC.php b/hwe/sammo/Scenario/NPC.php index f4bd3f50..3ce630b2 100644 --- a/hwe/sammo/Scenario/NPC.php +++ b/hwe/sammo/Scenario/NPC.php @@ -303,8 +303,8 @@ class NPC{ $killturn = ($this->death - $year) * 12 + mt_rand(0, 11) + $month - 1; } - $specage = $this->specAge?:$age + 1; - $specage2 = $this->specAge2?:$age + 1; + $specage = $this->specAge?:($age + 1); + $specage2 = $this->specAge2?:($age + 1); $db->insert('general',[ 'npc'=>$this->npc, diff --git a/hwe/templates/commandButton.php b/hwe/templates/commandButton.php index 4d26a0de..5aae5dad 100644 --- a/hwe/templates/commandButton.php +++ b/hwe/templates/commandButton.php @@ -7,20 +7,17 @@ + - - - -
- - + + diff --git a/src/sammo/Util.php b/src/sammo/Util.php index 19705e75..88631a75 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -284,10 +284,10 @@ class Util extends \utilphp\util return $result; } - public static function convertArrayToSetLike($arr){ + public static function convertArrayToSetLike($arr, $valueIsKey=true){ $result = []; foreach($arr as $datum){ - $result[$datum] = $datum; + $result[$datum] = $valueIsKey?$datum:1; } return $result; }