123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- const enum EActionPosition{
- ACTIONBAR = -1,
- BOTH = 0,
- PASSAGE = 1
- }
- var actAdd = function(macroContext:TwineSugarCube.MacroContext,label:string,contents:string,position?:EActionPosition,flags?:ActFlags){
- const pc = State.variables.pc;
- label ??= flags.label;
- let _styleClass = 'action';
- let _tooltip = '';
- let _act_contents = flags.contents ?? contents;
- let _capture_vars = flags.capture ?? [];
- _capture_vars.push('_autoCapture')//<!-- The vars that always get captured by actions -->
- if('action' in flags){
- flags = Object.assign({},flags,setup.getGenericActionApplied(flags.action))
- _act_contents += `<<actionApply '${flags.action}'>>`;
- }
- if(flags.disabled){
- _tooltip = flags.disabled ?? '';
- _styleClass += ' disabled';
- _act_contents = ''
- }
- if(flags.hidden){
- return;
- }
- if('time' in flags){
- if(flags.time > 0)
- _act_contents = `<<addtime ${flags.time}>>${_act_contents}`;
- label += ` (${setup.durationToString(Math.abs(flags.time))})`;
- }
- if('moodlet' in flags){
- let _moodletData = Moodlet.get(flags.moodlet);
- _tooltip += 'This would likely lead to you getting the effect '+_moodletData.title+'.';
- }
- if('mood' in flags){
- if(pc.mood < flags.mood){
- _tooltip += 'Your mood is too low to do this.'
- _styleClass += ' mood disabled'
- _act_contents = ''
- }else{
- _tooltip += 'Your mood is high enough (>='+flags.mood+') to do this.'
- _styleClass += ' mood'
- }
- }
- if('arousal' in flags){
- if(pc.horny < flags.arousal){
- _tooltip += 'Your arousal is too low ('+pc.horny+'/'+flags.arousal+') to do this.'
- _styleClass += ' arousal disabled'
- _act_contents = ''
- }else{
- _tooltip += 'Your arousal is high enough (>='+flags.arousal+') to do this.'
- _styleClass += ' arousal'
- }
- }
- /*if('fetish' in flags){
- let _actFetishes = flags.fetish
- <<for _actFetish range _actFetishes>>
- if(pc.fetish(_actFetish) < 0){
- let _tooltip += _actFetish+ ': You can\'t do this because of your fetish-settings (you can change them in the character-menu).'
- let _styleClass += ' fetish disabled'
- let _act_contents = ''
- }
- <</for>>
- }*/
- //<!-- Skills -->
- if('skillRequirment' in flags){
- let _skillsMessage = ''
- let _skillsEnable = true
- for(const[_skillId, _skillMin] of Object.entries(flags.skillRequirment)){
- if(pc.skillLevel(_skillId) >= _skillMin){
- _skillsMessage += 'Your skill '+_skillId+' of '+_skillMin+'+ enables you to do this.'
- }else{
- _skillsMessage += 'Your skill '+_skillId+' needs to be '+_skillMin+'+ to do this.'
- _skillsEnable = false
- }
- }
- _tooltip += _skillsMessage
- if(_skillsEnable){
- _styleClass += ' skill'
- }else{
- _styleClass += ' skill disabled'
- _act_contents = ''
- }
- }
- //#region Personality
- if(flags.personality){
- if(flags.willpower){
- console.error('personality and willpower must not be declare at the same time in actAdd: (label, flags)',label,flags);
- }
- let personality_willpower = 0;
- for(const [personalityId, personalityRequirement] of Object.entries(flags.personality)){
- const expectedPersonalityEffect = pc.personalityScale(personalityId).effectOfAction(personalityRequirement);
- if(expectedPersonalityEffect.willpower > 0)
- personality_willpower += expectedPersonalityEffect.willpower;
- }
- if(personality_willpower){
- }
- }
- //#endregion
- //#region Willpower
- if(flags.willpower){
- let _willpower_cost = 0;
- if(typeof flags.willpower == "number"){
- _willpower_cost = flags.willpower
- }else{
- _willpower_cost = setup.func('willpower','cost',flags.willpower)
- }
- label += " ("+_willpower_cost+")"
- if(_willpower_cost > pc.willpower){
- _styleClass += ' willpower willpower_disabled disabled'
- _act_contents = ''
- _tooltip = "You don\'t have enough willpower to perform this action."
- }else{
- _styleClass += ' willpower'
- _act_contents = "<<gs 'willpower' 'pay' "+_willpower_cost+" `"+ JSON.stringify(flags.willpower)+"`" + _act_contents;
- }
- }
-
- //#endregion
- //<!-- Money Cost -->
- if('cost' in flags){
- if(flags.cost.cash){
- let _cashCost = flags.cost.cash;
- label += " (<b>"+Math.abs(_cashCost).toLocaleString()+" ₽</b> Cash)"
- if(Math.abs(_cashCost) > State.variables.finances.cash){
- _styleClass += ' cost cost_disabled disabled'
- _act_contents = ''
- _tooltip = "You don\'t have enough cash to perform this action."
- }else{
- _styleClass += ' cost'
- if(_cashCost > 0){
- _act_contents = "<<set $finances.cash -= "+_cashCost+">>" + _act_contents;
- }
- }
- }else if(flags.cost.bank){
- let _bankCost = flags.cost.bank;
- label += " (<b>"+Math.abs(_bankCost).toLocaleString()+" ₽</b> from Bank Account)"
- if(!State.variables.finances.hasBankAccount){
- _styleClass += ' cost cost_disabled disabled';
- _act_contents = '';
- _tooltip = "You don't have a bank account.";
- }else if(Math.abs(_bankCost) > State.variables.finances.bankAvailable){
- _styleClass += ' cost cost_disabled disabled'
- _act_contents = ''
- _tooltip = "You don\'t have enough money on your bank account to perform this action."
- }else{
- _styleClass += ' cost'
- if(_bankCost > 0){
- _act_contents = "<<set $finances.bank -= "+_bankCost+">>" + _act_contents;
- }
- }
- }else if(flags.cost.both){
- let flagsOfCashButton = clone(flags);
- flagsOfCashButton.cost = {cash: flags.cost.both};
- let _contentsOfCashButton = clone(this.payload[0].contents)
- let flagsOfBankButton = clone(flags)
- flagsOfBankButton.cost = {bank: flags.cost.both}
- let _contentsOfBankButton = clone(this.payload[0].contents)
- actAdd(macroContext,label,_contentsOfCashButton,position,flagsOfCashButton);
- actAdd(macroContext,label,_contentsOfBankButton,position,flagsOfBankButton);
- return;
- }
- }
- //<!-- Do Once Every n time-units -->
- if('repeatReset' in flags){
- let _uniqueActionId = State.temporary.thisMainPassage + '~' + this.args[0]//<!-- Use the raw label so it doesn't get fucked up by willlpower calculations -->
- let _repeatResetCooldownEnd = State.variables.actions[_uniqueActionId]?.cooldownEnd ?? 0
- if(_repeatResetCooldownEnd < State.variables.time.now.getTime()){
- if(flags.repeatReset.days){
- _act_contents = "<<set $actions['"+_uniqueActionId+"'] = {cooldownEnd:$time.dayWithOffset("+flags.repeatReset.days+")}>>" + _act_contents;
- }
- }else{
- return;
- }
- }
- //<!-- items -->
- if('items' in flags){
- let _missingItems = ''
- for(const[_itemKey, _itemAmount] of Object.entries(flags.items)){
- if(_itemAmount > State.variables.inventory.get(_itemKey))
- _missingItems += '<br/>'+State.variables.inventory.metadata(_itemKey).label+': '+_itemAmount
- else if(_itemAmount > 0)
- _act_contents = "<<run $inventory.dec('"+_itemKey+"',"+_itemAmount+")>>" + _act_contents
-
- }
- if(_missingItems){
- _styleClass += ' disabled'
- _act_contents = ''
- _tooltip = 'You are missing the following:'+_missingItems+"x"
- }
- }
- if(_act_contents){
- _act_contents = (flags.contents_header ?? '') + _act_contents + (flags.contents_footer ?? '');
- }
- if(position == EActionPosition.BOTH || position === EActionPosition.ACTIONBAR){
- let _ab_label = flags.ab_label ?? label;
- let _priority = flags.priority ?? 0;
- let _capture_vars_actionBar = {};
- for(const _capture_var of _capture_vars)
- _capture_vars_actionBar[_capture_var] = clone(State.getVar(_capture_var))
-
- State.temporary.actions ??= [];
- State.temporary.actions.push( new setup.Action(
- {
- passage: passage(),
- label: _ab_label,
- contents: _act_contents,
- priority: _priority,
- captured: _capture_vars_actionBar,
- styleClass: _styleClass,
- tooltip: _tooltip,
- image: flags.image
- })
- );
- }
- if(position == EActionPosition.BOTH || position === EActionPosition.PASSAGE){
- let _linkMarkup = `<<link '${label}'>>${_act_contents}<</link>>`;
-
- if(_capture_vars.length > 0){
- _linkMarkup = '<<capture '+_capture_vars.join(', ')+'>>'+_linkMarkup+'<</capture>>';
- }
- jQuery(macroContext.output).wiki(`<<tooltip 'span' '${_styleClass}' '${_tooltip}'>>${_linkMarkup}<</tooltip>>`);
-
- }
- }
- Macro.add('act', {
- skipArgs : false,
- tags:[],
- handler : function () {
- try {
-
- let label:string = this.args[0];
- const position:EActionPosition = this.args[1] ?? State.temporary.actionBarOverride ?? EActionPosition.ACTIONBAR;
- let flags:ActFlags = this.args[2] ?? {};
- actAdd(this,label,this.payload[0].contents,position,flags);
- }
- catch (ex) {
- return this.error('ERROR in act-widget: ' + ex.message);
- }
- }
- });
- Macro.add('actCLA', {
- skipArgs : false,
- tags:[],
- handler : function () {
- try {
-
- let label:string = this.args[0];
- const position:EActionPosition = this.args[1] ?? State.temporary.actionBarOverride ?? EActionPosition.ACTIONBAR;
- let flags:ActFlags = this.args[2] ?? {};
- flags.contents_header = '<<set _actions = []>><<replace ".passage">>';
- flags.contents_footer = '<</replace>><<actionsRefresh>><<sidebarUpdate>>';
- actAdd(this,label,this.payload[0].contents,position,flags);
- }
- catch (ex) {
- return this.error('ERROR in act-widget: ' + ex.message);
- }
- }
- });
|