this.AIChibiActions = this.AIChibiActions || {}; (function() { "use strict"; // ACTIONS ==================================================================== var SetRandomPosition = function() { this.initialize(); } SetRandomPosition.prototype = new AILeafNode; SetRandomPosition.prototype.name = 'SetRandomPosition'; SetRandomPosition.prototype.update = function(target, fdelta) { target.memory.targetPosition = Math.random()*(registry.levelWidth-200)+100; target.memory.targetPosition -= (registry.levelWidth - 800)/2; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var GoToRandomPosition = function() { this.initialize(); } GoToRandomPosition.prototype = new AILeafNode; GoToRandomPosition.prototype.name = 'GoToRandomPosition'; GoToRandomPosition.prototype.update = function(target, fdelta) { if (target.memory.tree.interrupted) return AIFAILURE; target.forceWalk = false; var dx = target.memory.targetPosition - target.x; if (Math.abs(dx) < 20) { target.moveDirX = 0; return AISUCCESS; } target.moveDirX = dx/Math.abs(dx); // console.log(dx) return AIRUNNING; } // ============================================================================ // ACTIONS ==================================================================== var Wait = function(min_seconds, max_seconds) { this.initialize(min_seconds, max_seconds); } Wait.prototype = new AILeafNode; Wait.prototype.LeafNode_initialize = Wait.prototype.initialize; Wait.prototype.initialize = function(min_seconds, max_seconds) { this.LeafNode_initialize(); this.min_seconds = min_seconds; this.max_seconds = max_seconds; } Wait.prototype.name = 'Wait'; Wait.prototype.update = function(target, fdelta) { var seconds = this.getNodeVariable(target, 'seconds') var lastcont = this.getNodeVariable(target, 'lastcont') var currcont = target.memory.tree.executionCount; if (seconds === undefined || lastcont+1 != currcont) { seconds = RANDINT(this.min_seconds, this.max_seconds); } seconds -= fdelta; this.setNodeVariable(target, 'lastcont', currcont); if (seconds <= 0) { this.setNodeVariable(target, 'seconds', undefined); return AISUCCESS; } else { this.setNodeVariable(target, 'seconds', seconds); return AIRUNNING; } } // ============================================================================ // ACTIONS ==================================================================== var Stop = function() { this.initialize(); } Stop.prototype = new AILeafNode; Stop.prototype.name = 'Stop'; Stop.prototype.update = function(target, fdelta) { target.moveDirX = 0; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var GoToNearestSingleChibi = function() { this.initialize(); } GoToNearestSingleChibi.prototype = new AILeafNode; GoToNearestSingleChibi.prototype.name = 'GoToNearestSingleChibi'; GoToNearestSingleChibi.prototype.update = function(target, fdelta) { if (target.memory.tree.interrupted) return AIFAILURE; var relationTarget = this.getNodeVariable(target, 'relationTarget') if (relationTarget === undefined) { for (var i=0; i Math.abs(dx2)) { dx = dx2; } if (Math.abs(dx) < 5) { target.moveDirX = 0; target.relationTarget = relationTarget; return AISUCCESS; } target.moveDirX = dx/Math.abs(dx); return AIRUNNING; } // ============================================================================ // ACTIONS ==================================================================== var GoToNearestChattingChibi = function() { this.initialize(); } GoToNearestChattingChibi.prototype = new AILeafNode; GoToNearestChattingChibi.prototype.name = 'GoToNearestChattingChibi'; GoToNearestChattingChibi.prototype.update = function(target, fdelta) { if (target.memory.tree.interrupted) return AIFAILURE; var relationTarget = this.getNodeVariable(target, 'relationTarget') if (relationTarget === undefined) { for (var i=0; i Math.abs(dx2)) { dx = dx2; } if (Math.abs(dx) < 5) { target.moveDirX = 0; target.relationTarget = relationTarget; return AISUCCESS; } target.moveDirX = dx/Math.abs(dx); return AIRUNNING; } // ============================================================================ // ACTIONS ==================================================================== var SendConversationInvite = function() { this.initialize(); } SendConversationInvite.prototype = new AILeafNode; SendConversationInvite.prototype.name = 'SendConversationInvite'; SendConversationInvite.prototype.update = function(target, fdelta) { target.relationTarget.relationInvite = target; target.relationMyTurn = true; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var WaitForConversationResponse = function() { this.initialize(); } WaitForConversationResponse.prototype = new AILeafNode; WaitForConversationResponse.prototype.name = 'WaitForConversationResponse'; WaitForConversationResponse.prototype.update = function(target, fdelta) { if (target.relationStatus === 'talk') { target.relationMyTurn = true; return AISUCCESS; } else if (target.relationStatus === 'single' && target.relationTarget.relationInvite !== target) { return AIFAILURE; } return AIRUNNING; } // ============================================================================ // ACTIONS ==================================================================== var DenyConversationInvite = function() { this.initialize(); } DenyConversationInvite.prototype = new AILeafNode; DenyConversationInvite.prototype.name = 'DenyConversationInvite'; DenyConversationInvite.prototype.update = function(target, fdelta) { target.relationInvite.relationStatus = 'bored'; target.relationInvite.relationTocos++; target.relationInvite = null; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var AcceptConversationInvite = function() { this.initialize(); } AcceptConversationInvite.prototype = new AILeafNode; AcceptConversationInvite.prototype.name = 'AcceptConversationInvite'; AcceptConversationInvite.prototype.update = function(target, fdelta) { target.relationStatus = 'talk'; target.relationInvite.relationStatus = 'talk'; target.relationTarget = target.relationInvite; target.relationInvite = null; target.relationMyTurn = false; target.relationTarget.relationBad = 0; target.relationTarget.relationGood = 0; target.relationBad = 0; target.relationGood = 0; target.lookAt(target.relationTarget); target.relationTarget.lookAt(target); createjs.Tween.get(target) .to({y:target.y-40}, 300) .to({y:target.y}, 300) .to({y:target.y-40}, 300) .to({y:target.y}, 300) .to({y:target.y-40}, 300) .to({y:target.y}, 300); createjs.Tween.get(target.relationTarget) .to({y:target.y-40}, 300) .to({y:target.y}, 300) .to({y:target.y-40}, 300) .to({y:target.y}, 300) .to({y:target.y-40}, 300) .to({y:target.y}, 300); return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var AskQuestion = function() { this.initialize(); } AskQuestion.prototype = new AILeafNode; AskQuestion.prototype.name = 'AskQuestion'; AskQuestion.prototype.update = function(target, fdelta) { var questionIdx = RANDINT(0, DAT_TOPICS.length); var question = DAT_TOPICS[questionIdx]; target.relationTarget.relationQuestion = question; registry.chatQueue.push([target, question]); target.relationQuestion = null; target.relationAnswer = null; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var WaitAnswer = function() { this.initialize(); } WaitAnswer.prototype = new AILeafNode; WaitAnswer.prototype.name = 'WaitAnswer'; WaitAnswer.prototype.update = function(target, fdelta) { if (target.relationAnswer != null) { target.relationAnswer = null; return AISUCCESS; } return AIRUNNING; } // ============================================================================ // ACTIONS ==================================================================== var WaitQuestion = function() { this.initialize(); } WaitQuestion.prototype = new AILeafNode; WaitQuestion.prototype.name = 'WaitQuestion'; WaitQuestion.prototype.update = function(target, fdelta) { if (target.relationQuestion != null) { return AISUCCESS; } return AIRUNNING; } // ============================================================================ // ACTIONS ==================================================================== var AnswerQuestion = function() { this.initialize(); } AnswerQuestion.prototype = new AILeafNode; AnswerQuestion.prototype.name = 'AnswerQuestion'; AnswerQuestion.prototype.update = function(target, fdelta) { var topic = target.relationQuestion; if (Math.random() < CONST.RELATIONSHIP_SUCCESS_RATE) { target.relationTarget.relationAnswer = true; target.relationTarget.relationGood++; target.relationGood++; } else { target.relationTarget.relationAnswer = false; target.relationTarget.relationBad++; target.relationBad++; } registry.chatQueue.push([target, target.relationTarget.relationAnswer]); target.relationQuestion = null; target.relationAnswer = null; target.relationMyTurn = true; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var EndConversation = function() { this.initialize(); } EndConversation.prototype = new AILeafNode; EndConversation.prototype.name = 'EndConversation'; EndConversation.prototype.update = function(target, fdelta) { target.relationQuestion = null; target.relationAnswer = null; if (target.relationTarget) { target.relationTarget.relationQuestion = null; target.relationTarget.relationAnswer = null; target.relationTarget.relationTarget = null; target.relationTarget.relationStatus = 'bored'; target.relationTarget.relationTocos++; } target.relationTarget = null; target.relationStatus = 'bored'; target.relationTocos++; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var EndConversationWell = function() { this.initialize(); } EndConversationWell.prototype = new AILeafNode; EndConversationWell.prototype.name = 'EndConversationWell'; EndConversationWell.prototype.update = function(target, fdelta) { target.relationQuestion = null; target.relationAnswer = null; if (target.relationTarget) { target.relationTarget.relationQuestion = null; target.relationTarget.relationAnswer = null; target.relationTarget.relationTarget = null; target.relationTarget.relationStatus = 'single'; } target.relationTarget = null; target.relationStatus = 'single'; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var EndPartnerConversation = function() { this.initialize(); } EndPartnerConversation.prototype = new AILeafNode; EndPartnerConversation.prototype.name = 'EndPartnerConversation'; EndPartnerConversation.prototype.update = function(target, fdelta) { if (target.relationStatus == 'single') return AISUCCESS; target.relationQuestion = null; target.relationAnswer = null; if (target.relationTarget) { target.relationTarget.relationQuestion = null; target.relationTarget.relationAnswer = null; target.relationTarget.relationTarget = null; target.relationTarget.relationStatus = 'bored'; target.relationTarget.relationTocos++; } return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var RunAway = function() { this.initialize(); } RunAway.prototype = new AILeafNode; RunAway.prototype.name = 'RunAway'; RunAway.prototype.update = function(target, fdelta) { var dir = Math.random()-0.5; dir /= Math.abs(dir); target.relationStatus = 'running'; target.moveDirX = dir; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var Marry = function() { this.initialize(); } Marry.prototype = new AILeafNode; Marry.prototype.name = 'Marry'; Marry.prototype.update = function(target, fdelta) { var dir = Math.random()-0.5; dir /= Math.abs(dir); registry.chatQueue.push([target, 'love']); registry.chatQueue.push([target.relationTarget, 'love']); target.moveDirX = dir; target.relationStatus = 'running'; target.relationTarget.moveDirX = dir; target.relationTarget.relationStatus = 'running'; registry.points++; return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var Angry = function() { this.initialize(); } Angry.prototype = new AILeafNode; Angry.prototype.name = 'Angry'; Angry.prototype.update = function(target, fdelta) { registry.chatQueue.push([target, 'hate']); return AISUCCESS; } // ============================================================================ // ACTIONS ==================================================================== var GoSingle = function() { this.initialize(); } GoSingle.prototype = new AILeafNode; GoSingle.prototype.name = 'GoSingle'; GoSingle.prototype.update = function(target, fdelta) { target.relationStatus = 'single'; return AISUCCESS; } // ============================================================================ window.AIChibiActions.SetRandomPosition = SetRandomPosition; window.AIChibiActions.GoToRandomPosition = GoToRandomPosition; window.AIChibiActions.Wait = Wait; window.AIChibiActions.Stop = Stop; window.AIChibiActions.GoToNearestSingleChibi = GoToNearestSingleChibi; window.AIChibiActions.GoToNearestChattingChibi = GoToNearestChattingChibi; window.AIChibiActions.SendConversationInvite = SendConversationInvite; window.AIChibiActions.WaitForConversationResponse = WaitForConversationResponse; window.AIChibiActions.DenyConversationInvite = DenyConversationInvite; window.AIChibiActions.AcceptConversationInvite = AcceptConversationInvite; window.AIChibiActions.AskQuestion = AskQuestion; window.AIChibiActions.WaitAnswer = WaitAnswer; window.AIChibiActions.WaitQuestion = WaitQuestion; window.AIChibiActions.AnswerQuestion = AnswerQuestion; window.AIChibiActions.EndConversation = EndConversation; window.AIChibiActions.EndConversationWell = EndConversationWell; window.AIChibiActions.EndPartnerConversation = EndPartnerConversation; window.AIChibiActions.RunAway = RunAway; window.AIChibiActions.Marry = Marry; window.AIChibiActions.Angry = Angry; window.AIChibiActions.GoSingle = GoSingle; }());