- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
private function checkResourcesForIcon():void {
if (!(this is TotemMediator)) {
if ((!Player.instance.friendMode && buildable && step && step.bubbleIco) || _ico) {
sendNotification(GameNotifications.ADD_RESOURCE_CHECKER, {
'caller_id': id, 'res_v': step.requirement,
'action_0': { 'notification': ObjectNotifications.UPDATE_ICON, 'body': {'id': id, 'check': false } },
'action_1': { 'notification': ObjectNotifications.UPDATE_ICON, 'body': {'id': id, 'check': true } }
});
}
}
}
// команда на GameNotifications.ADD_RESOURCE_CHECKER
override public function execute(notification:INotification):void {
super.execute(notification);
var body:Object = notification.getBody();
var resChecker:ResourceChecker = this.facade.retrieveProxy(ResourceChecker.NAME) as ResourceChecker;
resChecker.addChecker(body.caller_id, body.res_v, body.action_0, body.action_1);
}
// ResourceChecker
public function addChecker(callerId:String, resV:Vector.<ResourceData>, action0:Object, action1:Object):void {
if (!callersToCheck) {
callersToCheck = { };
}
//overwrite
callersToCheck[callerId] = { 'res':resV, 'action0':action0, 'action1':action1, 'enough':false };
//recheck
checkCaller(callerId);
}
private function checkCaller(callerId:String):void {
if (callersToCheck[callerId]) {
var checkV:Vector.<ResourceData> = callersToCheck[callerId]['res'];
var allEnough:Boolean = true;
for each(var checkR:ResourceData in checkV) {
if (checkR.resourcetype != 'WORKER') { //TODO: wtf with worker?
//if no such res or res not enough OR this is not completed quest
if ((!storedResources[checkR.resourcetype] || storedResources[checkR.resourcetype].quantity < checkR.quantity) && storedQuests.indexOf(checkR.resourcetype) == -1) {
allEnough = false;
break;
}
}
}
if (allEnough && !callersToCheck[callerId]['enough']) {
callersToCheck[callerId]['enough'] = true;
executeAction(callersToCheck[callerId]['action1']);
}else if (!allEnough && callersToCheck[callerId]['enough']) {
callersToCheck[callerId]['enough'] = false;
executeAction(callersToCheck[callerId]['action0']);
}
}
}
// и наконец
private function executeAction(action:Object):void {
if (action) {
if (action['directive']) {
Facade.getInstance().sendNotification(GameNotifications.RUN_DIRECTIVE, {name: action['directive'], args: action['args'] });
} else if (action['notification']) {
Facade.getInstance().sendNotification(action['notification'], action['body']);
}
}
}