Frame 1
function Events() {
var listeners = new Array();
var stopCount = 0;
Object.prototype.eventOrphan = false;
this.runIt = function (object) {
if (typeof(object.run) == "function") {
if (object.eventOrphan) {
stopCount--;
}
object.eventOrphan = false;
var _local1 = 0;
while (_local1 < listeners.length) {
if (listeners[_local1] == object) {
return(undefined);
}
_local1++;
}
listeners.push(object);
} else {
wr("tried to run bad object!");
wrObj(object);
}
};
this.stopIt = function (object) {
var _local1 = 0;
while (_local1 < listeners.length) {
if (listeners[_local1] == object) {
stopCount++;
listeners[_local1].eventOrphan = true;
return(undefined);
}
_local1++;
}
};
onEnterFrame = function () {
if ((Key.isDown(16) && (Key.isDown(17))) && (dev_mode)) {
return(undefined);
}
var _local2 = listeners;
var _local1 = 0;
while (_local1 < _local2.length) {
if (!_local2[_local1].eventOrphan) {
_local2[_local1].run();
}
_local1++;
}
if (stopCount > 0) {
_local1 = 0;
while (_local1 < listeners.length) {
if (listeners[_local1].eventOrphan) {
listeners[_local1].eventOrphan = false;
listeners.splice(_local1, 1);
_local1--;
stopCount--;
}
_local1++;
}
}
};
}
function Sprites() {
var sprite_root = createEmptyMovieClip("sprite_root", 0);
var zRange = 500;
var zArray = new Array(zRange);
var _local2 = 0;
while (_local2 < zRange) {
zArray[_local2] = zRange - _local2;
_local2++;
}
this.getNumFree = function () {
return(zArray.length);
};
this.create = function (props) {
var _local4 = zArray.pop() + (zRange * 4);
var _local5 = "sp" + _local4;
var _local7 = (props.parent_sprite ? (props.parent_sprite) : (sprite_root));
var _local3;
if (typeof(props.member) == "string") {
_local3 = _local7.attachMovie(props.member, _local5, _local4);
} else {
_local3 = _local7.createEmptyMovieClip(_local5, _local4);
}
_local3._x = ((typeof(props.x) == "number") ? (props.x) : 0);
_local3._y = ((typeof(props.y) == "number") ? (props.y) : 0);
if (typeof(props.width) == "number") {
_local3._width = props.width;
}
if (typeof(props.height) == "number") {
_local3._height = props.height;
}
if (typeof(props.xscale) == "number") {
_local3._xscale = props.xscale;
}
if (typeof(props.yscale) == "number") {
_local3._yscale = props.yscale;
}
_local3._visible = ((typeof(props.visible) == "boolean") ? (props.visible) : true);
_local3._alpha = ((typeof(props.alpha) == "number") ? (props.alpha) : 100);
_local3.zIndex = _local4;
_local3.toLevel = function (_l) {
var _local3 = this.zIndex;
var _local2 = ((_l - 1) * zRange) + (this.zIndex % zRange);
this.swapDepths(_local2);
this.zIndex = _local2;
};
if (typeof(props.level) == "number") {
_local3.toLevel(props.level);
}
return(_local3);
};
this.remove = function (sprite) {
if (!sprite.zIndex) {
return(undefined);
}
var _local1 = sprite.zIndex % zRange;
sprite.removeMovieClip();
zArray.push(_local1);
return(_local1);
};
this.sort = function (sprite_array, descending) {
var _local2 = [];
var _local4 = sprite_array.length;
var _local1 = 0;
while (_local1 < _local4) {
_local2.push(sprite_array[_local1].getDepth());
_local1++;
}
if (descending) {
_local2.sort(Array.NUMERIC | Array.DESCENDING);
} else {
_local2.sort(Array.NUMERIC);
}
_local1 = 0;
while (_local1 < _local4) {
sprite_array[_local1].swapDepths(_local2[_local1]);
sprite_array[_local1].zIndex = _local2[_local1];
_local1++;
}
};
}
function SoundFx() {
var soundList = ["card_sound_2.aif", "card_sound_6.aif", "click_sound_2.aif", "click.wav", "game_over.aif", "game_win.aif", "next_round.aif", "stick.aif", "tone_a.aif", "tone_b.aif", "beep.wav", "slam.wav", "introSound", "outroSound", "attentionSound"];
var _local4 = createEmptyMovieClip("sound_fx_base", -1);
var _local5 = 0;
var sounds = new Object();
var silent = false;
var _local3 = 0;
while (_local3 < soundList.length) {
var _local2 = new Sound(_local4.createEmptyMovieClip("sound_" + (_local3 + 1), (-_local3) - 2));
_local2.attachSound(soundList[_local3]);
_local2.onSoundComplete = function () {
this.playing = false;
};
sounds[soundList[_local3]] = _local2;
sounds[soundList[_local3]].playing = false;
sounds[soundList[_local3]].soundName = soundList[_local3];
_local3++;
}
this.play = function (sound, nostop, vol) {
if (silent) {
return(undefined);
}
if (no_sound == 1) {
return(undefined);
}
if (sounds[sound].playing) {
if (nostop) {
return(undefined);
}
this.stop(sound);
}
sounds[sound].playing = true;
if (vol) {
sounds[sound].setVolume(vol);
} else {
sounds[sound].setVolume(100);
}
sounds[sound].start();
};
this.playLooped = function (sound, vol) {
if (no_sound == 1) {
return(undefined);
}
if (sounds[sound].playing) {
return(undefined);
}
sounds[sound].playing = true;
if (vol) {
sounds[sound].setVolume(vol);
} else {
sounds[sound].setVolume(100);
}
sounds[sound].start(0, 99);
};
this.stop = function (sound) {
sounds[sound].stop();
sounds[sound].playing = false;
};
this.soundOff = function () {
var _local1 = 0;
while (_local1 < soundList.length) {
sounds[soundList[_local1]].stop();
_local1++;
}
silent = true;
};
this.soundOn = function () {
silent = false;
};
}
function Random() {
var seed = 0;
var seed2 = 0;
this.range = function (start, stop) {
var _local2 = stop - start;
var _local1 = Math.random() * (_local2 + 1);
_local1 = Math.floor(start + _local1);
return(Math.min(_local1, stop));
};
this.setSeed = function (s) {
seed = s & 65535;
seed2 = seed;
};
this.rangeFromSeed = function (start, stop) {
var _local3 = stop - start;
var _local2 = this.floatFromSeed() * (_local3 + 1);
_local2 = Math.floor(start + _local2);
return(Math.min(_local2, stop));
};
this.rangeFromSeed2 = function (start, stop) {
var _local3 = stop - start;
var _local2 = this.floatFromSeed2() * (_local3 + 1);
_local2 = Math.floor(start + _local2);
return(Math.min(_local2, stop));
};
this.floatFromSeed = function () {
seed = ((seed * 732573) + 3545443) & 65535;
var _local1 = seed / 65536;
return(_local1);
};
this.floatFromSeed2 = function () {
seed2 = ((seed2 * 732573) + 3545443) & 65535;
var _local1 = seed2 / 65536;
return(_local1);
};
}
function wr() {
var _local3 = "> ";
var _local2 = 0;
while (_local2 < arguments.length) {
_local3 = _local3 + arguments[_local2];
_local2++;
if (arguments.length != _local2) {
_local3 = _local3 + " ";
}
}
trace(_local3);
if (netlog_wr) {
game.network.send_string(("LOG " + game.table.local_player.playernum) + _local3);
}
}
function wrObj(obj, rec) {
function wrObjDump(obj, rec, currprop) {
currprop = ((typeof(currprop) == "string") ? (currprop + ".") : "");
for (var _local4 in obj) {
trace(((currprop + _local4) + ": ") + obj[_local4]);
if (rec) {
if (typeof(obj[_local4]) == "object") {
wrObjDump(obj[_local4], rec, currprop + _local4);
}
}
}
}
trace("--- Obj dump: ---------");
wrObjDump(obj, rec);
trace("-----------------------");
}
function fill(width, p) {
var _local2 = "";
var _local3 = ((typeof(p) != "string") ? " " : (p));
var _local1 = 0;
while (_local1 < width) {
_local2 = _local2 + _local3;
_local1++;
}
return(_local2);
}
function parseArgString(argstr) {
var _local5 = [];
var _local2 = false;
var _local1 = "";
var _local3;
var _local4 = 0;
while (_local4 < argstr.length) {
_local3 = argstr.substr(_local4, 1);
if ((_local3 == "\"") && (!_local2)) {
_local2 = true;
} else if ((_local3 == " ") && (!_local2)) {
if (_local1 != "") {
_local5.push(_local1);
_local1 = "";
}
} else if ((_local3 == "\"") && (_local2)) {
_local2 = false;
_local5.push(_local1);
_local1 = "";
} else {
_local1 = _local1 + _local3;
}
_local4++;
}
if (_local1 != "") {
_local5.push(_local1);
}
return(_local5);
}
function GamedataObj(props) {
this.ready = false;
this.init = function (props) {
this.parent = props.parent;
events.runIt(this);
if (dev_mode) {
this.load_dev_xml();
}
};
this.run = function () {
if (gameData != undefined) {
this.parse_and_set(gameData);
events.stopIt(this);
}
};
this.parse_and_set = function (xmlstr) {
this.parse_gamedata(xmlstr);
this.ready = true;
this.parent.gamedata_loaded();
};
this.parse_gamedata = function (xmlstr) {
this.settings = {};
this.text = {};
this.mp = {};
var _local6 = new XML();
_local6.ignoreWhite = true;
_local6.parseXML(xmlstr);
var _local4 = _local6.firstChild.attributes;
for (var _local5 in _local4) {
this[_local5] = _local4[_local5];
}
var _local3 = _local6.firstChild.childNodes;
var _local2 = 0;
while (_local2 < _local3.length) {
if (_local3[_local2].nodeName == "text") {
this.text[_local3[_local2].attributes.id] = _local3[_local2].firstChild.nodeValue;
} else if (_local3[_local2].nodeName == "multiplayer") {
for (var _local5 in _local3[_local2].attributes) {
this.mp[_local5] = _local3[_local2].attributes[_local5];
}
} else if (_local3[_local2].nodeName == "settings") {
for (var _local5 in _local3[_local2].attributes) {
this.settings[_local5] = _local3[_local2].attributes[_local5];
}
}
_local2++;
}
};
this.load_dev_xml = function () {
var _local1 = new XML();
_local1.ignoreWhite = true;
_local1.onData = function (src) {
gameData = src;
};
_local1.load("xml/gamedata.xml");
};
this.init(props);
}
function Rules(props) {
var pass_directions = ["left", "right", "across", "none"];
var pass_increase_num = [1, 3, 2, 0];
var pass_direction_index = 0;
var players;
var local_player;
var current_playernum;
var current_round = 0;
var SLAM_SCORE = 26;
var SUPER_SLAM_SCORE = 52;
var no_players = 4;
var end_score = 100;
var game_over = false;
var cir_sent = false;
var start_player = 0;
var dealer_pnum = random.rangeFromSeed(0, no_players - 1);
var hearts_played = false;
var clubs_two_played = false;
var deal_count = 0;
var deal_rq_count = 0;
var trump_color = null;
var card_values = {};
card_values["2"] = 2;
card_values["3"] = 3;
card_values["4"] = 4;
card_values["5"] = 5;
card_values["6"] = 6;
card_values["7"] = 7;
card_values["8"] = 8;
card_values["9"] = 9;
card_values.T = 10;
card_values.J = 11;
card_values.Q = 12;
card_values.K = 13;
card_values.A = 14;
this.init = function (props) {
players = props.players_ref;
this.dealing = false;
current_playernum = start_player;
events.runIt(this);
};
this.get_pass_direction = function () {
return(pass_directions[pass_direction_index]);
};
this.get_slam_score = function () {
return(SLAM_SCORE);
};
this.get_super_slam_score = function () {
return(SUPER_SLAM_SCORE);
};
this.set_gamedata = function (gd) {
end_score = this.get_gamedata_int(gd.end_score, end_score);
};
this.get_gamedata_int = function (prop, defaultval) {
var _local1 = parseInt(prop);
return((isNaN(_local1) ? (defaultval) : (_local1)));
};
this.deal_cards = function (num, carddata) {
deal_count = deal_count + (carddata.length / 2);
players[num].deal_cards(carddata);
game.network.pause_incoming();
if (deal_count == 52) {
new Delay({callback:game.deal_done, callback_scope:game, seconds:0.8});
new Delay({callback:game.network.resume_incoming, callback_scope:game.network, seconds:1});
} else {
new Delay({callback:game.network.resume_incoming, callback_scope:game.network, frames:3});
}
};
this.check_card_legal = function (hand, card) {
var _local1 = true;
if (!clubs_two_played) {
if ((card.color != "C") || (card.value != 2)) {
wr(card.color, card.value, "is not legal");
_local1 = false;
}
}
if (game.table.pile.get_size() == 0) {
if ((card.color == "H") && (!hearts_played)) {
if (((hand.color_counts.C + hand.color_counts.S) + hand.color_counts.D) > 0) {
_local1 = false;
}
}
} else if (game.table.pile.get_color() != card.color) {
if (hand.color_counts[game.table.pile.get_color()] != 0) {
_local1 = false;
}
}
return(_local1);
};
this.card_clicked = function (hand, card) {
if (local_player.playernum != current_playernum) {
return(false);
}
wr("rules.card_clicked() legal:", this.check_card_legal(hand, card));
if (!this.check_card_legal(hand, card)) {
return(false);
}
var _local4 = hand.get_card_index(card);
hand.release_card(card);
card.playernum_sequence = current_playernum;
game.table.pile.add_card(card, hand.parent);
if (card.color == "H") {
hearts_played = true;
}
if ((card.color == "C") && (card.value == 2)) {
clubs_two_played = true;
}
game.network.send_string(((((("GPC " + local_player.playernum) + ",") + _local4) + ",") + card.value) + card.color);
this.check_trick();
return(true);
};
this.play_opponent_card = function (pnum, card_index, cardstr) {
var _local3 = players[pnum].hand;
var _local2 = _local3.get_card_by_index(card_index);
var _local7 = _local2.color;
var _local5 = _local2.value;
var _local6 = _local3.get_card_by_col_val(cardstr.charAt(1), cardstr.charAt(0));
_local6.setCard({color:_local7, value:_local5});
_local2.setCard({color:cardstr.charAt(1), value:cardstr.charAt(0)});
_local3.release_card(_local2);
_local2.switchSide();
_local2.playernum_sequence = current_playernum;
game.table.pile.add_card(_local2, _local3.parent);
if (_local2.color == "H") {
hearts_played = true;
}
if ((_local2.color == "C") && (_local2.value == 2)) {
clubs_two_played = true;
}
this.check_trick();
game.network.pause_incoming();
new Delay({callback:game.network.resume_incoming, callback_scope:game.network, seconds:0.2});
};
this.check_trick = function () {
var _local2 = game.table.pile;
if (_local2.get_size() == players.length) {
this.build_trick();
if (local_player.hand.get_no_cards() == 0) {
this.end_round();
}
return(undefined);
}
this.next_player();
};
this.build_trick = function () {
var _local12 = [];
var _local14 = game.table.pile;
var _local5 = _local14.get_cards();
_local14.purge();
var _local7 = -1;
var _local11 = -1;
var _local13 = _local5[0].color;
var _local6 = 0;
var _local3 = 0;
while (_local3 < _local5.length) {
var _local4 = 0;
var _local2 = _local5[_local3];
if (_local2.color == _local13) {
_local4 = _local4 + card_values[_local2.value];
}
if (_local2.color == "H") {
_local6 = _local6 + 1;
}
if ((_local2.color == "S") && (_local2.value == "Q")) {
_local6 = _local6 + 13;
}
var _local10 = players[_local2.playernum_sequence].seatnum;
_local12.push({seat:_local10, value:_local2.value, color:_local2.color});
if (_local4 > _local7) {
_local7 = _local4;
_local11 = _local2.playernum_sequence;
}
_local3++;
}
var _local15 = _local11;
var win_p = players[_local15];
win_p.level_score = win_p.level_score + _local6;
win_p.add_trick(_local5, _local6);
win_p.num_visual_tricks++;
var _local16 = function () {
var _local2 = 0;
while (_local2 < players.length) {
game.gui.set_player_score(players[_local2].playernum, players[_local2].level_score, players[_local2].score);
_local2++;
}
game.gui.set_lasttrick(this.t);
game.gui.set_player_tricks(win_p);
if (game.table.local_player == win_p) {
soundFx.play("stick.aif");
}
};
new Delay({seconds:1.4, callback:_local16, callback_scope:{p:players[_local15], t:_local12, wp:win_p}});
this.next_player(_local11, 0.6);
};
this.start_game = function () {
wr("rules.start_game()");
current_round = 0;
var _local2 = 0;
while (_local2 < 4) {
players[_local2].sequencenum = _local2;
_local2++;
}
_local2 = 0;
while (_local2 < players.length) {
var _local3 = ((players[_local2].sequencenum - local_player.sequencenum) + players.length) % players.length;
players[_local2].set_seatnum(_local3);
_local2++;
}
this.prepare_round();
};
this.prepare_round = function () {
current_round++;
game.gui.time_box.round.text = (game.gamedata.text.round + " ") + current_round;
var _local1 = 0;
while (_local1 < players.length) {
players[_local1].level_score = 0;
players[pnum].sent_cards = false;
game.gui.set_player_score(players[_local1].playernum, players[_local1].level_score, players[_local1].score);
_local1++;
}
};
this.start_round = function () {
this.set_start_player();
current_playernum = start_player;
players[current_playernum].enable();
game.start_round();
};
this.end_round = function () {
pass_direction_index = (pass_direction_index + 1) % pass_increase_num.length;
deal_count = 0;
deal_rq_count = 0;
hearts_played = false;
clubs_two_played = false;
var _local2 = 0;
while (_local2 < players.length) {
players[_local2].ready_for_round = false;
players[_local2].sent_cards = false;
_local2++;
}
dealer_pnum = (dealer_pnum + 1) % no_players;
_local2 = 0;
while (_local2 < players.length) {
if (players[_local2].level_score == 26) {
if (players[_local2].local) {
if (players[_local2].tricks.length == 13) {
new Delay({seconds:2, callback:game.gui.show_super_slambox, callback_scope:game.gui});
} else {
new Delay({seconds:2, callback:game.gui.show_slambox, callback_scope:game.gui});
}
} else {
if (players[_local2].tricks.length == 13) {
new Delay({seconds:1.5, callback:game.gui.show_opponent_super_slambox, callback_scope:game.gui});
} else {
new Delay({seconds:1.5, callback:game.gui.show_opponent_slambox, callback_scope:game.gui});
}
if (players[_local2].ai_player) {
players[_local2].ai_player.select_slam();
}
}
return(undefined);
}
_local2++;
}
this.slambox_done(false);
};
this.slambox_clicked = function (punish_opponents) {
game.network.send_string((("GSS " + local_player.playernum) + ",") + (punish_opponents ? 1 : 0));
this.slambox_done(punish_opponents);
};
this.slambox_done = function (punish_opponents) {
wr("rules.slambox_done punish_opponents = ", punish_opponents);
var _local4 = 0;
while (_local4 < players.length) {
if (players[_local4].level_score == 26) {
var _local3 = ((players[_local4].tricks.length == 13) ? 52 : 26);
var _local2 = 0;
while (_local2 < players.length) {
if (punish_opponents) {
players[_local2].level_score = ((_local4 == _local2) ? 0 : (_local3));
} else {
players[_local2].level_score = ((_local4 == _local2) ? (-_local3) : 0);
}
_local2++;
}
break;
}
_local4++;
}
_local4 = 0;
while (_local4 < players.length) {
var _local5 = players[_local4];
_local5.score = _local5.score + _local5.level_score;
_local4++;
}
var _local7 = false;
_local4 = 0;
while (_local4 < players.length) {
_local7 = _local7 | (players[_local4].score > end_score);
_local4++;
}
if (_local7) {
this.set_game_over();
}
game.end_round();
};
this.get_round_localwinner = function () {
var _local2 = 1000;
var _local1 = 0;
while (_local1 < players.length) {
_local2 = Math.min(_local2, players[_local1].score);
_local1++;
}
var _local3 = _local2 == local_player.score;
return(_local3);
};
this.set_game_over = function () {
game_over = true;
local_player.winner = this.get_round_localwinner();
var _local2 = 0;
while (_local2 < players.length) {
players[_local2].ready_for_round = false;
_local2++;
}
game.set_game_over();
};
this.get_game_over = function () {
return(game_over);
};
this.localplayer_next_round = function () {
wr("rules.localplayer_next_round()");
game.network.send_string("GNR " + local_player.playernum);
this.player_next_round(local_player.playernum);
var _local2 = 0;
while (_local2 < players.length) {
if (players[_local2].ai_player) {
if (!players[_local2].ready_for_round) {
players[_local2].ai_player.send_next_round();
}
}
_local2++;
}
};
this.player_next_round = function (playernum) {
wr("rules.player_next_round()", playernum);
players[playernum].ready_for_round = true;
game.table.players[playernum].avatar.avatar_sprite._visible = true;
var _local3 = true;
var _local2 = 0;
while (_local2 < players.length) {
_local3 = _local3 & players[_local2].ready_for_round;
_local2++;
}
if (_local3) {
this.prepare_round();
game.table.next_round();
this.request_deal();
}
};
this.next_player = function (requested_suequence_number, next_player_delay) {
wr("rules.next_player");
players[current_playernum].disable();
if (typeof(requested_suequence_number) == "number") {
current_playernum = requested_suequence_number;
} else {
current_playernum = (current_playernum + 1) % no_players;
}
if (typeof(next_player_delay) == "number") {
new Delay({seconds:next_player_delay, callback:this.enable_current_player, callback_scope:this});
} else {
new Delay({seconds:0.5, callback:this.enable_current_player, callback_scope:this});
}
};
this.enable_current_player = function () {
players[current_playernum].enable();
};
this.add_local_player = function (pobj) {
var _local1 = game.table.add_local_player(pobj);
_local1.round_score = 0;
_local1.level_score = 0;
local_player = _local1;
};
this.add_remote_player = function (pobj) {
var _local1 = game.table.add_remote_player(pobj);
_local1.player_sequence_number = _local1.playernum;
_local1.round_score = 0;
_local1.level_score = 0;
};
this.run = function () {
if (this.dealing) {
this.deal_a_card();
}
};
this.request_deal = function () {
wr("request_deal");
var _local2 = 0;
while (_local2 < players.length) {
players[_local2].ready_for_round = true;
_local2++;
}
players[0].set_dealer(true);
var _local3 = local_player.dealer;
if (local_player.playernum != 0) {
_local3 = players[0].ai_player != null;
}
if (_local3) {
game.network.send_string("JRD");
deal_rq_count = 0;
this.dealing = true;
}
};
this.deal_a_card = function () {
if (deal_rq_count == 52) {
this.dealing = false;
return(undefined);
}
var _local2 = (start_player + deal_rq_count) % no_players;
var _local3 = _local2;
game.network.send_string((("JRC " + _local3) + ",") + 1);
deal_rq_count = deal_rq_count + 1;
};
this.check_continue_deal = function () {
if (this.dealing) {
return(undefined);
}
wr("rules.check_continue_deal()");
var _local2 = 1;
while (_local2 < players.length) {
if (!players[_local2].ready_for_round) {
return(false);
}
_local2++;
}
wr("deal_count:", deal_count);
if (deal_count == 52) {
return(false);
}
var _local3 = 52 - deal_count;
if (_local3 == 52) {
game.network.send_string("JRD");
}
deal_rq_count = deal_count;
this.dealing = true;
return(true);
};
this.send_cir = function () {
if (!cir_sent) {
game.network.send_string("CIR");
cir_sent = true;
}
};
this.start_send_cards = function () {
current_playernum = start_player;
var _local1 = 0;
while (_local1 < players.length) {
players[_local1].send_cards_active = true;
if (players[_local1].ai_player) {
players[_local1].ai_player.send_cards();
}
_local1++;
}
};
this.start_without_send_cards = function () {
current_playernum = start_player;
local_player.hand.show_cards();
var _local2 = 2;
new Delay({seconds:_local2, callback:this.start_round, callback_scope:this});
game.network.pause_incoming();
new Delay({seconds:_local2 + 0.5, callback:game.network.resume_incoming, callback_scope:game.network});
};
this.localplayer_send_cards = function (cards) {
wr("localplayer_send_cards");
game.network.send_string("GSC " + local_player.playernum);
this.player_sent_cards(local_player.playernum);
var _local2 = 0;
while (_local2 < players.length) {
if ((!players[_local2].sent_cards) && (players[_local2].ai_player)) {
players[_local2].ai_player.send_cards();
}
_local2++;
}
};
this.player_sent_cards = function (pnum) {
wr("player_sent_cards from pnum =", pnum);
var _local3 = players[pnum];
players[i].send_cards_active = false;
var _local4 = [];
_local3.sent_cards = true;
var i = (_local3.hand.cards.length - 1);
while (i >= 0) {
if (_local3.hand.cards[i].selected) {
var _local2 = _local3.hand.cards[i];
_local2.selected = false;
_local3.hand.release_card(_local2);
_local2.set_parent(_local4);
_local4.push(_local2);
}
i--;
}
_local3.sendcards = _local4;
game.gui.rest_cards_to_send(_local3.sendcards, _local3.seatnum);
_local3.hand.resort();
var _local5 = this.check_send_cards();
if (_local5) {
this.distribute_sent_cards();
wr("got bet - now all players have sent cards - return");
return(undefined);
}
};
this.localplayer_choose_card = function (c) {
game.network.send_string(((("GCC " + local_player.playernum) + ",") + c.value) + c.color);
};
this.opponent_chose_card = function (pnum, card_str) {
wr("rules.opponent_chose_card()", pnum, card_str);
players[pnum].select_card(card_str.charAt(0), card_str.charAt(1));
};
this.check_send_cards = function () {
var _local2 = true;
var _local1 = 0;
while (_local1 < players.length) {
_local2 = _local2 & players[_local1].sent_cards;
_local1++;
}
if (_local2) {
return(1);
}
return(0);
};
this.set_start_player = function () {
var _local4 = 1;
var _local1 = 0;
while (_local1 < players.length) {
var _local2 = 0;
while (_local2 < players[_local1].hand.cards.length) {
var _local3 = players[_local1].hand.cards[_local2];
if ((_local3.color == "C") && (_local3.value == 2)) {
wr("found C2 at player", _local1);
current_playernum = (start_player = _local1);
return(undefined);
}
_local2++;
}
_local1++;
}
};
this.distribute_sent_cards = function () {
wr("distribute_sent_cards");
var _local4 = 1;
var _local3 = 0;
while (_local3 < players.length) {
var _local2 = players[_local3];
_local2.send_to_player = players[(_local2.playernum + pass_increase_num[pass_direction_index]) % players.length];
new Delay({seconds:_local4, callback:_local2.give_sendcards, callback_scope:_local2});
wr(" from player", _local3, "to player", _local2.send_to_player.playernum);
_local4 = _local4 + 0.5;
_local3++;
}
new Delay({seconds:_local4, callback:this.start_round, callback_scope:this});
game.network.pause_incoming();
new Delay({seconds:_local4 + 0.5, callback:game.network.resume_incoming, callback_scope:game.network});
};
this.get_trump_color = function () {
return(trump_color);
};
this.get_teamscore = function () {
return(this.team_score);
};
this.get_current_round = function () {
return(current_round);
};
this.get_start_player = function () {
return(start_player);
};
this.get_start_player_num = function () {
return(start_player);
};
this.get_deal_seatnum = function () {
return(players[((dealer_pnum + no_players) - 1) % no_players].seatnum);
};
this.get_no_players = function () {
return(no_players);
};
this.get_current_playernum = function () {
return(current_playernum);
};
this.get_card_value = function (_char) {
return(card_values[_char]);
};
this.get_local_playernum = function () {
return(local_player.playernum);
};
this.init(props);
}
function Gui(props) {
this.state = "startup";
this.player_count = 0;
this.player_boxes = [];
this.halos = [];
this.player_positions = [];
this.avatar_positions = [];
this.halo_positions = [];
this.score_avatar_pos = [];
this.instr_avatar_pos = [];
this.chatbubble_positions = [];
this.other_positions = {};
this.scoreboard_timer = null;
this.cardbox_timer = null;
this.CARDBOX_TIMER_DURATION = 15;
this.SLAMBOX_TIMER_DURATION = 10;
this.SCOREBOARD_TIMER_DURATION = 10;
this.lasttrick_viewed = false;
this.init = function (props) {
this.parent = props.parent;
this.ph = sprites.create({member:"placeholders_gui", visible:false});
var _local2;
var _local3 = 0;
while (_local3 < 4) {
_local2 = this.ph["player" + _local3];
this.player_positions.push([_local2._x, _local2._y, _local2._xscale, _local2._yscale]);
_local2 = this.ph["avatar" + _local3];
this.avatar_positions.push([_local2._x, _local2._y, _local2._xscale, _local2._yscale]);
_local2 = this.ph["chat" + _local3];
this.chatbubble_positions.push([_local2._x, _local2._y, _local2._xscale, _local2._yscale]);
_local2 = this.ph["halo" + _local3];
this.halo_positions.push([_local2._x, _local2._y, _local2._xscale, _local2._yscale]);
_local3++;
}
_local2 = this.ph.emoticons;
this.other_positions.emoticons = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.hourglass;
this.other_positions.hourglass = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.score_board;
this.other_positions.score_board = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.chat_icon;
this.other_positions.chat_icon = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.chat_box;
this.other_positions.chat_box = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.lasttrick_panel;
this.other_positions.lasttrick_panel = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.time_box;
this.other_positions.time_box = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.score_box;
this.other_positions.score_box = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.pass_cards_box;
this.other_positions.card_box = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.slam_box;
this.other_positions.slam_box = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.logo;
this.other_positions.logo = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local3 = 0;
while (_local3 < 4) {
_local2 = this.ph["score_avatar" + _local3];
this.score_avatar_pos.push([_local2._x, _local2._y, _local2._xscale, _local2._yscale]);
_local3++;
}
sprites.remove(this.ph);
this.ph = sprites.create({member:"placeholders_instructions", visible:false});
_local2 = this.ph.instructions;
this.other_positions.instructions = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local2 = this.ph.statusbox;
this.other_positions.statusbox = [_local2._x, _local2._y, _local2._xscale, _local2._yscale];
_local3 = 0;
while (_local3 < 4) {
_local2 = this.ph["avatar" + _local3];
this.instr_avatar_pos.push([_local2._x, _local2._y, _local2._xscale, _local2._yscale]);
_local3++;
}
sprites.remove(this.ph);
this.bg = sprites.create({member:"bg_main", x:0, y:0, level:1});
this.bg_dark_plate = sprites.create({member:"bg_dark_plate", x:0, y:0, visible:false, level:15});
this.lasttrick_panel = sprites.create({member:"lasttrick_panel", x:this.other_positions.lasttrick_panel[0], y:this.other_positions.lasttrick_panel[1], visible:false, level:10});
this.score_box = sprites.create({member:"score_box", x:this.other_positions.score_box[0], y:this.other_positions.score_box[1], visible:false, level:10});
this.time_box = sprites.create({member:"time_box", x:this.other_positions.time_box[0], y:this.other_positions.time_box[1], visible:false, level:10});
this.logo = sprites.create({member:"logo", x:this.other_positions.logo[0], y:this.other_positions.logo[1], visible:false, level:4});
this.scoreboard = sprites.create({member:"score_board", x:this.other_positions.score_board[0], y:this.other_positions.score_board[1], visible:false, level:17});
this.scoreboard.active = false;
var _local4 = function () {
game.gui.click_scoreboard();
};
this.scoreboard_timer = new Timer({duration:this.SCOREBOARD_TIMER_DURATION, textref:this.scoreboard.next_round_counter, cb:_local4, format:"sec"});
this.cardbox = sprites.create({member:"pass_cards_box", x:this.other_positions.card_box[0], y:this.other_positions.card_box[1], level:7});
this.cardbox.active = false;
this.cardbox._visible = false;
var _local6 = function () {
game.gui.autoselect_cardbox();
};
this.cardbox_timer = new Timer({duration:this.CARDBOX_TIMER_DURATION, textref:this.cardbox.counter, cb:_local6, format:"sec"});
this.slambox = sprites.create({member:"slam_box", x:this.other_positions.slam_box[0], y:this.other_positions.slam_box[1], level:9});
this.slambox.active = false;
this.slambox._visible = false;
var _local5 = function () {
game.gui.autoselect_slambox();
};
this.slambox_timer = new Timer({duration:this.SLAMBOX_TIMER_DURATION, textref:this.slambox.counter, cb:_local5, format:"sec"});
this.opponent_slambox = sprites.create({member:"opponent_slam_box", x:this.other_positions.slam_box[0], y:this.other_positions.slam_box[1], level:9});
this.opponent_slambox.active = false;
this.opponent_slambox._visible = false;
this.hourglass = new HourGlass({x:this.other_positions.hourglass[0], y:this.other_positions.hourglass[1], scale:this.other_positions.hourglass[2]});
this.chat = new ChatClient({positions:this.other_positions});
this.alertbox = sprites.create({member:"alertbox", x:0, y:0, visible:false, level:22});
this.alertbox.active = false;
this.alertbox._x = (props.parent.width * 0.5) - (this.alertbox._width / 2);
this.alertbox._y = (props.parent.height * 0.43) - (this.alertbox._height / 2);
this.alertbox.tween_obj = new Tween();
};
this.set_gamedata = function (gamedata) {
var _local2 = gamedata.text.chat_to_fast;
_local2 = (((_local2 == undefined) || (_local2 == "")) ? "Please wait before sending more text." : (_local2));
this.chat.set_chat_to_fast_msg(_local2);
this.CARDBOX_TIMER_DURATION = this.getValueFromXML("cardboxtimer", this.CARDBOX_TIMER_DURATION);
this.SLAMBOX_TIMER_DURATION = this.getValueFromXML("slamboxtimer", this.SLAMBOX_TIMER_DURATION);
this.SCOREBOARD_TIMER_DURATION = this.getValueFromXML("scoreboardtimer", this.SCOREBOARD_TIMER_DURATION);
};
this.getValueFromXML = function (xmlIdentifier, atimer) {
var _local1 = parseInt(game.gamedata[xmlIdentifier]);
if (isNaN(_local1) || (_local1 == 0)) {
wr("xmlvalue not found leaving default");
return(atimer);
}
wr("returning xmlvalue for", xmlIdentifier);
return(_local1);
};
this.show_instructions = function () {
this.instructions = sprites.create({member:"instructions", x:this.other_positions.instructions[0], y:this.other_positions.instructions[1]});
this.instructions.active = true;
this.instructions.header.text = game.gamedata.text.instruction_header.toUpperCase();
this.instructions.start_btn_text.text = game.gamedata.text.start_btn_text.toUpperCase();
this.instructions.h1.text = game.gamedata.text.instruction_h1.toUpperCase();
this.instructions.t1.text = game.gamedata.text.instruction_t1;
this.instructions.h2.text = game.gamedata.text.instruction_h2.toUpperCase();
this.instructions.t2.text = game.gamedata.text.instruction_t2;
this.instructions.h3.text = game.gamedata.text.instruction_h3.toUpperCase();
this.instructions.t3.text = game.gamedata.text.instruction_t3;
this.instructions.h4.text = game.gamedata.text.instruction_h4.toUpperCase();
this.instructions.t4.text = game.gamedata.text.instruction_t4;
this.instructions.tween_obj = new Tween();
var _local2 = [{sprite:this.instructions, from:{_alpha:0, _xscale:70, _yscale:70, _x:this.other_positions.instructions[0] + (this.instructions._width * 0.15), _y:this.other_positions.instructions[1] + (this.instructions._height * 0.15)}, to:{_alpha:100, _xscale:100, _yscale:100, _x:this.other_positions.instructions[0], _y:this.other_positions.instructions[1]}}];
this.instructions.tween_obj.go(_local2, {duration:300});
this.instructions.onRelease = function () {
game.gui.click_instructions();
};
soundFx.play("introSound");
};
this.click_instructions = function () {
if (!this.instructions.active) {
return(undefined);
}
this.instructions.active = false;
delete this.instructions.onRelease;
this.hide_instructions();
this.slide_up_statusbox();
game.network.pause_incoming();
new Delay({seconds:0.6, callback:game.network.resume_incoming, callback_scope:game.network});
game.rules.send_cir();
soundFx.play("click.wav", false, 80);
};
this.hide_instructions = function () {
var _local2 = [{sprite:this.instructions, from:{_alpha:100, _xscale:100, _yscale:100, _x:this.other_positions.instructions[0], _y:this.other_positions.instructions[1]}, to:{_alpha:0, _xscale:70, _yscale:70, _x:this.other_positions.instructions[0] + (this.instructions._width * 0.15), _y:this.other_positions.instructions[1] + (this.instructions._height * 0.15)}}];
this.instructions.tween_obj.go(_local2, {duration:200});
soundFx.stop("introSound");
};
this.show_cardbox = function () {
this.cardbox.cards = [0, 0, 0];
this.cardbox.no_sel_cards = 0;
this.cardbox.header.text = game.gamedata.text.send_cards_header;
this.cardbox.btn_sp = this.cardbox.btn_send;
var _local6 = game.rules.get_pass_direction();
var _local4 = game.gamedata.text[_local6];
this.cardbox.btn_sp.msg.text = _local4;
var _local2 = new ClickButton({sp:this.cardbox.btn_sp, id:"send_cards", callback:this.click_cardbox, callback_scope:this});
this.cardbox.btn_sp.btn_obj = _local2;
_local2.disable();
this.cardbox.btn_sp._alpha = 50;
this.cardbox.doAction = function (card, x) {
game.gui.remove_card_from_cardbox(card, x);
};
this.cardbox.tween_obj = new Tween();
var _local5 = [{sprite:this.cardbox, from:{_alpha:0, _xscale:70, _yscale:70}, to:{_alpha:100, _xscale:100, _yscale:100}}];
this.cardbox._visible = true;
this.cardbox.active = true;
this.cardbox.running = false;
var _local3 = function () {
game.table.players[game.rules.get_local_playernum()].show_cards();
game.table.players[game.rules.get_local_playernum()].hand.enable();
};
this.cardbox.tween_obj.go(_local5, {duration:300, callback:_local3, callback_scope:this});
};
this.click_cardbox = function (id) {
this.stop_cardbox();
this.cardbox.btn_sp.btn_obj.disable();
var _local2 = 0;
while (_local2 < this.cardbox.cards.length) {
this.cardbox.cards.deactivate_click();
_local2++;
}
game.table.local_player.hand.disable();
game.rules.localplayer_send_cards();
game.table.local_player.sendcards = this.cardbox.cards;
this.hide_cardbox();
this.rest_cards_to_send(this.cardbox.cards, game.table.local_player.seatnum);
soundFx.play("click.wav", false, 80);
};
this.hide_cardbox = function () {
this.cardbox.active = false;
var _local2 = [{sprite:this.cardbox, to:{_alpha:0, _xscale:70, _yscale:70}, from:{_alpha:100, _xscale:100, _yscale:100}}];
this.cardbox.tween_obj.go(_local2, {duration:200});
};
this.start_cardbox = function () {
if (this.cardbox.running) {
return(undefined);
}
this.cardbox.running = true;
this.cardbox_timer.init({duration:this.CARDBOX_TIMER_DURATION});
this.cardbox_timer.startTimer();
soundFx.play("next_round.aif");
};
this.stop_cardbox = function () {
if (!this.cardbox.running) {
return(undefined);
}
this.cardbox.running = false;
this.cardbox_timer.stopTimer();
};
this.autoselect_cardbox = function () {
soundFx.play("click.wav", false, 80);
if (this.cardbox.no_sel_cards != this.cardbox.cards.length) {
var _local2 = 0;
while (_local2 < this.cardbox.cards.length) {
if (this.cardbox.cards[_local2] == 0) {
var _local3 = game.table.local_player.hand.get_random_card();
this.add_card_to_cardbox(_local3);
}
_local2++;
}
}
this.click_cardbox();
};
this.remove_card_from_cardbox = function (card, x) {
var _local2 = 0;
while (_local2 < this.cardbox.cards.length) {
if (this.cardbox.cards[_local2] == card) {
this.cardbox.cards[_local2] = 0;
this.cardbox.no_sel_cards--;
game.table.local_player.hand.add_card_from_cardbox(card);
game.rules.localplayer_choose_card(card);
soundFx.play("click.wav", false, 80);
break;
}
_local2++;
}
this.cardbox.btn_sp.btn_obj.disable();
this.cardbox.btn_sp._alpha = 50;
};
this.add_card_to_cardbox = function (card) {
if (this.cardbox.no_sel_cards == this.cardbox.cards.length) {
soundFx.play("beep.wav", false, 80);
return(undefined);
}
game.table.local_player.hand.release_card(card);
card.set_parent(this.cardbox);
card.activate_click();
game.rules.localplayer_choose_card(card);
var _local2 = 0;
while (_local2 < this.cardbox.cards.length) {
if (this.cardbox.cards[_local2] == 0) {
this.cardbox.no_sel_cards++;
this.cardbox.cards[_local2] = card;
var _local4 = this.cardbox._x + this.cardbox["sendcard" + _local2]._x;
var _local3 = this.cardbox._y + this.cardbox["sendcard" + _local2]._y;
card.move_to({x:_local4, y:_local3, v:0, scale:70});
game.table.local_player.hand.resort();
soundFx.play("click.wav", false, 80);
break;
}
_local2++;
}
if (this.cardbox.no_sel_cards == this.cardbox.cards.length) {
this.cardbox.btn_sp.btn_obj.enable();
this.cardbox.btn_sp._alpha = 100;
}
};
this.is_cardbox_active = function () {
return(this.cardbox.active);
};
this.rest_cards_to_send = function (cards, seatnum) {
var _local1 = 0;
while (_local1 < cards.length) {
if (game.table.local_player.seatnum == seatnum) {
soundFx.play("card_sound_6.aif", false, 80);
cards[_local1].deactivate_click();
cards[_local1].setTurnedUp(false);
cards[_local1].animate_to({x:game.table.pass_positions[seatnum][0], y:game.table.pass_positions[seatnum][1], v:(game.table.deck_positions[seatnum][2] + ((_local1 - 1) * 12)) - 4, scale:game.table.pass_positions[seatnum][3], cb:cback, cb_scope:cards[_local1]});
} else {
soundFx.play("card_sound_6.aif", false, 80);
cards[_local1].toLevel(3);
cards[_local1].animate_to({x:game.table.pass_positions[seatnum][0], y:game.table.pass_positions[seatnum][1], scale:game.table.pass_positions[seatnum][3], cb:cback, cb_scope:cards[_local1]});
}
_local1++;
}
};
this.show_super_slambox = function () {
this.show_slambox(true);
};
this.show_slambox = function (_super) {
this.slambox_timer.init({duration:this.SLAMBOX_TIMER_DURATION});
this.slambox_timer.startTimer();
soundFx.play("slam.wav", false, 80);
var _local5 = (_super ? (game.gamedata.text.slambox_header_superslam) : (game.gamedata.text.slambox_header_slam));
var _local3 = (_super ? (game.gamedata.text.slam_desc_superslam) : (game.gamedata.text.slam_desc_slam));
var _local2 = (_super ? (game.rules.get_super_slam_score()) : (game.rules.get_slam_score()));
this.slambox.header.text = _local5;
this.slambox.desc.text = ((((game.gamedata.text.slam_desc1 + _local2) + game.gamedata.text.slam_desc2) + _local2) + game.gamedata.text.slam_desc3) + _local3;
this.slambox.btn1_sp = this.slambox.slam1;
this.slambox.btn2_sp = this.slambox.slam2;
this.slambox.btn1_sp.msg.text = game.gamedata.text.btn_self;
this.slambox.btn2_sp.msg.text = game.gamedata.text.btn_others;
var _local4 = new ClickButton({sp:this.slambox.btn1_sp, id:"1", callback:this.click_slambox, callback_scope:this});
this.slambox.btn1_sp.btn_obj = _local4;
_local4 = new ClickButton({sp:this.slambox.btn2_sp, id:"2", callback:this.click_slambox, callback_scope:this});
this.slambox.btn2_sp.btn_obj = _local4;
this.slambox.tween_obj = new Tween();
var _local7 = [{sprite:this.slambox, from:{_alpha:0, _xscale:70, _yscale:70}, to:{_alpha:100, _xscale:100, _yscale:100}}];
this.slambox._visible = true;
this.slambox.active = true;
this.slambox.running = true;
this.slambox.tween_obj.go(_local7, {duration:300});
};
this.hide_slambox = function () {
this.slambox.active = false;
var _local2 = [{sprite:this.slambox, to:{_alpha:0, _xscale:70, _yscale:70}, from:{_alpha:100, _xscale:100, _yscale:100}}];
this.slambox.tween_obj.go(_local2, {duration:200});
};
this.click_slambox = function (id) {
this.slambox.btn1_sp.btn_obj.disable();
this.slambox.btn1_sp.btn_obj.disable();
this.slambox_timer.stopTimer();
if (id == "1") {
game.rules.slambox_clicked(false);
} else if (id == "2") {
game.rules.slambox_clicked(true);
}
this.hide_slambox();
soundFx.play("click.wav", false, 80);
};
this.autoselect_slambox = function () {
soundFx.play("click.wav", false, 80);
var _local2 = random.rangeFromSeed(1, 2);
this.click_slambox(_local2);
};
this.show_opponent_super_slambox = function () {
this.show_opponent_slambox(true);
};
this.show_opponent_slambox = function (_super) {
soundFx.play("slam.wav", false, 80);
var _local2 = (_super ? (game.gamedata.text.opponent_slambox_header_superslam) : (game.gamedata.text.opponent_slambox_header_slam));
this.opponent_slambox.header.text = _local2;
this.opponent_slambox.desc.text = game.gamedata.text.opponent_slam_desc;
this.opponent_slambox.tween_obj = new Tween();
var _local3 = [{sprite:this.opponent_slambox, from:{_alpha:0, _xscale:70, _yscale:70}, to:{_alpha:100, _xscale:100, _yscale:100}}];
this.opponent_slambox._visible = true;
this.opponent_slambox.active = true;
this.opponent_slambox.tween_obj.go(_local3, {duration:300});
};
this.hide_opponent_slambox = function () {
this.opponent_slambox.active = false;
var _local2 = [{sprite:this.opponent_slambox, to:{_alpha:0, _xscale:70, _yscale:70}, from:{_alpha:100, _xscale:100, _yscale:100}}];
this.opponent_slambox.tween_obj.go(_local2, {duration:200});
};
this.hide_lasttrick = function () {
var _local2 = [{sprite:this.lasttrick_panel.fade, to:{_y:-100}, from:{_y:this.lasttrick_panel.fade._y}}, {sprite:this.lasttrick_panel.minicards, to:{_y:-100}, from:{_y:this.lasttrick_panel.minicards._y}}];
this.lasttrick_panel.tween_obj.go(_local2, {duration:200});
this.lasttrick_panel.bg.gotoAndPlay(1);
this.lasttrick_panel.is_showing = false;
};
this.show_lasttrick = function () {
var _local2 = [{sprite:this.lasttrick_panel.fade, from:{_y:this.lasttrick_panel.fade._y}, to:{_y:9}}, {sprite:this.lasttrick_panel.minicards, from:{_y:this.lasttrick_panel.minicards._y}, to:{_y:44}}];
this.lasttrick_panel.tween_obj.go(_local2, {duration:200});
this.lasttrick_panel.bg.gotoAndPlay(2);
this.lasttrick_panel.is_showing = true;
};
this.show_table = function () {
var _local3 = game.gamedata.text.totaltime;
this.stopwatch = new Stopwatch({textref:this.time_box.totaltime, text:_local3});
this.stopwatch.start();
this.time_box.round.text = (game.gamedata.text.round + " ") + 1;
this.score_box.score.text = game.gamedata.text.score;
var _local2 = 0;
while (_local2 < 4) {
this.set_player_score(_local2, 0, 0);
_local2++;
}
this.lasttrick_panel.lasttrick.text = game.gamedata.text.lasttrick;
this.lasttrick_panel.minicards._visible = false;
this.lasttrick_panel.tween_obj = new Tween();
this.lasttrick_panel.is_showing = false;
this.lasttrick_panel.onRelease = function () {
soundFx.play("click.wav", false, 80);
if (game.gui.lasttrick_panel.is_showing) {
game.gui.hide_lasttrick();
} else {
game.gui.show_lasttrick();
}
};
var _local5 = new Tween();
var _local4 = [{to:{_alpha:100}, from:{_alpha:0}, sprite:this.lasttrick_panel}, {to:{_alpha:100}, from:{_alpha:0}, sprite:this.score_box}, {to:{_alpha:100}, from:{_alpha:0}, sprite:this.time_box}, {to:{_alpha:100}, from:{_alpha:0}, sprite:this.logo}];
_local5.go(_local4, {duration:300, callback:this.show_playerboxes, callback_scope:this});
};
this.set_lasttrick = function (sortedTricks) {
this.lasttrick_panel.minicards._visible = true;
var _local2 = 0;
while (_local2 < sortedTricks.length) {
var _local3 = sortedTricks[_local2].value;
_local3 = ((_local3 == "T") ? 10 : (_local3));
this.lasttrick_panel.minicards["minicard" + sortedTricks[_local2].seat].value.text = _local3;
this.lasttrick_panel.minicards["minicard" + sortedTricks[_local2].seat].color_symbols.gotoAndStop(sortedTricks[_local2].color);
_local2++;
}
if (!this.lasttrick_viewed) {
this.show_lasttrick();
this.lasttrick_viewed = true;
}
};
this.show_scoreboard = function () {
this.scoreboard.active = true;
this.scoreboard.header.text = game.gamedata.text.scoreboard_header;
this.scoreboard.next_round.text = game.gamedata.text.next_round;
this.scoreboard.ranking = [];
var _local3 = 0;
while (_local3 < game.table.players.length) {
var _local5 = game.table.players[_local3];
var _local4 = new Object();
_local4.playernum = _local5.playernum;
_local4.playername = _local5.playername;
_local4.score = _local5.score;
_local4.level_score = _local5.level_score;
this.scoreboard.ranking.push(_local4);
_local3++;
}
this.scoreboard.ranking.sortOn("score", Array.ASCENDING | Array.NUMERIC);
_local3 = 0;
while (_local3 < this.scoreboard.ranking.length) {
var _local2 = this.scoreboard.ranking[_local3];
this.scoreboard["rank" + _local3].text = _local2.playername;
this.scoreboard["score" + _local3].text = _local2.score;
this.set_player_score(_local2.playernum, _local2.level_score, _local2.score);
_local3++;
}
if (!game.get_game_over()) {
this.scoreboard.onRelease = function () {
game.gui.click_scoreboard();
};
this.scoreboard_timer.init({duration:this.SCOREBOARD_TIMER_DURATION});
this.scoreboard_timer.startTimer();
soundFx.play("next_round.aif");
} else {
this.scoreboard.next_round.text = "";
this.scoreboard.next_round_counter.text = "";
this.scoreboard.next_round_frame._visible = false;
this.scoreboard.header.text = game.gamedata.text.scoreboard_game_over;
if (game.table.local_player.winner) {
soundFx.play("game_win.aif");
} else {
soundFx.play("game_over.aif");
}
}
this.scoreboard._visible = true;
this.scoreboard._alpha = 0;
if (!this.scoreboard.tween_obj) {
this.scoreboard.tween_obj = new Tween();
}
var _local6 = [{sprite:this.scoreboard, from:{_alpha:0, _xscale:70, _yscale:70, _x:this.other_positions.score_board[0] + (this.scoreboard._width * 0.15), _y:this.other_positions.score_board[1] + (this.scoreboard._height * 0.15)}, to:{_alpha:100, _xscale:100, _yscale:100, _x:this.other_positions.score_board[0], _y:this.other_positions.score_board[1]}}];
this.scoreboard.tween_obj.go(_local6, {duration:300, callback:this.avatars_to_scoreboard, callback_scope:this});
this.bg_dark_plate._visible = true;
};
this.click_scoreboard = function () {
soundFx.play("click.wav", false, 80);
delete this.scoreboard.onRelease;
this.scoreboard_timer.stopTimer();
game.rules.click_scoreboard();
this.hide_scoreboard();
game.table.local_player.avatar.setMood("neutral");
game.rules.localplayer_next_round();
};
this.hide_scoreboard = function () {
if (!this.scoreboard.active) {
return(undefined);
}
this.scoreboard.active = false;
var _local3 = [{sprite:this.scoreboard, from:{_alpha:100, _xscale:100, _yscale:100, _x:this.other_positions.score_board[0], _y:this.other_positions.score_board[1]}, to:{_alpha:0, _xscale:70, _yscale:70, _x:this.other_positions.score_board[0] + (this.scoreboard._width * 0.15), _y:this.other_positions.score_board[1] + (this.scoreboard._height * 0.15)}}];
this.scoreboard.tween_obj.go(_local3, {duration:200});
this.bg_dark_plate._visible = false;
var _local2 = 0;
while (_local2 < game.table.players.length) {
this.positionate_avatar(game.table.players[_local2].seatnum, game.table.players[_local2].avatar);
game.table.players[_local2].avatar.avatar_sprite._visible = game.table.players[_local2].ready_for_round;
this.reset_player_tricks();
this.lasttrick_panel.minicards._visible = false;
_local2++;
}
};
this.set_player_score = function (pnum, roundscore, totalscore) {
var _local2 = game.table.players[pnum].seatnum;
this.score_box["score" + _local2].textfield.text = ((("" + roundscore) + " (") + totalscore) + ")";
};
this.hilite_playerbox = function (boxnum, activate) {
if (!this.player_boxes[boxnum].pulsate) {
this.player_boxes[boxnum].pulsate = new Pulsate({sprite:this.player_boxes[boxnum].hilite, alpha:60});
}
if (activate) {
this.player_boxes[boxnum].pulsate.start();
this.player_boxes[boxnum].hilite._visible = true;
} else {
this.player_boxes[boxnum].pulsate.stop();
this.player_boxes[boxnum].hilite._visible = false;
}
};
this.set_playerbox = function (boxnum, name) {
var _local5 = "player_box_blue";
var _local3 = sprites.create({member:_local5, x:this.player_positions[boxnum][0], y:this.player_positions[boxnum][1], visible:false, level:10});
var _local4 = sprites.create({member:"halo", x:this.halo_positions[boxnum][0], y:this.halo_positions[boxnum][1], visible:false, level:2});
this.halos[boxnum] = _local4;
_local3.hilite._visible = false;
_local3.name.text = name;
_local3.name._alpha = 100;
this.player_boxes[boxnum] = _local3;
};
this.set_player_tricks = function (player) {
var _local4 = player.tricks;
var _local2 = 0;
while (_local2 < _local4.length) {
var _local3 = _local2 + 1;
if (_local4[_local2].points > 0) {
if (_local4[_local2].points >= 13) {
this.player_boxes[player.seatnum]["marker" + _local3].gotoAndStop(4);
} else {
this.player_boxes[player.seatnum]["marker" + _local3].gotoAndStop(3);
}
} else {
this.player_boxes[player.seatnum]["marker" + _local3].gotoAndStop(2);
}
_local2++;
}
};
this.reset_player_tricks = function () {
var _local4 = 0;
while (_local4 < this.player_boxes.length) {
var _local2 = 0;
while (_local2 < 14) {
var _local3 = _local2 + 1;
this.player_boxes[_local4]["marker" + _local3].gotoAndStop(1);
_local2++;
}
_local4++;
}
};
this.show_playerboxes = function () {
var _local13 = new Tween();
var _local7 = [];
var _local6;
var _local2;
var _local3 = 0;
while (_local3 < this.player_boxes.length) {
_local6 = this.player_positions[_local3][0] < (game.width / 2);
this.player_boxes[_local3]._x = (_local6 ? (-this.player_boxes[_local3]._width) : (game.width));
this.player_boxes[_local3]._visible = true;
_local2 = {sprite:this.player_boxes[_local3], from:{_x:this.player_positions[_local3][0], _alpha:0}, to:{_x:this.player_positions[_local3][0], _alpha:100}};
_local7.push(_local2);
_local3++;
}
var _local4;
var _local5;
_local3 = 0;
while (_local3 < game.table.players.length) {
_local4 = game.table.players[_local3].avatar.avatar_sprite;
_local5 = game.table.players[_local3].avatar.avatar_sprite._x;
_local6 = _local4._x < (game.width / 2);
_local4._x = (_local6 ? (-_local5) : (game.width + (game.width - _local5)));
_local4._visible = true;
_local2 = {sprite:_local4, from:{_x:_local5, _alpha:0}, to:{_x:_local5, _alpha:100}};
_local7.push(_local2);
_local3++;
}
_local3 = 0;
while (_local3 < this.halos.length) {
this.halos[_local3]._visible = true;
_local2 = {sprite:this.halos[_local3], from:{_alpha:0}, to:{_alpha:100}};
_local7.push(_local2);
_local3++;
}
_local13.go(_local7, {duration:500});
};
this.avatar_ready = function (avatar) {
avatar.avatar_sprite._xscale = -this.instr_avatar_pos[this.player_count][2];
avatar.avatar_sprite._yscale = this.instr_avatar_pos[this.player_count][3];
avatar.avatar_sprite._x = this.instr_avatar_pos[this.player_count][0] + (avatar.avatar_width * (this.instr_avatar_pos[this.player_count][2] / 100));
avatar.avatar_sprite._y = this.instr_avatar_pos[this.player_count][1] + this.statusbox.offset_y;
avatar.avatar_sprite._visible = true;
this.player_count++;
this.set_statusbox_msg(((game.gamedata.text.waiting_for_players + " (") + this.player_count) + "/4)");
soundFx.play("tone_a.aif", false, 80);
};
this.positionate_avatar = function (num, avatar) {
var _local3 = 70;
avatar.avatar_sprite._x = this.avatar_positions[num][0];
avatar.avatar_sprite._y = this.avatar_positions[num][1];
avatar.avatar_sprite._visible = false;
avatar.avatar_sprite._xscale = -_local3;
avatar.avatar_sprite._x = avatar.avatar_sprite._x + ((avatar.avatar_width * _local3) / 100);
avatar.avatar_sprite._yscale = _local3;
};
this.avatars_to_scoreboard = function () {
var _local5 = 50;
var _local3 = 0;
while (_local3 < this.scoreboard.ranking.length) {
var _local4 = game.table.players[this.scoreboard.ranking[_local3].playernum].avatar;
var _local2 = _local4.avatar_sprite;
_local2._xscale = -_local5;
_local2._yscale = _local5;
var _local7 = this.score_avatar_pos[_local3][0] + ((_local4.avatar_width * _local5) / 100);
var _local6 = this.score_avatar_pos[_local3][1];
_local2._x = _local7;
_local2._y = _local6;
_local2._visible = true;
_local3++;
}
var _local9 = game.rules.get_round_localwinner();
var _local8 = (_local9 ? "happy" : "angry");
game.table.local_player.avatar.setMood(_local8);
};
this.show_statusbox = function () {
this.statusbox = sprites.create({member:"statusbox", x:this.other_positions.statusbox[0], y:this.other_positions.statusbox[1]});
this.statusbox.status.text = "";
this.statusbox.status_msg.text = game.gamedata.text.waiting_for_players + " (0/4)";
this.statusbox.time_to_game.text = game.gamedata.text.time_to_start.toUpperCase();
this.statusbox.time.text = "";
this.statusbox.offset_y = 0;
var _local2 = function () {
game.gui.instructions_timer_ended();
};
this.instructions_timer = new Timer({duration:20, textref:this.statusbox.time, cb:_local2, format:"time"});
this.instructions_timer.startTimer();
this.statusbox.tween_obj = new Tween();
var _local3 = [{to:{_alpha:100}, from:{_alpha:0}, sprite:this.statusbox}];
this.statusbox.tween_obj.go(_local3, {duration:200});
this.statusbox.active = true;
};
this.slide_up_statusbox = function () {
var _local11 = (game.height / 2) - (this.statusbox._height / 2);
var _local9 = this.other_positions.statusbox[1] - _local11;
this.statusbox.offset_y = -_local9;
var _local10 = [{from:{_y:this.other_positions.statusbox[1]}, to:{_y:_local11}, sprite:this.statusbox}];
var _local4;
var _local3;
var _local13;
var _local2 = 0;
while (_local2 < game.table.players.length) {
_local3 = game.table.players[_local2].avatar.avatar_sprite;
avatar_y = game.table.players[_local2].avatar.avatar_sprite._y;
_local4 = {sprite:_local3, from:{_y:this.instr_avatar_pos[_local2][1]}, to:{_y:this.instr_avatar_pos[_local2][1] - _local9}};
_local10.push(_local4);
_local2++;
}
this.statusbox.tween_obj.go(_local10, {duration:500});
};
this.hide_statusbox = function () {
if (!this.statusbox.active) {
return(undefined);
}
this.statusbox.active = false;
this.instructions_timer.stopTimer();
if (this.status_dotanimator) {
this.status_dotanimator.stop();
}
var _local4 = [{to:{_alpha:0}, from:{_alpha:100}, sprite:this.statusbox}];
this.statusbox.tween_obj.go(_local4, {duration:200});
var _local3;
var _local2 = 0;
while (_local2 < game.table.players.length) {
_local3 = game.table.players[_local2].avatar.avatar_sprite;
_local3._visible = false;
_local2++;
}
};
this.set_statusbox_msg = function (msg) {
if (!this.statusbox) {
return(undefined);
}
this.statusbox.status_msg.text = msg;
};
this.instructions_timer_ended = function () {
game.rules.send_cir();
this.click_instructions();
this.status_dotanimator = {txt:"", dots:0, cnt:0, running:false, run:function () {
this.cnt++;
var _local2 = "..............";
if ((this.cnt % 25) == 0) {
this.dots++;
this.dots = this.dots % 11;
game.gui.statusbox.time.text = this.txt + _local2.substr(0, this.dots);
}
}, start:function () {
if (this.running) {
return(undefined);
}
this.running = true;
events.runIt(this);
}, stop:function () {
if (!this.running) {
return(undefined);
}
this.running = false;
events.stopIt(this);
}};
this.status_dotanimator.start();
};
this.show_alert = function (msg) {
soundFx.play("game_over.aif");
this.bg_dark_plate.toLevel(21);
this.bg_dark_plate.useHandCursor = false;
this.bg_dark_plate.onRelease = function () {
trace("bg_dark_plate cover click");
};
this.bg_dark_plate._visible = true;
this.alertbox.header.text = game.gamedata.text.alert;
this.alertbox.msg.text = msg;
this.alertbox._visible = true;
if (!this.alertbox.active) {
this.alertbox._alpha = 0;
var _local2 = [{sprite:this.alertbox, from:{_alpha:0, _xscale:70, _yscale:70, _x:this.alertbox._x + (this.alertbox._width * 0.15), _y:this.alertbox._y + (this.alertbox._height * 0.15)}, to:{_alpha:100, _xscale:100, _yscale:100, _x:this.alertbox._x, _y:this.alertbox._y}}];
this.alertbox.tween_obj.go(_local2, {duration:300});
}
this.alertbox.active = true;
};
this.halt = function () {
if (this.instructions.active) {
delete this.instructions.onRelease;
this.hide_instructions();
}
if (this.statusbox.active) {
this.hide_statusbox();
}
if (this.cardbox.active) {
this.stop_cardbox();
this.hide_cardbox();
}
if (this.scoreboard.active) {
delete this.scoreboard.onRelease;
this.scoreboard_timer.stopTimer();
this.hide_scoreboard();
}
if (this.slambox.active) {
this.slambox_timer.stopTimer();
this.hide_slambox();
}
};
this.init(props);
}
function Table(props) {
this.players = [];
this.positions = [];
this.trick_positions = [];
this.hand_positions = [];
this.deck_positions = [];
this.pass_positions = [];
this.local_player = null;
this.deck = null;
this.pile = null;
this.pile_positions = [];
this.trump_position = [];
this.init = function (props) {
this.ph = sprites.create({member:"placeholders_table", visible:false});
var _local4;
var _local3;
var _local11;
var _local10;
var _local5 = 0;
while (_local5 < 4) {
_local4 = this.ph["hand" + _local5];
_local3 = _local4.getBounds(_root);
_local11 = _local3.xMin + ((_local3.xMax - _local3.xMin) / 2);
_local10 = _local3.yMin + ((_local3.yMax - _local3.yMin) / 2);
this.hand_positions.push([_local11, _local10, _local4._rotation, _local4._xscale]);
this.positions.push([_local11, _local10, _local4._width, _local4._height]);
_local4 = this.ph["pile" + _local5];
_local3 = _local4.getBounds(_root);
_local11 = _local3.xMin + ((_local3.xMax - _local3.xMin) / 2);
_local10 = _local3.yMin + ((_local3.yMax - _local3.yMin) / 2);
this.pile_positions.push([_local11, _local10, _local4._rotation, _local4._xscale]);
_local4 = this.ph["trick" + _local5];
_local3 = _local4.getBounds(_root);
_local11 = _local3.xMin + ((_local3.xMax - _local3.xMin) / 2);
_local10 = _local3.yMin + ((_local3.yMax - _local3.yMin) / 2);
var _local6 = 20;
if (_local11 > (props.width / 2)) {
_local6 = -_local6;
}
this.trick_positions.push([_local11, _local10, _local6, 0, _local4._rotation * 2]);
_local4 = this.ph["deck" + _local5];
_local3 = _local4.getBounds(_root);
_local11 = _local3.xMin + ((_local3.xMax - _local3.xMin) / 2);
_local10 = _local3.yMin + ((_local3.yMax - _local3.yMin) / 2);
this.deck_positions.push([_local11, _local10, _local4._rotation, _local4._xscale]);
_local4 = this.ph["pass" + _local5];
_local3 = _local4.getBounds(_root);
_local11 = _local3.xMin + ((_local3.xMax - _local3.xMin) / 2);
_local10 = _local3.yMin + ((_local3.yMax - _local3.yMin) / 2);
this.pass_positions.push([_local11, _local10, _local4._rotation, _local4._xscale]);
_local5++;
}
this.pile = new Pile({x:200, y:200, parent:this});
};
this.get_centerpos = function (mc) {
var _local1 = (mc._rotation * Math.PI) / 180;
var _local2 = 0;
};
this.add_local_player = function (pobj) {
pobj.parent = this;
pobj.local = true;
this.players[pobj.playernum] = new Player(pobj);
this.local_player = this.players[pobj.playernum];
this.players[pobj.playernum].add_avatar();
return(this.players[pobj.playernum]);
};
this.add_remote_player = function (pobj) {
pobj.parent = this;
pobj.local = false;
this.players[pobj.playernum] = new Player(pobj);
this.players[pobj.playernum].add_avatar();
return(this.players[pobj.playernum]);
};
this.next_round = function () {
var _local2 = 0;
while (_local2 < this.players.length) {
this.players[_local2].next_round();
_local2++;
}
var _local3 = game.rules.get_deal_seatnum();
this.deck = new Deck({x:this.deck_positions[_local3][0], y:this.deck_positions[_local3][1], v:this.deck_positions[_local3][2], scale:this.deck_positions[_local3][3], parent:this, parent_sp:this.card_group});
this.deck.show();
};
this.halt = function () {
var _local2 = 0;
while (_local2 < this.players.length) {
this.players[_local2].halt();
_local2++;
}
};
this.init(props);
}
function Network(props) {
this.cmd_listeners = {};
this.out_listeners = [];
this.pause_in_active = 0;
this.pause_in_stack = [];
this.init = function (props) {
this.parent = props.parent;
};
this.connect = function (props) {
this.mp_props = props;
var _local3 = {listener:this, host:props.hostname, port:props.port, pingtime:parseInt(props.pingtime)};
this.sock = new CommSocket(_local3);
this.sock.connect();
};
this.disconnect = function () {
this.sock.disconnect();
};
this.add_listener = function (cmd, obj) {
this.cmd_listeners[cmd] = obj;
};
this.socketEvent = function (props, force_through) {
if (typeof(props.status) == "string") {
if (props.status == "connection established") {
var _local6 = this.mp_props.slotid;
var _local7 = this.mp_props.magic;
this.send_string((("CCC " + _local6) + " ") + _local7);
} else if ((props.status == "no connection") || (props.status == "connection failed")) {
this.handleCommError("unable_to_connect");
} else if (props.status == "connection closed") {
this.handleCommError("local_disconnect");
}
}
if (typeof(props.data) == "string") {
if (((this.pause_in_active > 0) || (this.pause_in_stack.length > 0)) && (force_through != true)) {
this.pause_in_stack.push(props);
} else {
var _local5 = props.data.charAt(0);
var _local3 = props.data.substr(0, 3);
var _local4 = props.data.substr(4);
if (_local5 == "S") {
this.handleServerEvent(_local3, _local4);
} else if (_local5 == "G") {
this.handleGameEvent(_local3, _local4);
} else if (this.cmd_listeners[_local3]) {
this.cmd_listeners[_local3].networkEvent(_local3, _local4);
}
}
}
};
this.handleServerEvent = function (cmd, dat) {
switch (cmd) {
case "SCA" :
this.parent.add_local_player(this.parse_player_info(dat));
break;
case "SAC" :
this.parent.add_remote_player(this.parse_player_info(dat));
break;
case "SCD" :
this.parent.remove_player(parseInt(dat));
break;
case "SSG" :
this.parent.start_game();
break;
case "SAG" :
this.handleCommError("server_abort_game");
break;
case "STM" :
break;
default :
this.parent.networkServerEvent(cmd, dat);
}
};
this.handleGameEvent = function (cmd, dat) {
var _local2 = dat.split(",");
var _local4 = parseInt(_local2[0]);
_local2.splice(0, 1);
var _local3 = _local2.join(",");
this.parent.networkGameEvent(cmd, _local4, _local3);
};
this.handleCommError = function (msg) {
this.parent.handleCommError(msg);
};
this.send_string = function (str, sender) {
if (this.sock.online) {
this.sock.send_string(str);
}
};
this.send_ai_string = function (str) {
if (this.sock.online) {
this.socketEvent({data:str});
this.sock.send_string(str);
}
};
this.pause_incoming = function () {
this.pause_in_active++;
};
this.resume_incoming = function () {
this.pause_in_active--;
if (this.pause_in_active > 0) {
return(undefined);
}
var _local2 = 0;
while (_local2 < this.pause_in_stack.length) {
this.socketEvent(this.pause_in_stack[_local2], true);
if (this.pause_in_active > 0) {
this.pause_in_stack.splice(0, _local2 + 1);
return(undefined);
}
_local2++;
}
this.pause_in_stack = [];
};
this.parse_player_info = function (dat) {
var _local2 = parseArgString(dat);
var _local1 = {};
_local1.playernum = parseInt(_local2[0]);
_local1.playername = _local2[1];
_local1.avatar = _local2[2];
return(_local1);
};
this.init(props);
}
function Playdata(props) {
this.init = function (props) {
};
this.init(props);
}
function Robohand(props) {
this.init = function (props) {
this.cards = [];
this.color_counts = {};
this.color_counts.S = 0;
this.color_counts.D = 0;
this.color_counts.H = 0;
this.color_counts.C = 0;
};
this.add_card = function (_carddata) {
this.color_counts[_carddata.charAt(1)]++;
this.cards.push(_carddata);
};
this.remove_card = function (_index) {
this.color_counts[this.cards[_index].charAt(1)]--;
this.cards.length();
this.cards.splice(_index, 1);
this.cards.length();
};
this.init(props);
}
function Roboplayer(props) {
var card_values = {};
card_values["2"] = 2;
card_values["3"] = 3;
card_values["4"] = 4;
card_values["5"] = 5;
card_values["6"] = 6;
card_values["7"] = 7;
card_values["8"] = 8;
card_values["9"] = 9;
card_values.T = 10;
card_values.J = 11;
card_values.Q = 12;
card_values.K = 13;
card_values.A = 14;
var pass_increase_num = [1, 3, 2, 0];
var pass_direction_index = 0;
this.init = function (props) {
this.net_verbose = false;
this.verbose = false;
this.players = [];
this.current_playernum = -1;
this.num_players = 4;
this.deck_length = 52;
this.start_player = -1;
this.playfast = false;
this.disconnect_ai_test = false;
this.hand = new Robohand();
this.pile = [];
this.recieved_cards = [];
var _local3 = function () {
this.my_robot.connect();
};
var _local2 = new RoboDelay(_local3, (this.playfast ? 0 : (Math.round(Math.random() * 40) + 40)));
_local2.my_robot = this;
};
this.connect = function () {
this.network = new Network({parent:this});
this.network.connect(props);
};
this.add_local_player = function (pobj) {
this.network.send_string("CIR");
this.playername = pobj.playername;
this.playernum = pobj.playernum;
this.players[this.playernum] = {playernum:this.playernum, level_score:0};
};
this.add_remote_player = function (pobj) {
if (this.verbose) {
wr(("robot " + this.playernum) + ": added player:", pobj.playernum);
}
this.players[pobj.playernum] = {playernum:pobj.playernum, level_score:0};
};
this.start_game = function () {
};
this.start_send_cards = function () {
this.card_send_count = 0;
var _local3 = function () {
this.my_robot.send_cards();
};
var _local2 = new RoboDelay(_local3, (this.playfast ? 0 : (75 + random.range(1, 50))));
_local2.my_robot = this;
};
this.send_cards = function () {
wr("robot", this.playernum, "sending cards!!");
var _local4 = 0;
while (_local4 < 3) {
var _local3 = random.range(0, this.hand.cards.length - 1);
var _local2 = this.hand.cards[_local3];
if ((_local2.charAt(0) == "2") && (_local2.charAt(1) == "C")) {
var _local5 = (this.playernum + pass_increase_num[pass_direction_index]) % pass_increase_num.length;
this.start_player = _local5;
}
this.hand.remove_card(_local3);
this.network.send_string((("GCC " + this.playernum) + ",") + _local2);
_local4++;
}
this.network.send_string("GSC " + this.playernum);
this.cards_sent();
};
this.opponent_chose_card = function (pnum, carddata) {
var _local5 = (parseInt(pnum) + pass_increase_num[pass_direction_index]) % pass_increase_num.length;
if ((carddata.charAt(0) == "2") && (carddata.charAt(1) == "C")) {
this.start_player = _local5;
}
if (this.playernum != _local5) {
return(undefined);
}
var _local4 = false;
var _local2 = 0;
while (_local2 < this.recieved_cards.length) {
if (this.recieved_cards[_local2] == carddata) {
this.recieved_cards.splice(_local2, 1);
_local4 = true;
}
_local2++;
}
if (!_local4) {
this.recieved_cards.push(carddata);
}
};
this.cards_sent = function () {
this.card_send_count++;
wr("in robot", this.playernum, "this.card_send_count is:", this.card_send_count);
if (this.card_send_count == 4) {
var _local2 = 0;
while (_local2 < this.recieved_cards.length) {
this.hand.add_card(this.recieved_cards[_local2]);
_local2++;
}
this.recieved_cards = [];
this.start_round();
return(undefined);
}
};
this.start_round = function () {
if (this.disconnect_ai_test) {
if (this.playernum == 2) {
this.network.disconnect();
return(undefined);
}
}
var _local2 = 0;
while (_local2 < this.players.length) {
this.players[_local2].level_score = 0;
_local2++;
}
wr("in robot", this.playernum, "start player is:", this.start_player);
this.current_playernum = ((this.start_player + this.num_players) - 1) % this.num_players;
this.next_player();
};
this.next_player = function () {
if (this.pile.length == this.players.length) {
var _local6 = -1;
var _local7 = -1;
var _local8 = this.pile[0].color;
var _local5 = 0;
var _local4 = 0;
while (_local4 < this.pile.length) {
var _local3 = 0;
var _local2 = this.pile[_local4];
if (_local2.color == _local8) {
_local3 = _local3 + card_values[_local2.value];
}
if (_local3 > _local6) {
_local6 = _local3;
win_playernumindex = _local2.playernumindex;
_local7 = _local2.playernum_sequence;
}
if (_local2.color == "H") {
_local5 = _local5 + 1;
}
if ((_local2.color == "S") && (_local2.value == "Q")) {
_local5 = _local5 + 13;
}
_local4++;
}
if (this.verbose) {
wr("in robot, winning player is:", win_playernumindex);
}
this.players[_local7].level_score = this.players[_local7].level_score + _local5;
this.current_playernum = _local7;
this.pile = [];
if (this.hand.cards.length == 0) {
this.end_round();
}
} else {
this.current_playernum = (this.current_playernum + 1) % this.num_players;
}
wr(("robot " + this.playernum) + " next player:", this.current_playernum);
if (this.current_playernum == this.playernum) {
var _local10 = function () {
wr("robo_cb");
this.my_robot.play_card();
};
var _local9 = new RoboDelay(_local10, (this.playfast ? 0 : (Math.round(Math.random() * 30) + 20)));
_local9.my_robot = this;
}
};
this.end_round = function () {
var _local2 = 0;
while (_local2 < this.players.length) {
if (this.players[_local2].level_score == 26) {
if (_local2 == this.playernum) {
this.network.send_string((("GSS " + this.playernum) + ",") + random.range(0, 1));
this.slam_done();
}
return(undefined);
}
_local2++;
}
this.slam_done();
};
this.slam_done = function () {
pass_direction_index = (pass_direction_index + 1) % pass_increase_num.length;
this.recieved_cards = [];
this.deck_length = 52;
this.network.send_string("GNR " + this.playernum);
};
this.play_card = function () {
if (this.hand.cards.length == 0) {
return(undefined);
}
var _local2 = 0;
_local2 = 0;
while (_local2 < this.hand.cards.length) {
wr("robot", this.playernum, "check card:", this.hand.cards[_local2]);
if (game.rules.check_card_legal(this.hand, {color:this.hand.cards[_local2].charAt(1), value:this.hand.cards[_local2].charAt(0)})) {
break;
}
_local2++;
}
if (_local2 == this.hand.cards.length) {
wr("alert!!! robot could not find a legal card!!");
_local2 = random.range(0, this.hand.cards.length - 1);
}
var _local3 = this.hand.cards[_local2];
this.hand.remove_card(_local2);
this.pile.push({color:_local3.charAt(1), value:_local3.charAt(0), playernumindex:this.current_playernum, playernum_sequence:this.current_playernum});
this.network.send_string((((("GPC " + this.playernum) + ",") + _local2) + ",") + _local3);
this.next_player();
};
this.networkServerEvent = function (cmd, dat) {
if (this.net_verbose) {
wr(("robot " + this.playernum) + " networkServerEvent()", cmd, dat);
}
if (!(cmd === "SDC")) {
} else {
var _local5 = dat.split(",", 2);
var _local4 = parseInt(_local5[0]);
var _local3 = _local5[1];
this.deck_length = this.deck_length - (_local3.length / 2);
var _local2 = 0;
while (_local2 < _local3.length) {
if (_local4 == this.playernum) {
this.hand.add_card(_local3.charAt(_local2) + _local3.charAt(_local2 + 1));
}
if ((_local3.charAt(_local2) == "2") && (_local3.charAt(_local2 + 1) == "C")) {
this.start_player = _local4;
}
_local2 = _local2 + 2;
}
if (this.deck_length == 0) {
this.start_send_cards();
}
}
};
this.networkGameEvent = function (cmd, playernum, playdata) {
if (this.net_verbose) {
wr(("robot " + this.playernum) + " networkGameEvent()", cmd, playernum, playdata);
}
switch (cmd) {
case "GCC" :
this.opponent_chose_card(playernum, playdata);
break;
case "GSC" :
this.cards_sent();
break;
case "GPC" :
var _local2 = playdata.split(",")[1];
wr("robot got GPC", _local2);
this.pile.push({color:_local2.charAt(1), value:_local2.charAt(0), playernumindex:this.current_playernum, playernum_sequence:this.current_playernum});
this.next_player();
break;
case "GSS" :
this.slam_done();
}
};
this.handleCommError = function (msg) {
wr("BOT Network error: " + msg);
game.gui.show_alert("BOT Network error: " + msg);
game.gui.hide_statusbox();
};
this.deal_cards = function (carddata) {
};
this.enable = function () {
};
this.disable = function () {
};
this.kill = function () {
};
this.halt = function () {
};
this.init(props);
}
function RoboDelay(what, frames) {
this.what = what;
this.counter = 0;
this.nFrames = frames;
this.run = function () {
this.counter++;
if (this.counter > this.nFrames) {
events.stopIt(this);
this.what();
}
};
events.runIt(this);
}
function Avatar(props) {
this.ready = false;
this.avatar_width = 110;
this.avatar_height = 110;
this.init = function (props) {
this.parent = props.parent;
this.props = props;
this.swf_path = game.gamedata.mp.chatcontrol;
};
this.load = function () {
if (__midas_chatcontrol) {
this.chatcontrol = __midas_chatcontrol;
if (__midas_chatcontrol.initiated) {
this.getAvatar();
} else {
var _local3 = {parent:this};
_local3.run = function () {
if (this.parent.chatcontrol.initiated) {
events.stopIt(this);
this.parent.getAvatar();
}
};
events.runIt(_local3);
}
} else {
this.sp = sprites.create({x:0, y:0, level:18});
this.chatcontrol = sprites.create({x:0, y:0, parent_sprite:this.sp});
this.chatcontrol.loadMovie(this.swf_path);
this.chatcontrol.initiated = false;
__midas_chatcontrol = this.chatcontrol;
var _local3 = {cc_load_ready:false, cc:this.chatcontrol, parent:this};
_local3.run = function () {
if (this.cc_load_ready) {
events.stopIt(this);
this.parent.setupChatControl();
this.parent.getAvatar();
return(undefined);
}
var _local2 = this.cc.getBytesTotal();
if (isNaN(_local2) || (_local2 < 1)) {
_local2 = -1;
} else if (this.cc.getBytesLoaded() == _local2) {
this.cc_load_ready = true;
}
};
events.runIt(_local3);
}
};
this.setupChatControl = function () {
if (__midas_chatcontrol) {
if (__midas_chatcontrol.initiated) {
return(false);
}
}
System.security.allowDomain(_root.gameDomain);
this.chatcontrol.setAllowDomain(_root.gameDomain);
if (dev_mode) {
this.chatcontrol.init(this, "../chatcontrol/");
} else {
this.chatcontrol.init(this);
}
this.chatcontrol.initiated = true;
this.chatcontrol.enable();
};
this.getAvatar = function () {
if (!this.chatcontrol.initiated) {
return(undefined);
}
this.avatar_display = this.chatcontrol.getAvatar(this.props.playernum, this.props.avatar, 0, 0, this.parent.local, this);
this.avatar_display.show();
this.avatar_sprite = this.avatar_display.clipRef;
};
this.onAvatarLoaded = function () {
this.ready = true;
if (this.parent.avatar_ready) {
this.parent.avatar_ready();
}
};
this.setMood = function (mood) {
if (!this.avatar_display) {
return(undefined);
}
this.chatcontrol.setMood(this.avatar_display, mood);
};
this.ccom = function (a) {
game.network.send_string(a);
};
this.hide = function () {
this.avatar_sprite._visible = false;
};
this.init(props);
}
function ClickButton(props) {
this.init = function (props) {
this.sp = props.sp;
this.id = props.id;
this.callback = props.callback;
this.callback_scope = props.callback_scope;
this.padding = ((typeof(props.padding) == "number") ? (props.padding) : 0);
this.on_down = props.on_down || false;
this.color_obj = new Color(this.sp);
this.std_color = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0};
this.over_color = ((typeof(props.over_color) == "object") ? (props.over_color) : null);
this.over_alpha = ((typeof(props.over_alpha) == "number") ? (props.over_alpha) : null);
if (this.padding > 0) {
this.click_sp = this.sp.createEmptyMovieClip("cl_a", 99);
this.click_sp._x = -this.padding;
this.click_sp._y = -this.padding;
this.drawRect(this.click_sp, this.sp._width + (this.padding * 2), this.sp._height + (this.padding * 2), 65280, 0);
} else {
this.click_sp = this.sp;
}
this.click_sp.parent = this;
this.enable();
};
this.enable = function () {
this.click_sp.onPress = function () {
if (this.parent.on_down) {
this.parent.exec_cb();
}
};
this.click_sp.onRelease = function () {
if (!this.parent.on_down) {
this.parent.exec_cb();
}
};
this.click_sp.onRollOver = function () {
if (this.parent.over_color) {
this.parent.color_obj.setTransform(this.parent.over_color);
}
if (this.parent.over_alpha) {
this.parent.sp._alpha = this.parent.over_alpha;
}
};
this.click_sp.onRollOut = function () {
if (this.parent.over_color) {
this.parent.color_obj.setTransform(this.parent.std_color);
}
if (this.parent.over_alpha) {
this.parent.sp._alpha = 100;
}
};
this.click_sp.onDragOut = function () {
if (this.parent.over_color) {
this.parent.color_obj.setTransform(this.parent.std_color);
}
if (this.parent.over_alpha) {
this.parent.sp._alpha = 100;
}
};
};
this.disable = function () {
delete this.click_sp.onPress;
delete this.click_sp.onRelease;
delete this.click_sp.onDragOut;
delete this.click_sp.onRollOver;
delete this.click_sp.onRollOut;
};
this.exec_cb = function () {
if (this.callback) {
this.callback.call(this.callback_scope, this.id);
}
};
this.kill = function () {
this.disable();
delete this.click_sp.parent;
sprites.remove(this.click_sp);
};
this.drawRect = function (mc, w, h, c, a) {
mc.moveTo(0, 0);
mc.beginFill(c, a);
mc.lineTo(w, 0);
mc.lineTo(w, h);
mc.lineTo(0, h);
mc.lineTo(0, 0);
mc.endFill();
};
this.init(props);
}
function CommSocket(props) {
function handle_onConnect(success) {
if (success) {
self.online = true;
if (net_debug) {
trace("CommSocket: connection established");
}
_add_to_queue({status:"connection established"});
} else {
if (net_debug) {
trace("CommSocket: connection failed");
}
_add_to_queue({status:"connection failed"});
}
}
function handle_onClose() {
self.online = false;
if (net_debug) {
trace("CommSocket: connection closed");
}
_add_to_queue({status:"connection closed"});
}
function handle_onError(err) {
if (net_debug) {
trace("CommSocket error: " + err);
}
}
function handle_onData(src) {
_add_to_queue({data:src});
last_activity = getTimer();
}
function _add_to_queue(obj) {
msg_queue.push(obj);
}
function _dispatch_event(obj) {
listener.socketEvent(obj);
}
var zock = null;
var host = props.host;
var port = props.port;
var pingtime = ((props.pingtime > 0) ? (props.pingtime * 1000) : 10000);
var lastping = 0;
var last_activity = 0;
var listener = props.listener;
var msg_queue = [];
var _local8 = 0;
var _local6 = 0;
var self = this;
this.online = false;
this.connect = function () {
if (zock) {
return(undefined);
}
events.runIt(this);
zock = new XMLSocket();
zock.onConnect = handle_onConnect;
zock.onClose = handle_onClose;
zock.onData = handle_onData;
zock.onError = handle_onError;
if (zock.connect(host, port)) {
if (net_debug) {
trace((("CommSocket: connecting to " + host) + " ") + port);
}
_add_to_queue({status:"connecting"});
} else {
if (net_debug) {
trace("CommSocket: no connection");
}
_add_to_queue({status:"no connection"});
}
};
this.disconnect = function () {
if (!zock) {
return(undefined);
}
zock.close();
this.online = false;
zock = null;
events.stopIt(this);
};
this.send_string = function (str) {
zock.send(str);
};
this.send_data = function (data) {
var _local1 = stringify(data);
zock.send(_local1);
};
this.run = function () {
if (msg_queue.length > 0) {
_dispatch_event(msg_queue.shift());
}
var _local2 = getTimer();
if ((_local2 - lastping) > pingtime) {
lastping = _local2;
if (this.online) {
this.send_string("CTM");
}
} else if ((_local2 - last_activity) > (pingtime + 4000)) {
this.disconnect();
listener.handleCommError("local_disconnect");
}
};
}
function Timer(props) {
function time_format_str(t) {
var _local2 = "";
if (timeformat == "sec") {
_local2 = "" + Math.floor(t);
} else {
_local2 = Math.floor(t / 60) + ":";
t = t % 60;
_local2 = _local2 + ((t < 10) ? ("0" + t) : (t));
}
return(_local2);
}
var running = false;
var timeLeft = {};
var textref;
var textfunc;
var timeformat = "time";
var callback;
var tick_sound;
this.init = function (props) {
timeLeft.startTime = getTimer();
timeLeft.stopTime = timeLeft.startTime;
timeLeft.secondsLeft = 0;
timeLeft.current = -1;
timeLeft.stopped = false;
if (props.duration) {
timeLeft.duration = parseInt(props.duration);
}
if (props.textref) {
textref = props.textref;
textfunc = null;
} else if (props.textfunc) {
textfunc = props.textfunc;
textref = null;
}
if (props.cb) {
callback = props.cb;
}
if (typeof(props.format) == "string") {
timeformat = props.format;
}
if (typeof(props.tick_sound) == "string") {
tick_sound = props.tick_sound;
}
running = false;
if (timeLeft.duration > 0) {
this.time_countdown();
}
};
this.time_countdown = function () {
if (timeLeft.stopped) {
return(undefined);
}
var _local4 = Math.max(0, (timeLeft.duration * 1000) - (getTimer() - timeLeft.startTime));
var _local2 = Math.round(_local4 / 1000);
timeLeft.secondsLeft = _local2;
var _local3 = time_format_str(_local2);
if (timeLeft.current != _local3) {
timeLeft.current = _local3;
if (textref) {
textref.text = _local3;
} else if (textfunc) {
textfunc(_local3);
}
if (_local2 <= 5) {
if (typeof(tick_sound) == "string") {
soundFx.play(tick_sound);
}
}
}
if (_local4 == 0) {
this.stopTimer();
if (callback) {
callback();
}
}
return(_local2);
};
this.startTimer = function () {
if (running) {
return(undefined);
}
running = true;
timeLeft.startTime = timeLeft.startTime + (getTimer() - timeLeft.stopTime);
timeLeft.stopped = false;
events.runIt(this);
};
this.stopTimer = function () {
if (!running) {
return(undefined);
}
running = false;
timeLeft.stopTime = getTimer();
timeLeft.stopped = true;
events.stopIt(this);
};
this.stopResetTimer = function () {
this.stopTimer();
this.init();
};
this.run = function () {
this.time_countdown();
};
this.setStopTime = function (t) {
timeLeft.stopTime = parseInt(t);
};
this.setSecondsPassed = function (t) {
timeLeft.startTime = timeLeft.stopTime + ((t - timeLeft.duration) * 1000);
timeLeft.secondsLeft = t;
var _local1 = time_format_str(t);
if (timeLeft.current != _local1) {
timeLeft.current = _local1;
if (textref) {
textref.text = _local1;
} else if (textfunc) {
textfunc(_local1);
}
}
};
this.getSecondsLeft = function () {
return(timeLeft.secondsLeft);
};
this.init(props);
}
function Stopwatch(props) {
function time_format_str(t) {
var _local2 = "";
if (timeformat == "sec") {
_local2 = "" + Math.floor(t);
} else {
_local2 = Math.floor(t / 60) + ":";
t = t % 60;
_local2 = _local2 + ((t < 10) ? ("0" + t) : (t));
}
return(_local2);
}
var running = false;
var textref;
var textfunc;
var timeformat = "time";
var callback;
this.init = function (props) {
wr("stopwatch init");
this.startTime = getTimer();
this.stopTime = 0;
this.current = -1;
this.stopped = false;
this.leadingtext = "";
if (props.duration) {
this.duration = parseInt(props.duration);
}
if (typeof(props.text) == "string") {
this.leadingtext = props.text;
}
if (props.textref) {
textref = props.textref;
textfunc = null;
} else if (props.textfunc) {
textfunc = props.textfunc;
textref = null;
}
if (props.cb) {
callback = props.cb;
}
if (typeof(props.format) == "string") {
timeformat = props.format;
}
running = false;
};
this.time_countup = function () {
if (this.stopped) {
return(undefined);
}
var _local4 = getTimer() - this.startTime;
var _local3 = Math.round(_local4 / 1000);
this.secondsLeft = _local3;
var _local2 = time_format_str(_local3);
if (this.current != _local2) {
this.current = _local2;
if (textref) {
textref.text = (this.leadingtext + " ") + _local2;
} else if (textfunc) {
textfunc(_local2);
}
}
if (this.duration) {
if (_local4 >= (this.duration * 1000)) {
this.stop();
if (callback) {
callback();
}
}
}
return(_local3);
};
this.start = function () {
if (running) {
return(undefined);
}
running = true;
this.startTime = getTimer();
this.stopped = false;
events.runIt(this);
};
this.stop = function () {
if (!running) {
return(undefined);
}
running = false;
this.stopTime = getTimer();
this.stopped = true;
events.stopIt(this);
};
this.stopResetTimer = function () {
this.stop();
this.init();
};
this.run = function () {
this.time_countup();
};
this.init(props);
}
function ScoreAutomat(props) {
function updateScore() {
var _local1 = dest_p - curr_p;
var _local2 = _local1 * speed;
if (Math.abs(_local1) <= 2) {
curr_p = dest_p;
} else {
curr_p = curr_p + _local2;
}
txt_field.text = txt_prefix + Math.round(curr_p);
if (dest_p == curr_p) {
calcReady();
}
}
function calcReady() {
running = false;
}
var running = false;
var speed = 0.4;
var curr_p = 0;
var dest_p = 0;
var txt_field;
var txt_prefix;
this.init = function (props) {
txt_field = props._field;
txt_prefix = props._prefix;
};
this.addScore = function (howMuch) {
running = true;
dest_p = dest_p + howMuch;
};
this.setScore = function (howMuch) {
dest_p = Math.round(howMuch);
curr_p = dest_p;
txt_field.text = txt_prefix + dest_p;
};
this.run = function () {
if (running) {
updateScore();
}
};
this.init(props);
}
function Tween(props) {
function limit_3(a, b, c) {
return(((a < b) ? (b) : (((a > c) ? (c) : (a)))));
}
function computeNextFloat(from, to, ease) {
return(from + ((to - from) * ease));
}
this.running = false;
this.animation = [];
this.callback = null;
this.callback_scope = null;
this.init = function (props) {
};
this.go = function (anim, props) {
this.duration = props.duration || 500;
this.starttime = props.starttime || (new Date().getTime());
this.callback = props.callback;
this.callback_scope = props.callback_scope;
this.animation = anim;
if (Key.isDown(16) && (dev_mode)) {
this.duration = this.duration * 5;
}
this.animate();
var _local2 = 0;
while (_local2 < this.animation.length) {
if (typeof(this.animation[_local2].from._alpha) == "number") {
this.animation[_local2].sprite._visible = true;
}
_local2++;
}
if (!this.running) {
this.running = true;
events.runIt(this);
}
};
this.run = function () {
this.animate();
};
this.animate = function () {
var _local7;
var _local5;
var _local8 = new Date().getTime();
var _local4 = this.animation.length;
var _local2;
var _local3;
_local7 = limit_3(_local8 - this.starttime, 0, this.duration);
_local5 = 0.5 - (0.5 * Math.cos((Math.PI * _local7) / this.duration));
if (_local7 >= this.duration) {
if (this.running) {
this.running = false;
events.stopIt(this);
}
_local2 = 0;
while (_local2 < _local4) {
_local3 = this.animation[_local2].sprite;
for (var _local6 in this.animation[_local2].to) {
_local3[_local6] = this.animation[_local2].to[_local6];
if (_local6 == "_alpha") {
if (this.animation[_local2].to[_local6] < 1) {
_local3._visible = false;
}
}
}
_local2++;
}
if (this.callback) {
this.callback.call(this.callback_scope);
}
} else {
_local2 = 0;
while (_local2 < _local4) {
_local3 = this.animation[_local2].sprite;
for (var _local6 in this.animation[_local2].to) {
_local3[_local6] = computeNextFloat(this.animation[_local2].from[_local6], this.animation[_local2].to[_local6], _local5);
}
_local2++;
}
}
};
this.stop = function () {
if (this.running) {
this.running = false;
events.stopIt(this);
}
};
this.init(props);
}
function Delay(props) {
this.init = function (props) {
this.callback = props.callback;
this.callback_scope = props.callback_scope;
if (typeof(props.frames) == "number") {
this.frame_current = 0;
this.frame_frames = props.frames;
this.run = this.run_frame_delay;
} else if (typeof(props.seconds) == "number") {
this.time_startTime = getTimer();
this.time_duration = props.seconds;
this.run = this.run_time_delay;
} else {
wr("invalid delay...");
wrObj(props);
return(false);
}
events.runIt(this);
};
this.run_frame_delay = function () {
this.frame_current++;
if (this.frame_current >= this.frame_frames) {
this.done();
}
};
this.run_time_delay = function () {
var _local2 = Math.max(0, this.time_duration - ((getTimer() - this.time_startTime) / 1000));
if (_local2 == 0) {
this.done();
}
return(_local2);
};
this.done = function () {
events.stopIt(this);
if (this.callback) {
this.callback.call(this.callback_scope);
}
};
this.init(props);
}
function Pulsate(props) {
this.running = false;
this.sinv = [1, 2, 4, 7, 10, 14, 18, 22, 28, 33, 39, 44, 50, 56, 62, 67, 73, 78, 82, 87, 90, 94, 96, 98, 99, 100, 100, 99, 98, 96, 93, 90, 86, 82, 77, 72, 66, 61, 55, 49, 43, 37, 32, 27, 22, 17, 13, 9, 6, 4, 2, 0];
this.sinlen = this.sinv.length;
this.sinpos = 0;
this.alpha_div = 1;
if (typeof(props.alpha) == "number") {
this.alpha_div = props.alpha / 100;
}
this.mysprite = props.sprite;
this.start = function () {
if (this.running) {
return(undefined);
}
this.running = true;
this.sinpos = 0;
events.runIt(this);
};
this.stop = function () {
if (!this.running) {
return(undefined);
}
this.running = false;
this.mysprite._alpha = 0;
events.stopIt(this);
};
this.run = function () {
this.mysprite._alpha = this.sinv[this.sinpos++] * this.alpha_div;
if (this.sinpos == this.sinlen) {
this.sinpos = 0;
}
};
}
function Draggable(props) {
this.init = function (props) {
this.parent = props.parent;
this.sp = props.sprite;
this.sp_target = props.sp_target || (props.sprite);
this.sp_follow = props.sp_follow;
this.sp.drag_self = this;
this.enable();
};
this.enable = function () {
this.sp.onPress = this.sp_onPress;
this.sp.onRelease = this.sp_onRelease;
this.sp.onReleaseOutside = this.sp_onReleaseOutside;
};
this.disable = function () {
delete this.sp.onPress;
delete this.sp.onRelease;
delete this.sp.onReleaseOutside;
delete this.sp.onMouseMove;
};
this.sp_onPress = function () {
this.ox = this.drag_self.sp_target._x - _root._xmouse;
this.oy = this.drag_self.sp_target._y - _root._ymouse;
if (this.drag_self.sp_follow) {
this.follow_ox = this.drag_self.sp_target._x - _root._xmouse;
this.follow_oy = this.drag_self.sp_target._y - _root._ymouse;
}
this.onMouseMove = function () {
this.drag_self.sp_target._x = _root._xmouse + this.ox;
this.drag_self.sp_target._y = _root._ymouse + this.oy;
if (this.drag_self.sp_follow) {
this.drag_self.sp_follow._x = _root._xmouse + this.follow_ox;
this.drag_self.sp_follow._y = _root._ymouse + this.follow_oy;
}
};
this.drag_self.start_drag();
};
this.sp_onRelease = function () {
this.drag_self.stop_drag();
};
this.sp_onReleaseOutside = function () {
this.drag_self.stop_drag();
};
this.start_drag = function () {
if (this.parent.draggable_start) {
this.parent.draggable_start(this.sp_target);
}
};
this.stop_drag = function () {
delete this.sp.onMouseMove;
if (this.parent.draggable_dropped) {
this.parent.draggable_dropped(this.sp_target);
}
};
this.init(props);
}
function Emoticons(props) {
this.moods = ["mad", "tired", "superior", "happy", "surprised"];
this.mood_active = false;
this.mood_duration = 5;
this.current_mood = "neutral";
this.init = function (props) {
this.parent = props.parent;
events.runIt(this);
};
this.setMood = function (m, t) {
wr("setMood", m, t);
game.table.local_player.avatar.setMood(m);
this.click_time = getTimer();
this.mood_duration = t;
this.mood_active = true;
this.current_mood = m;
};
this.getMood = function () {
wr("emoticons.getMood");
return(this.current_mood);
};
this.reset_mood = function () {
game.table.local_player.avatar.setMood("neutral");
this.mood_active = false;
this.current_mood = "neutral";
};
this.run = function () {
if (this.mood_active) {
var _local2 = Math.max(0, this.mood_duration - ((getTimer() - this.click_time) / 1000));
if (_local2 == 0) {
this.reset_mood();
}
}
};
this.init(props);
}
function HourGlass(props) {
function limit_3(a, b, c) {
return(((a < b) ? (b) : (((a > c) ? (c) : (a)))));
}
function computeNextFloat(from, to, perc) {
return(from + ((to - from) * perc));
}
this.running = false;
this.top_start_y = -41;
this.top_end_y = 0;
this.btm_start_y = 59;
this.btm_end_y = 11;
this.callback = null;
this.callback_scope = null;
this.blink_speed = 4;
this.blink_count = 0;
this.init = function (props) {
this.sp = sprites.create({member:"hourglass", x:props.x, y:props.y, alpha:0, level:11});
this.sp._xscale = props.scale;
this.sp._yscale = props.scale;
this.mask_top = this.sp.mask_top;
this.mask_btm = this.sp.mask_bottom;
this.sand = this.sp.sand;
this.red = this.sp.red;
my_color = new Color(this.sp);
my_color.setRGB(7897476);
this.tween_obj = new Tween();
this.mask_top.stop();
this.mask_btm.stop();
this.sand.stop();
this.sand._visible = false;
};
this.start = function (props) {
this.start_percent = (props.percent / 100) || 1;
this.duration = props.duration || 5000;
this.starttime = new Date().getTime();
this.callback = props.callback;
this.callback_scope = props.callback_scope;
this.t_y = computeNextFloat(this.top_start_y, this.top_end_y, 1 - this.start_percent);
this.b_y = computeNextFloat(this.btm_start_y, this.btm_end_y, 1 - this.start_percent);
this.mask_top.gotoAndPlay(1);
this.mask_btm.gotoAndPlay(1);
this.sand.gotoAndPlay(1);
this.sand._visible = true;
if (!this.running) {
this.running = true;
events.runIt(this);
var _local3 = [{from:{_rotation:180, _alpha:10}, to:{_rotation:0, _alpha:100}, sprite:this.sp}];
this.tween_obj.go(_local3, {duration:250});
}
this.run();
};
this.stop = function () {
this.mask_top.stop();
this.mask_btm.stop();
this.sand.stop();
this.sand._visible = false;
if (this.running) {
this.running = false;
events.stopIt(this);
var _local2 = [{from:{_rotation:0, _alpha:100}, to:{_rotation:-180, _alpha:0}, sprite:this.sp}];
this.tween_obj.go(_local2, {duration:250});
}
};
this.run = function () {
var _local6 = new Date().getTime();
var _local3 = limit_3(_local6 - this.starttime, 0, this.duration);
var _local2 = _local3 / this.duration;
if (_local3 >= this.duration) {
this.stop();
this.mask_top._y = this.top_end_y;
this.mask_btm._y = this.btm_end_y;
if (this.callback) {
this.callback.call(this.callback_scope);
}
} else {
var _local4 = computeNextFloat(this.t_y, this.top_end_y, _local2);
var _local5 = computeNextFloat(this.b_y, this.btm_end_y, _local2);
this.mask_top._y = _local4;
this.mask_btm._y = _local5;
if (_local2 > 0.85) {
this.blink_count++;
if (this.blink_speed == this.blink_count) {
this.blink_count = 0;
this.sp._visible = !this.sp._visible;
}
}
}
};
this.show = function () {
};
this.hide = function () {
};
this.kill = function () {
this.tween_obj.stop();
sprites.remove(this.sp);
if (this.running) {
events.stopIt(this);
}
};
this.init(props);
}
function ChatClient(props) {
this.bubbles = [];
this.chat_enabled = false;
this.init = function (props) {
this.positions = props.positions;
this.chat_box = sprites.create({member:"chat_box", x:this.positions.chat_box[0], y:this.positions.chat_box[1], visible:false, alpha:0, level:19});
this.chat_box.orig_w = this.chat_box._width;
this.chat_box.orig_h = this.chat_box._height;
this.chat_box.bg.onRelease = function () {
};
this.chat_box.bg.useHandCursor = false;
this.chat_icon = sprites.create({member:"chat_icon", x:this.positions.chat_icon[0], y:this.positions.chat_icon[1], visible:false, level:19});
this.open_btn = new ClickButton({sp:this.chat_icon, id:"open", callback_scope:this, callback:this.show_panel, padding:4, over_alpha:60});
this.chat_icon.orig_w = this.chat_icon._width;
this.chat_icon.orig_h = this.chat_icon._height;
this.str_to_fast = "Oooops!";
this.field_in = this.chat_box.chat_in;
this.button_send = this.chat_box.send_button;
this.speedlimit = {active:false, last:0, sum:0, cnt:0, limit:1000};
this.tween_obj = new Tween();
if (typeof(props.username) == "string") {
this.username = props.username;
}
this.field_in.maxChars = 40;
this.field_in.active = false;
this.field_in.onSetFocus = function () {
this.active = true;
};
this.field_in.onKillFocus = function () {
this.active = false;
};
this.onKeyUp = function () {
if (!this.chat_enabled) {
return(undefined);
}
if (!this.field_in.active) {
if (Key.getCode() == 32) {
this.show_panel();
}
}
};
this.onKeyDown = function () {
if (!this.chat_enabled) {
return(undefined);
}
if (this.field_in.active) {
if (this.field_in.text == "") {
if ((Key.getCode() == 13) || (Key.getCode() == 32)) {
this.hide_panel();
}
} else if (Key.getCode() == 13) {
this.msg_send();
}
}
};
Key.addListener(this);
this.send_btn = new ClickButton({sp:this.button_send, callback_scope:this, callback:this.msg_send, over_alpha:72});
this.field_in.text = "";
};
this.set_chat_to_fast_msg = function (str) {
this.str_to_fast = str;
};
this.msg_send = function () {
var _local2 = getTimer();
if (this.speedlimit.active) {
if (_local2 > (this.speedlimit.last + (this.speedlimit.limit * 5))) {
this.speedlimit.active = false;
} else {
return(undefined);
}
}
this.speedlimit.cnt++;
this.speedlimit.sum = this.speedlimit.sum + (_local2 - this.speedlimit.last);
this.speedlimit.last = _local2;
if (this.speedlimit.cnt >= 3) {
if (this.speedlimit.sum < (this.speedlimit.limit * 3)) {
this.draw_msg(game.table.local_player.playernum, this.str_to_fast);
this.speedlimit.active = true;
}
this.speedlimit.cnt = 0;
this.speedlimit.sum = 0;
if (this.speedlimit.active) {
return(undefined);
}
}
var _local3 = this.field_in.text;
if (_local3 != "") {
game.network.send_string((("MSG " + game.table.local_player.playernum) + ",") + _local3);
this.draw_msg(game.table.local_player.playernum, _local3);
soundFx.play("tone_a.aif", false, 60);
}
this.hide_panel();
};
this.msg_receive = function (dat) {
var _local2 = dat.split(",", 2);
var _local3 = parseInt(_local2[0]);
var _local4 = _local2[1];
this.draw_msg(_local3, _local4);
soundFx.play("tone_b.aif", false, 60);
};
this.focus_chat = function () {
Selection.setFocus(this.field_in);
};
this.show = function () {
this.chat_enabled = true;
this.chat_icon._visible = true;
};
this.hide = function () {
this.chat_enabled = false;
this.chat_icon._visible = false;
this.chat_box._visible = false;
};
this.show_panel = function () {
this.field_in.text = "";
var _local2 = [{to:{_alpha:0, _x:this.positions.chat_box[0], _y:this.positions.chat_box[1], _width:this.chat_box.orig_w, _height:this.chat_box.orig_h}, from:{_alpha:100, _x:this.positions.chat_icon[0], _y:this.positions.chat_icon[1], _width:this.chat_icon.orig_w, _height:this.chat_icon.orig_h}, sprite:this.chat_icon}, {to:{_alpha:100, _x:this.positions.chat_box[0], _y:this.positions.chat_box[1], _width:this.chat_box.orig_w, _height:this.chat_box.orig_h}, from:{_alpha:0, _x:this.positions.chat_icon[0], _y:this.positions.chat_icon[1], _width:this.chat_icon.orig_w, _height:this.chat_icon.orig_h}, sprite:this.chat_box}];
this.tween_obj.go(_local2, {duration:300});
this.focus_chat();
};
this.hide_panel = function () {
var _local2 = [{to:{_alpha:0, _x:this.positions.chat_icon[0], _y:this.positions.chat_icon[1], _width:this.chat_icon.orig_w, _height:this.chat_icon.orig_h}, from:{_alpha:100, _x:this.positions.chat_box[0], _y:this.positions.chat_box[1], _width:this.chat_box.orig_w, _height:this.chat_box.orig_h}, sprite:this.chat_box}, {to:{_alpha:100, _x:this.positions.chat_icon[0], _y:this.positions.chat_icon[1], _width:this.chat_icon.orig_w, _height:this.chat_icon.orig_h}, from:{_alpha:0, _x:this.positions.chat_box[0], _y:this.positions.chat_box[1], _width:this.chat_box.orig_w, _height:this.chat_box.orig_h}, sprite:this.chat_icon}];
this.tween_obj.go(_local2, {duration:300});
};
this.draw_msg = function (pno, str) {
if (this.bubbles[pno] != undefined) {
if (this.bubbles[pno].step < 3) {
this.bubbles[pno].step = 2;
this.bubbles[pno].is_orphan = true;
this.bubbles[pno].next_step();
}
}
var _local3 = game.gui.chatbubble_positions[game.table.players[pno].seatnum];
var _local4 = _local3[1] < 350;
var movement = (_local4 ? -1 : 1);
var _local5 = _local3[0];
var tmp_y = (_local3[1] + (_local4 ? -10 : 10));
var _local6 = (_local4 ? "chat_bubble_flipped" : "chat_bubble");
var _local2 = sprites.create({member:_local6, x:_local5, y:tmp_y, alpha:0, level:19});
_local2.txt.text = str;
var _local8 = (_local2.txt._height - _local2.txt.textHeight) / 2;
if (_local8 > 3) {
_local2.txt._y = _local2.txt._y + (((_local2.txt._height - _local2.txt.textHeight) / 2) - 2);
}
_local2.tween_obj = new Tween();
this.bubbles[pno] = _local2;
_local2.pno = pno;
_local2.parent = this;
_local2.step = 0;
_local2.next_step = function () {
if (this.step == 0) {
var _local2 = [{from:{_alpha:0, _y:tmp_y}, to:{_alpha:100, _y:tmp_y - (15 * movement)}, sprite:this}];
this.tween_obj.go(_local2, {duration:400, callback_scope:this, callback:this.next_step});
} else if (this.step == 1) {
var _local2 = [{from:{_y:this._y}, to:{_y:this._y - (5 * movement)}, sprite:this}];
this.tween_obj.go(_local2, {duration:2000, callback_scope:this, callback:this.next_step});
} else if (this.step == 2) {
var _local2 = [{from:{_y:this._y, _alpha:100}, to:{_y:this._y - (10 * movement), _alpha:0}, sprite:this}];
this.tween_obj.go(_local2, {duration:300, callback_scope:this, callback:this.next_step});
} else if (this.step == 3) {
this.tween_obj.stop();
if (!this.is_orphan) {
this.parent.bubbles[this.pno] = null;
}
sprites.remove(this);
}
this.step++;
};
_local2.next_step();
};
this.init(props);
}
function Pile(props) {
this.init = function (props) {
this.parent = props.parent;
this.x = props.x;
this.y = props.y;
this.cards = [];
this.level_start = 3;
};
this.add_card = function (_card, _player) {
var _local6 = (this.parent.pile_positions[_player.seatnum][0] + random(6)) - 3;
var _local4 = (this.parent.pile_positions[_player.seatnum][1] + random(6)) - 3;
if (_player.seatnum == 1) {
var _local7 = (this.parent.pile_positions[_player.seatnum][2] + 30) + (random(20) - 10);
} else if (_player.seatnum == 3) {
var _local7 = (this.parent.pile_positions[_player.seatnum][2] - 30) - (random(20) - 10);
} else {
var _local7 = this.parent.pile_positions[_player.seatnum][2] + (random(14) - 7);
}
var _local8 = this.parent.pile_positions[_player.seatnum][3];
this.cards.push(_card);
_card.set_parent(this);
_card.last_hand = _player.hand;
var _local5 = function () {
this.show_fade_shadow();
this.last_hand.resort_hand_after_release();
this.toLevel(4);
this.parent.z_sort_cards();
};
_card.show_simple_shadow();
_card.animate_to({x:_local6, y:_local4, v:_local7, scale:_local8, cb:_local5, cb_scope:_card});
};
this.z_sort_cards = function () {
var _local3 = [];
var _local2 = 0;
while (_local2 < this.cards.length) {
_local3.push(this.cards[_local2].get_sprite());
_local2++;
}
sprites.sort(_local3);
};
this.get_size = function () {
return(this.cards.length);
};
this.get_cards = function () {
return(this.cards);
};
this.get_color = function () {
return(this.cards[0].color);
};
this.purge = function () {
this.cards = [];
};
this.enable = function () {
};
this.disable = function () {
};
this.show = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].show();
_local2++;
}
};
this.hide = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].hide();
_local2++;
}
};
this.kill = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].kill();
_local2++;
}
};
this.init(props);
}
function Deck(props) {
this.init = function (props) {
this.parent = props.parent;
this.x = props.x;
this.y = props.y;
this.v = props.v + (random(14) - 7);
this.scale = props.scale;
this.trump_x = props.trump_x;
this.trump_y = props.trump_y;
this.trump_v = props.trump_v;
this.trump_scale = props.trump_scale;
this.trump_card = null;
this.cards = [];
props.num_cards = 52;
var _local8 = [];
var _local6 = this.x;
var _local5 = this.y;
var _local9 = true;
if (props.num_cards > 0) {
var _local3 = 0;
while (_local3 < props.num_cards) {
var _local2 = new Card({x:_local6, y:_local5, v:this.v, scale:this.scale, parent_sp:props.parent_sp, parent:this});
_local2.hide();
this.cards.push(_local2);
_local8.push(_local2.get_sprite());
if ((_local3 % 8) == 7) {
_local5 = _local5 - 1;
_local6 = _local6 - 1;
}
_local3++;
}
}
sprites.sort(_local8);
this.cards[this.cards.length - 1].show();
};
this.set_trump = function (carddata) {
if (this.cards.length > 0) {
var _local2 = this.cards[0];
this.cards.splice(0, 1);
_local2.setCard({color:carddata.charAt(1), value:carddata.charAt(0)});
_local2.setTurnedUp(true);
_local2.animate_to({x:this.trump_x, y:this.trump_y, v:this.trump_v, scale:this.trup_scale});
this.trump_card = _local2;
}
};
this.get_trump_card = function () {
var _local2 = this.trump_card;
this.trump_card = null;
return(_local2);
};
this.get_card = function () {
var _local2 = null;
if (this.cards.length > 0) {
_local2 = this.cards[this.cards.length - 1];
this.cards.splice(this.cards.length - 1, 1);
_local2.show();
if (this.cards.length > 0) {
this.cards[this.cards.length - 1].show();
}
} else if (this.trump_card) {
_local2 = this.trump_card;
this.trump_card = null;
}
return(_local2);
};
this.get_length = function () {
return(this.cards.length);
};
this.enable = function () {
};
this.disable = function () {
};
this.show = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
if ((_local2 % 8) == 7) {
this.cards[_local2].show();
}
this.cards[_local2].show_simple_shadow();
_local2++;
}
if (this.cards.length > 0) {
this.cards[this.cards.length - 1].show();
}
};
this.hide = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].hide();
_local2++;
}
if (this.trump_card != null) {
this.trump_card.hide();
}
};
this.kill = function () {
};
this.init(props);
}
function Card(props) {
this.value = null;
this.color = null;
this.turned_up = true;
this.card_back = null;
this.card_front = null;
this.init = function (props) {
global_card_count++;
this.parent = props.parent;
this.x = props.x;
this.y = props.y;
this.v = ((props.v != undefined) ? (props.v) : 0);
this.scale = props.scale;
this.scale = ((typeof(props.scale) == "number") ? (props.scale) : 100);
this.tween = new Tween();
this.selected = false;
this.group = sprites.create({x:this.x, y:this.y, level:8, parent_sprite:props.parent_sp});
this.card_back = sprites.create({member:"card_bg", parent_sprite:this.group, x:0, y:0});
this.card_front = sprites.create({member:"card_fg", parent_sprite:this.group, x:0, y:0, visible:false});
this.card_front.shadow._visible = true;
this.card_front.sharpshadow._visible = false;
this.card_back.shadow._visible = true;
this.card_back.sharpshadow._visible = false;
this.card_back._x = this.card_back._x - (this.card_back._width / 2);
this.card_back._y = this.card_back._y - (this.card_back._height / 2);
this.card_front._x = this.card_front._x - (this.card_front._width / 2);
this.card_front._y = this.card_front._y - (this.card_front._height / 2);
this.card_front.gotoAndStop(1);
this.setTurnedUp(false);
this.group.parent = this;
this.group._rotation = this.v;
this.group.set_scale = function (n) {
this._xscale = n;
this._yscale = n;
};
this.group.addProperty("scale", function () {
return(this._xscale);
}, this.group.set_scale);
this.group.set_scale(this.scale);
this.group.onRollOver = function () {
this.parent.mouse_over(this);
};
this.group.onDragOver = function () {
this.parent.mouse_over(this);
};
this.group.onRollOut = function () {
this.parent.mouse_out(this);
};
this.group.onDragOut = function () {
this.parent.mouse_out(this);
};
this.group.useHandCursor = false;
this.width = this.card_back._width;
this.height = this.card_back._height;
};
this.mouse_over = function (sp) {
this.parent.mouse_over(this);
};
this.mouse_out = function () {
this.parent.mouse_out(this);
};
this.set_position = function (x, y) {
this.group._x = (this.x = x);
this.group._y = (this.y = y);
};
this.set_parent = function (p) {
this.parent = p;
};
this.animate_to = function (props) {
var _local5 = ((typeof(props.duration) == "number") ? (props.duration) : 350);
var _local3 = {from:{}, to:{}, sprite:this.group};
if (typeof(props.x) == "number") {
_local3.to._x = props.x;
_local3.from._x = this.group._x;
this.x = props.x;
}
if (typeof(props.y) == "number") {
_local3.to._y = props.y;
_local3.from._y = this.group._y;
this.y = props.y;
}
if (typeof(props._y) == "number") {
_local3.to._y = props._y;
_local3.from._y = this.group._y;
}
if (typeof(props.v) == "number") {
_local3.to._rotation = props.v;
_local3.from._rotation = this.v;
this.v = props.v;
}
if (typeof(props.scale) == "number") {
_local3.to.scale = props.scale;
_local3.from.scale = this.group._xscale;
this.scale = props.scale;
}
var _local4 = [_local3];
this.tween.go(_local4, {duration:_local5, callback:props.cb, callback_scope:props.cb_scope});
};
this.move_to = function (props) {
var _local6 = ((typeof(props.x) == "number") ? (props.x) : (this.group._x));
var _local5 = ((typeof(props.y) == "number") ? (props.y) : (this.group._y));
var _local3 = ((typeof(props.v) == "number") ? (props.v) : (this.group._rotation));
var _local4 = ((typeof(props.scale) == "number") ? (props.scale) : (this.group._xscale));
this.group._x = (this.x = _local6);
this.group._y = (this.y = _local5);
this.group._rotation = (this.v = _local3);
this.group._yscale = (this.group._xscale = (this.scale = _local4));
};
this.stop_anim = function () {
if (this.tween.running) {
this.tween.stop();
}
};
this.activate_click = function () {
this.group.onRelease = function () {
this.parent.card_click();
};
this.group.useHandCursor = true;
};
this.deactivate_click = function () {
delete this.group.onRelease;
this.group.useHandCursor = false;
};
this.getlevel = function () {
return(this.group.getDepth());
};
this.toLevel = function (l) {
this.group.toLevel(l);
};
this.setCard = function (cardprops) {
if ((cardprops.color == "x") || (cardprops.value == "x")) {
return(undefined);
}
this.color = cardprops.color;
this.value = cardprops.value;
this.card_front.gotoAndStop(this.getCardFgOffset(this.color, this.value));
this.group._visible = true;
};
this.setTurnedUp = function (_turned_up) {
if (this.turned_up != _turned_up) {
this.switchSide();
}
};
this.switchSide = function () {
if (this.turned_up) {
this.turned_up = false;
this.card_front._visible = false;
this.card_back._visible = true;
} else {
this.turned_up = true;
this.card_front._visible = true;
this.card_back._visible = false;
}
};
this.card_click = function () {
this.parent.doAction(this, "args...");
};
this.enable = function () {
};
this.disable = function () {
};
this.show = function () {
this.group._visible = true;
};
this.show_simple_shadow = function () {
if (this.card_front._visible) {
this.card_front.shadow._visible = false;
this.card_front.sharpshadow._visible = true;
} else if (this.card_back._visible) {
this.card_back.shadow._visible = false;
this.card_back.sharpshadow._visible = true;
}
};
this.show_fade_shadow = function () {
if (this.card_front._visible) {
this.card_front.shadow._visible = true;
this.card_front.sharpshadow._visible = false;
} else if (this.card_back._visible) {
this.card_back.shadow._visible = true;
this.card_back.sharpshadow._visible = false;
}
};
this.hide = function () {
this.group._visible = false;
};
this.get_sprite = function () {
return(this.group);
};
this.kill = function () {
sprites.remove(this.card_front);
sprites.remove(this.card_back);
sprites.remove(this.group);
global_card_count--;
};
this.getCardFgOffset = function (_color, _value) {
var _local2 = 0;
switch (_color) {
case "S" :
break;
case "C" :
_local2 = 13;
break;
case "H" :
_local2 = 26;
break;
case "D" :
_local2 = 39;
}
return(this.valueToInt(_value) + _local2);
};
this.getValue = function () {
return(this.valueToInt(this.value));
};
this.valueToInt = function (_value) {
var _local2 = parseInt(_value);
if ((_local2 > 0) && (_local2 < 10)) {
return(_local2);
}
var _local1 = {};
_local1.T = 10;
_local1.J = 11;
_local1.Q = 12;
_local1.K = 13;
_local1.A = 14;
return(_local1[_value]);
};
this.init(props);
}
function Trick(props) {
this.init = function (props) {
this.parent = props.parent;
this.cards = props.cards;
this.points = props.points;
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].set_parent(this);
_local2++;
}
var _local3 = this.parent.get_trick_pos();
this.x = _local3.x;
this.y = _local3.y;
this.v = _local3.v;
};
this.animate_to_targetpos = function () {
var _local5 = function () {
this.hide();
};
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].setTurnedUp(false);
this.cards[_local2].toLevel(3);
this.cards[_local2].show_simple_shadow();
this.cards[_local2].animate_to({x:this.x, y:this.y, v:this.v, cb:_local5, cb_scope:this.cards[_local2]});
_local2++;
}
soundFx.play("card_sound_6.aif", false, 80);
};
this.z_sort_cards = function () {
var _local3 = [];
var _local2 = 0;
while (_local2 < this.cards.length) {
_local3.push(this.cards[_local2].get_sprite());
_local2++;
}
sprites.sort(_local3);
};
this.get_size = function () {
return(this.cards.length);
};
this.get_sprite = function () {
return(this.cards[0].get_sprite());
};
this.get_cards = function () {
return(this.cards);
};
this.purge = function () {
this.cards = [];
};
this.enable = function () {
};
this.disable = function () {
};
this.show = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].show();
_local2++;
}
};
this.hide = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].hide();
_local2++;
}
};
this.kill = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].kill();
_local2++;
}
};
this.init(props);
}
function Hand(props) {
this.enabled = false;
this.cards = [];
this.is_over = false;
this.mouse_over_cardindex = -1;
this.size_min = 140;
this.size_max = 155;
this.size_span = 40;
this.amplitude = 4;
this.ratio = (Math.PI/2) / this.size_span;
this.amplitude_y = 12;
this.color_counts = {};
var center_x_displacement = 16;
this.init = function (props) {
this.parent = props.parent;
this.set_pos(props.x, props.y);
this.color_counts.S = 0;
this.color_counts.D = 0;
this.color_counts.H = 0;
this.color_counts.C = 0;
events.runIt(this);
};
this.set_pos = function (x, y, v, scale) {
this.x = x;
this.y = y;
this.v = v;
this.scale = scale;
};
this.deal_cards = function (carddata) {
var _local2 = 0;
while (_local2 < carddata.length) {
this.get_card(this.x + (this.cards.length * 32), this.y, {color:carddata.charAt(_local2 + 1), value:carddata.charAt(_local2)});
_local2 = _local2 + 2;
}
};
this.resort = function (card_cb, dur) {
var _local13 = (this.parent.local ? 3 : 5);
var _local6 = (this.parent.local ? 600 : 150);
var _local5 = 0;
_local5 = _local5 - ((_local13 * (this.cards.length - 1)) / 2);
var _local4 = 0;
while (_local4 < this.cards.length) {
var _local3 = _local6 * Math.sin((_local5 * Math.PI) / 180);
var _local2 = _local6 - (_local6 * Math.cos((_local5 * Math.PI) / 180));
switch (this.parent.seatnum) {
case 0 :
_local3 = this.x + _local3;
_local2 = this.y + _local2;
break;
case 1 :
var _local7 = this.x - _local2;
_local2 = this.y + _local3;
_local3 = _local7;
break;
case 2 :
_local3 = this.x - _local3;
_local2 = this.y - _local2;
break;
case 3 :
_local7 = this.x + _local2;
_local2 = this.y - _local3;
_local3 = _local7;
}
this.cards[_local4].hand_angle = _local5;
this.cards[_local4].animate_to({x:_local3, y:_local2, v:_local5 + this.v, scale:this.scale, duration:dur, cb:card_cb, cb_scope:this.cards[_local4]});
_local5 = _local5 + _local13;
_local4++;
}
};
this.move_card_to_pos = function (card) {
var _local8 = 3;
var _local6 = 600;
var _local3 = 0;
_local3 = _local3 - ((_local8 * (this.cards.length - 1)) / 2);
var _local2 = 0;
while (_local2 < this.cards.length) {
if (this.cards[_local2] == card) {
_local3 = _local3 + (_local2 * _local8);
var _local5 = _local6 * Math.sin((_local3 * Math.PI) / 180);
var _local4 = _local6 - (_local6 * Math.cos((_local3 * Math.PI) / 180));
_local3 = this.v + _local3;
_local5 = this.x + _local5;
_local4 = this.y + _local4;
this.cards[_local2].move_to({x:_local5, y:_local4, v:_local3, scale:this.scale});
return(undefined);
}
_local2++;
}
};
this.deal = function (_card) {
this.z_sort_cards();
var _local6 = (this.parent.local ? 3 : 5);
var _local5 = (this.parent.local ? 600 : 150);
var _local4 = ((-_local6) * 12) / 2;
_local4 = _local4 + ((this.cards.length - 1) * _local6);
var _local3 = _local5 * Math.sin((_local4 * Math.PI) / 180);
var _local2 = _local5 - (_local5 * Math.cos((_local4 * Math.PI) / 180));
switch (this.parent.seatnum) {
case 0 :
_local3 = this.x + _local3;
_local2 = this.y + _local2;
break;
case 1 :
var _local8 = this.x - _local2;
_local2 = this.y + _local3;
_local3 = _local8;
break;
case 2 :
_local3 = this.x - _local3;
_local2 = this.y - _local2;
break;
case 3 :
_local8 = this.x + _local2;
_local2 = this.y - _local3;
_local3 = _local8;
}
_card.animate_to({x:_local3, y:_local2, v:_local4 + this.v, scale:this.scale, duration:250, cb:_card.show_fade_shadow, cb_scope:_card});
soundFx.play("card_sound_2.aif", false, 70);
};
this.get_no_cards = function () {
return(this.cards.length);
};
this.get_random_card = function () {
return(this.cards[random.rangeFromSeed(0, this.cards.length - 1)]);
};
this.get_card = function (x, y, cardprops) {
var _local2 = this.parent.parent.deck.get_card();
_local2.set_parent(this);
_local2.setCard(cardprops);
this.add_card(_local2);
};
this.create_card = function (x, y, cardprops) {
var _local2 = new Card({x:x, y:y, parent:this});
_local2.setCard(cardprops);
this.add_card(_local2);
};
this.add_card = function (_card) {
if (this.parent.local && (this.enabled)) {
_card.activate_click();
}
_card.selected = false;
this.color_counts[_card.color]++;
_card.set_parent(this);
this.cards.push(_card);
this.deal(_card);
};
this.show_cards = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].setTurnedUp(true);
_local2++;
}
this.suite_sort_cards();
this.z_sort_cards();
this.resort();
};
this.doAction = function (obj, args) {
var _local11 = 600;
var _local3;
var _local4 = 1000;
var _local6 = null;
var _local7 = -1;
var _local5;
var _local9 = this.xmouse - this.x;
var _local8 = this.ymouse - (this.y + _local11);
var _local10 = Math.sqrt((_local9 * _local9) + (_local8 * _local8));
if (_local10 != 0) {
_local9 = _local9 / _local10;
_local8 = _local8 / _local10;
_local5 = (Math.asin(_local9) * 180) / Math.PI;
_local5 = _local5 + 1.9;
if (_local8 > 0) {
_local5 = -_local5;
}
}
var _local2 = 0;
while (_local2 < this.cards.length) {
_local3 = Math.abs(_local5 - this.cards[_local2].hand_angle);
if (_local3 < _local4) {
_local4 = _local3;
_local7 = _local2;
_local6 = this.cards[_local2];
}
_local2++;
}
this.parent.card_clicked(this, _local6);
};
this.mouse_over = function (card) {
this.is_over = true;
};
this.mouse_out = function (card) {
this.is_over = false;
};
this.mouse_over_index = function (n) {
wr("hand.mouse_over_index:", n);
var _local2 = 0;
while (_local2 <= n) {
if (this.cards[_local2].selected) {
n++;
}
_local2++;
}
if (this.mouse_over_cardindex != n) {
if (this.mouse_over_cardindex >= 0) {
var _local6 = new Tween();
var _local4 = this.cards[this.mouse_over_cardindex];
var _local9 = [{to:{_x:_local4.x, _y:_local4.y}, from:{_x:_local4.group._x, _y:_local4.group._y}, sprite:_local4.group}];
_local6.go(_local9, {duration:350});
}
this.mouse_over_cardindex = n;
if (n >= 0) {
var _local4 = this.cards[this.mouse_over_cardindex];
var _local5 = ((Math.PI*2) * _local4.group._rotation) / 360;
var _local7 = _local4.x + (6 * Math.sin(_local5));
var _local8 = _local4.y - (6 * Math.cos(_local5));
var _local6 = new Tween();
var _local9 = [{to:{_x:_local7, _y:_local8}, from:{_x:_local4.group._x, _y:_local4.group._y}, sprite:_local4.group}];
_local6.go(_local9, {duration:350});
}
}
};
this.set_card_selected = function (c) {
c.selected = c.selected ^ true;
var _local3 = (c.selected ? 10 : 0);
var _local2 = ((Math.PI*2) * c.group._rotation) / 360;
var _local5 = c.x + (_local3 * Math.sin(_local2));
var _local6 = c.y - (_local3 * Math.cos(_local2));
var _local4 = new Tween();
var _local7 = [{to:{_x:_local5, _y:_local6}, from:{_x:c.group._x, _y:c.group._y}, sprite:c.group}];
_local4.go(_local7, {duration:350});
};
this.get_card_by_col_val = function (col, val) {
var _local3 = 0;
while (_local3 < this.cards.length) {
var _local2 = this.cards[_local3];
if ((_local2.color == col) && (_local2.value == val)) {
return(_local2);
}
_local3++;
}
wr("card fetch", col, val, "failed!");
return(null);
};
this.get_card_by_index = function (i) {
if ((i < 0) || (i >= this.cards.length)) {
return(null);
}
return(this.cards[i]);
};
this.get_card_index = function (obj) {
var _local2 = 0;
while (_local2 < this.cards.length) {
if (obj == this.cards[_local2]) {
return(_local2);
}
_local2++;
}
};
this.release_card = function (obj) {
this.mouse_over_cardindex = -1;
var _local2 = 0;
while (_local2 < this.cards.length) {
if (obj == this.cards[_local2]) {
this.color_counts[obj.color]--;
this.cards.splice(_local2, 1);
obj.deactivate_click();
obj.stop_anim();
soundFx.play("click_sound_2.aif", false, 65);
return(obj);
}
_local2++;
}
};
this.add_card_from_cardbox = function (_card) {
this.color_counts[_card.color]++;
_card.set_parent(this);
this.cards.push(_card);
this.suite_sort_cards();
this.z_sort_cards();
this.move_card_to_pos(_card);
this.resort();
};
this.add_cards_from_other_player = function (_cards) {
var _local3 = 0;
while (_local3 < _cards.length) {
var _local2 = _cards[_local3];
this.color_counts[_local2.color]++;
_local2.set_parent(this);
this.cards.push(_local2);
if (this.parent.local) {
_local2.setTurnedUp(true);
}
_local3++;
}
this.suite_sort_cards();
this.z_sort_cards();
this.resort(cb);
};
this.resort_hand_after_release = function () {
if (game.table.deck.get_length() == 0) {
this.resort();
}
};
this.check_inside_rect = function () {
var _local2 = this.cards[this.cards.length - 1];
var _local3 = this.cards[0];
var _local4 = (((this.xmouse > (_local3.x - (_local3.group._width / 2))) && (this.xmouse < (_local2.x + (_local2.group._width / 2)))) && (this.ymouse > (_local2.y - (_local2.group._height / 2)))) && (this.ymouse < (_local2.y + (_local2.group._height / 2)));
return(_local4);
};
this.run = function () {
if (this.parent.local) {
this.xmouse = _root._xmouse;
this.ymouse = _root._ymouse;
if (this.enabled) {
if (this.check_inside_rect()) {
var _local20 = 600;
var _local5;
var _local10 = 1000;
var _local13 = null;
var _local9 = -1;
var _local11;
var _local4 = this.xmouse - this.x;
var _local15 = this.ymouse - (this.y + _local20);
var _local16 = Math.sqrt((_local4 * _local4) + (_local15 * _local15));
if (_local16 != 0) {
_local4 = _local4 / _local16;
_local15 = _local15 / _local16;
_local11 = (Math.asin(_local4) * 180) / Math.PI;
_local11 = _local11 + 1.9;
if (_local15 > 0) {
_local11 = -_local11;
}
}
var _local3 = 0;
while (_local3 < this.cards.length) {
_local5 = Math.abs(_local11 - this.cards[_local3].hand_angle);
if (_local5 < _local10) {
_local10 = _local5;
_local9 = _local3;
_local13 = this.cards[_local3];
}
_local3++;
}
var _local14 = this.cards[_local9];
var _local19 = ((Math.PI*2) * _local14.group._rotation) / 360;
var _local12 = _local14.x + (this.amplitude_y * Math.sin(_local19));
var _local21 = _local14.y - (this.amplitude_y * Math.cos(_local19));
if (_local9 != this.mouse_over_cardindex) {
var _local17 = !_local14.tween.running;
if (this.mouse_over_cardindex >= 0) {
var _local18 = this.cards[this.mouse_over_cardindex];
_local17 = _local17 & (!_local18.tween.running);
if (_local17) {
_local18.animate_to({_y:_local18.y, duration:100});
}
}
if (_local17) {
this.mouse_over_cardindex = _local9;
_local14.animate_to({_y:_local21, duration:100});
game.network.send_string((("GMO " + this.parent.playernum) + ",") + this.mouse_over_cardindex);
}
}
_local3 = 0;
while (_local3 < this.cards.length) {
var _local6 = this.cards[_local3].card_back._width * ((_local3 / (this.cards.length - 1)) - 0.5);
_local4 = ((this.cards[_local3].x - center_x_displacement) - this.xmouse) + _local6;
_local4 = Math.min(Math.max(_local4, -this.size_span), this.size_span);
var _local7 = ((_local3 == _local9) ? (_local12) : (this.cards[_local3].x));
var _local8 = _local7 + (this.amplitude * Math.sin(_local4 * this.ratio));
this.cards[_local3].group._x = this.cards[_local3].group._x + ((_local8 - this.cards[_local3].group._x) * 0.3);
_local3++;
}
} else {
if (this.mouse_over_cardindex >= 0) {
this.mouse_over_cardindex = -1;
game.network.send_string((("GMO " + this.parent.playernum) + ",") + this.mouse_over_cardindex);
}
var _local3 = 0;
while (_local3 < this.cards.length) {
this.cards[_local3].group._x = this.cards[_local3].group._x + ((this.cards[_local3].x - this.cards[_local3].group._x) * 0.6);
this.cards[_local3].group._y = this.cards[_local3].group._y + ((this.cards[_local3].y - this.cards[_local3].group._y) * 0.6);
_local3++;
}
}
} else {
if (this.mouse_over_cardindex >= 0) {
this.mouse_over_cardindex = -1;
game.network.send_string((("GMO " + this.parent.playernum) + ",") + this.mouse_over_cardindex);
}
var _local3 = 0;
while (_local3 < this.cards.length) {
this.cards[_local3].group._x = this.cards[_local3].group._x + ((this.cards[_local3].x - this.cards[_local3].group._x) * 0.6);
this.cards[_local3].group._y = this.cards[_local3].group._y + ((this.cards[_local3].y - this.cards[_local3].group._y) * 0.6);
_local3++;
}
}
}
return(true);
};
this.enable = function () {
this.enabled = true;
if (this.parent.local) {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].activate_click();
_local2++;
}
}
};
this.suite_sort_cards = function () {
var suite_vals = {};
suite_vals.H = 0;
suite_vals.C = 25;
suite_vals.D = 50;
suite_vals.S = 75;
var _local4 = function (a, b) {
var _local2 = suite_vals[a.color] + game.rules.get_card_value(a.value);
var _local1 = suite_vals[b.color] + game.rules.get_card_value(b.value);
if (_local2 < _local1) {
return(-1);
}
if (_local2 > _local1) {
return(1);
}
return(-1);
};
this.cards.sort(_local4);
};
this.z_sort_cards = function () {
var _local3 = [];
var _local2 = 0;
while (_local2 < this.cards.length) {
_local3.push(this.cards[_local2].get_sprite());
_local2++;
}
sprites.sort(_local3);
};
this.disable = function () {
this.enabled = false;
if (this.parent.local) {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].deactivate_click();
_local2++;
}
}
};
this.halt = function () {
events.stopIt(this);
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].halt();
_local2++;
}
};
this.show = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].show();
_local2++;
}
};
this.hide = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].hide();
_local2++;
}
};
this.kill = function () {
var _local2 = 0;
while (_local2 < this.cards.length) {
this.cards[_local2].kill();
_local2++;
}
this.cards = [];
};
this.init(props);
}
function Player(props) {
this.init = function (props) {
this.parent = props.parent;
this.playername = props.playername;
this.playernum = props.playernum;
this.avatardata = props.avatar;
this.local = props.local;
this.sequencenum = -1;
this.seatnum = -1;
this.avatar = null;
this.dealer = false;
this.winner = false;
this.ready_for_round = false;
this.enabled = false;
this.ai_player = null;
this.sendcards = [];
this.send_to_player = null;
this.level_score = 0;
this.score = 0;
this.cards_revealed = false;
this.disconnected = false;
this.send_cards_active = false;
this.auto_select_count = 0;
this.auto_select_max = 3;
this.pos_x = this.parent.positions[this.playernum][0] + (this.parent.positions[this.playernum][2] / 2);
this.pos_y = this.parent.positions[this.playernum][1] + (this.parent.positions[this.playernum][3] / 2);
this.hand_pos = this.parent.hand_positions[this.playernum];
this.hand = new Hand({parent:this, x:this.hand_pos[0], y:this.hand_pos[1]});
this.tricks = [];
this.num_visual_tricks = 0;
if (this.local) {
this.emoticons = new Emoticons({parent:this});
}
};
this.set_ai_player = function (ai_p) {
this.ai_player = ai_p;
};
this.set_sequencenum = function (num) {
this.sequencenum = num;
};
this.set_seatnum = function (num) {
this.seatnum = num;
this.pos_x = this.parent.positions[this.seatnum][0] + (this.parent.positions[this.seatnum][2] / 2);
this.pos_y = this.parent.positions[this.seatnum][1] + (this.parent.positions[this.seatnum][3] / 2);
this.hand_pos = this.parent.hand_positions[this.seatnum];
this.hand.set_pos(this.hand_pos[0], this.hand_pos[1], this.hand_pos[2], this.hand_pos[3]);
game.gui.positionate_avatar(num, this.avatar);
game.gui.set_playerbox(num, this.playername);
};
this.add_avatar = function () {
this.avatar = new Avatar({parent:this, playernum:this.playernum, avatar:this.avatardata, x:0, y:0});
this.avatar.load();
};
this.avatar_ready = function () {
if (game.gameover) {
return(undefined);
}
if (this.local) {
game.gui.show_instructions();
}
game.gui.avatar_ready(this.avatar);
};
this.deal_cards = function (carddata) {
this.hand.deal_cards(carddata);
};
this.show_cards = function () {
this.hand.show_cards();
};
this.set_dealer = function (d) {
this.dealer = d;
};
this.add_trick = function (cards, _points) {
var _local4 = new Trick({cards:cards, points:_points, parent:this});
this.tricks.push(_local4);
var _local3 = [];
var _local2 = 0;
while (_local2 < this.tricks.length) {
_local3.push(this.tricks[_local2].get_sprite());
_local2++;
}
if (this.local) {
if (_points >= 13) {
this.emoticons.setMood("mad", 3);
} else if (_points > 0) {
var _local5 = ((random.range(1, 2) == 2) ? "sad" : "ashamed");
this.emoticons.setMood(_local5, 3);
}
}
new Delay({seconds:1.2, callback:_local4.animate_to_targetpos, callback_scope:_local4});
};
this.get_trick_pos = function () {
var _local3 = this.parent.trick_positions[this.seatnum][0];
var _local2 = this.parent.trick_positions[this.seatnum][1];
var _local4 = this.parent.trick_positions[this.seatnum][4];
_local3 = _local3 + this.parent.trick_positions[this.seatnum][2];
_local2 = _local2 + this.parent.trick_positions[this.seatnum][3];
return({x:_local3, y:_local2, v:_local4});
};
this.next_round = function () {
var _local2 = 0;
while (_local2 < this.tricks.length) {
this.tricks[_local2].kill();
_local2++;
}
this.tricks = [];
this.num_visual_tricks = 0;
};
this.select_card = function (val, col) {
var _local2 = this.hand.get_card_by_col_val(col, val);
this.hand.set_card_selected(_local2);
};
this.auto_select_card = function () {
var _local2 = 0;
while (_local2 < this.hand.cards.length) {
var _local3 = this.hand.cards[_local2];
if (game.rules.card_clicked(this.hand, _local3)) {
game.gui.hourglass.stop();
break;
}
_local2++;
}
this.auto_select_count++;
wr("player.auto_select_card this.auto_select_count = ", this.auto_select_count);
wr("auto_select_count", this.auto_select_count, "auto_select_max", this.auto_select_max);
if (this.auto_select_count == this.auto_select_max) {
game.handleCommError("inactive_too_long");
}
};
this.enable = function () {
this.enabled = true;
if (this.hand.get_no_cards() > 0) {
game.gui.hilite_playerbox(this.seatnum, true);
if (this.local) {
soundFx.play("attentionSound", false, 70);
this.hand.enable();
var _local2 = parseInt(game.gamedata.autoplay);
if (isNaN(_local2) || (_local2 == 0)) {
_local2 = 10;
}
game.gui.hourglass.start({duration:_local2 * 1000, callback:this.auto_select_card, callback_scope:this});
} else if (this.ai_player) {
this.ai_player.play_card();
}
}
};
this.card_clicked = function (hand, card) {
if (game.gui.is_cardbox_active()) {
game.gui.add_card_to_cardbox(card);
} else if (game.rules.card_clicked(hand, card)) {
this.auto_select_count = 0;
game.gui.hourglass.stop();
wr("player.card_clicked stoppping hourglass");
if ((card.color == "S") && (card.value == "Q")) {
var _local3 = this.emoticons.getMood();
wr("this.emoticons.getMood() = ", _local3);
if (_local3 != "mad") {
this.emoticons.setMood("teasing", 3);
}
}
} else {
soundFx.play("beep.wav");
}
};
this.give_sendcards = function () {
soundFx.play("card_sound_6.aif", false, 80);
var _local2 = 0;
while (_local2 < this.sendcards.length) {
if (!this.local) {
this.sendcards[_local2].toLevel(8);
}
_local2++;
}
this.send_to_player.hand.add_cards_from_other_player(this.sendcards);
this.sendcards = [];
};
this.disable = function () {
this.enabled = false;
if (this.local) {
this.hand.disable();
}
game.gui.hilite_playerbox(this.seatnum, false);
};
this.halt = function () {
this.hand.halt();
if (this.local) {
game.gui.hourglass.stop();
}
};
this.show = function () {
this.hand.show();
};
this.hide = function () {
this.hand.hide();
};
this.kill = function () {
this.hand.kill();
};
this.init(props);
}
function Ai_player(props) {
this.parent = props.parent;
this.init = function () {
wr("aiplayer.init()");
this.network_queue = [];
if (game.table.local_player.ready_for_round && (!this.parent.ready_for_round)) {
this.send_next_round();
return(undefined);
}
if (this.parent.playernum == 0) {
if (game.rules.check_continue_deal()) {
return(undefined);
}
}
if (game.table.local_player.send_cards_done && (!this.parent.send_cards_done)) {
wr("ai select + send cards");
this.send_cards();
return(undefined);
}
if (this.parent.enabled) {
wr("ai_player.parent enabled");
this.play_card();
return(undefined);
}
if (game.gui.opponent_slambox.active && (this.parent.tricks.length == 13)) {
this.select_slam();
return(undefined);
}
};
this.play_card = function () {
wr("ai_player.play_card()");
var _local3 = this.parent.hand;
var _local2 = 0;
var _local4;
_local2 = 0;
while (_local2 < _local3.cards.length) {
if (game.rules.check_card_legal(_local3, _local3.cards[_local2])) {
break;
}
_local2++;
}
if (_local2 == _local3.cards.length) {
wr("ai_player could not find a legal card!!");
_local2 = random.range(0, this.hand.cards.length - 1);
}
_local4 = _local3.cards[_local2];
this.network_queue.push(((((("GPC " + this.parent.playernum) + ",") + _local2) + ",") + _local4.value) + _local4.color);
new Delay({callback:this.send_next_queued, callback_scope:this, seconds:0.6});
};
this.send_cards = function () {
wr("ai_player.send_cards()");
var _local6 = 1;
var _local5 = 0;
var _local4 = this.parent.hand;
var _local3 = 0;
while (_local3 < _local4.cards.length) {
if (_local4.cards[_local3].selected) {
_local5++;
}
_local3++;
}
_local3 = 0;
while (_local3 < _local4.cards.length) {
var _local2 = _local4.cards[_local3];
if (!_local2.selected) {
this.network_queue.push(((("GCC " + this.parent.playernum) + ",") + _local2.value) + _local2.color);
new Delay({callback:this.send_next_queued, callback_scope:this, seconds:_local6});
_local6 = _local6 + 0.5;
_local5++;
if (_local5 == 3) {
break;
}
}
_local3++;
}
this.network_queue.push("GSC " + this.parent.playernum);
new Delay({callback:this.send_next_queued, callback_scope:this, seconds:_local6});
};
this.select_slam = function () {
wr("ai_player.select_slam()");
this.network_queue.push(("GSS " + this.parent.playernum) + ",0");
new Delay({callback:this.send_next_queued, callback_scope:this, seconds:5});
};
this.send_next_round = function () {
wr("ai_player.send_next_round()");
game.network.send_ai_string("GNR " + this.parent.playernum);
};
this.send_next_queued = function () {
var _local2 = this.network_queue.shift();
game.network.send_ai_string(_local2);
};
}
function Game(props) {
this.width = 752;
this.height = 620;
this.gamestarted = false;
this.gameover = false;
this.no_disc_opponents = 0;
this.cm = null;
this.soundon = true;
this.init = function (props) {
_quality = "BEST";
this.gamedata = new GamedataObj({parent:this});
this.gui = new Gui({parent:this});
this.table = new Table({width:this.width, height:this.height});
this.network = new Network({parent:this});
this.playdata = new Playdata();
this.rules = new Rules({players_ref:this.table.players});
this.network.add_listener("MCC", this);
this.network.add_listener("MSG", this);
};
this.gamedata_loaded = function () {
this.rules.set_gamedata(this.gamedata);
this.gui.set_gamedata(this.gamedata);
this.gui.show_statusbox();
this.network.connect(this.gamedata.mp);
if (dev_mode) {
var _local5 = 0;
this.robo = [];
var _local4 = parseInt(_level0.robocount) || 0;
if (isNaN(_local4)) {
_local4 = -1;
}
var _local2 = 0;
while (_local2 < _local4) {
var _local3 = new Roboplayer(this.gamedata.mp);
this.robo.push(_local3);
_local2++;
}
}
};
this.add_local_player = function (pobj) {
this.rules.add_local_player(pobj);
};
this.add_remote_player = function (pobj) {
this.rules.add_remote_player(pobj);
};
this.remove_player = function (pno) {
wr("game.remove_player()", pno);
if (this.gameover) {
return(undefined);
}
this.table.players[pno].disconnected = true;
if (!this.gamestarted) {
this.gui.show_alert(this.gamedata.text.opponent_disconnect);
this.set_game_over("opponent_disconnect");
} else {
this.no_disc_opponents++;
if (this.no_disc_opponents < 3) {
wr("an opponent disconnect");
var _local9 = this.table.players[pno].avatar.avatar_sprite;
_local9._visible = false;
var _local8 = sprites.create({member:"robot_avatar", x:_local9._x, y:_local9._y, visible:true, level:18});
_local8._xscale = -70;
_local8._yscale = 70;
this.table.players[pno].avatar.avatar_sprite = _local8;
this.gui.chat.msg_receive((("" + pno) + ",") + game.gamedata.text.robot_activated);
this.gui.player_boxes[this.table.players[pno].seatnum].name.text = this.gamedata.text.robot;
var _local5 = true;
var _local2 = 0;
while (_local2 < this.table.local_player.playernum) {
_local5 = _local5 && (this.table.players[_local2].disconnected);
_local2++;
}
if (_local5) {
wr("activate ai");
_local2 = 0;
while (_local2 < this.table.players.length) {
if (this.table.players[_local2].disconnected) {
var _local3 = this.table.players[_local2];
var _local4 = new Ai_player({parent:_local3});
_local3.set_ai_player(_local4);
_local4.init();
}
_local2++;
}
}
} else {
wr("3 opponents have disconnected - set game over");
this.gui.show_alert(this.gamedata.text.opponent_disconnect);
this.set_game_over("opponent_disconnect");
}
}
};
this.start_game = function () {
var _local3 = 0;
var _local2 = 0;
while (_local2 < this.table.players.length) {
if (this.table.players[_local2]) {
_local3++;
}
_local2++;
}
if (_local3 < this.rules.get_no_players()) {
this.remove_player(-1);
return(undefined);
}
this.network.pause_incoming();
new Delay({seconds:1, callback:this.start_game2, callback_scope:this});
};
this.start_game2 = function () {
this.gui.hide_statusbox();
this.rules.start_game();
fscommand ("gameStart");
this.gamestarted = true;
this.gui.show_table();
this.lowerbar = sprites.create({member:"lowerbar", x:0, y:600, visible:true, level:10});
this.lowerbar.btn_end_sp = this.lowerbar.btn_end;
this.lowerbar.btn_end_sp.txt.text = this.gamedata.text.end_game;
var _local6 = new ClickButton({sp:this.lowerbar.btn_end_sp, id:"end_game", callback:this.end_game_pressed, callback_scope:this});
this.lowerbar.btn_snd_sp = this.lowerbar.btn_snd;
this.lowerbar.btn_snd_sp.txt.text = this.gamedata.text.sound_on;
var _local7 = new ClickButton({sp:this.lowerbar.btn_snd_sp, id:"sound_toggle", callback:this.sound_button_pressed, callback_scope:this});
new Delay({seconds:1.5, callback:this.gui.chat.show, callback_scope:this.gui.chat});
new Delay({seconds:1, callback:this.table.next_round, callback_scope:this.table});
new Delay({seconds:1, callback:this.rules.request_deal, callback_scope:this.rules});
new Delay({seconds:1.8, callback:this.network.resume_incoming, callback_scope:this.network});
};
this.sound_button_pressed = function () {
soundon = !soundon;
if (soundon) {
soundFx.soundOn();
this.lowerbar.btn_snd_sp.txt.text = this.gamedata.text.sound_on;
} else {
soundFx.soundOff();
this.lowerbar.btn_snd_sp.txt.text = this.gamedata.text.sound_off;
}
};
this.end_game_pressed = function () {
this.set_game_over("disconnected", 1);
};
this.start_round = function () {
};
this.deal_done = function () {
var _local2 = this.rules.get_pass_direction();
if (_local2 != "none") {
this.rules.start_send_cards();
this.gui.show_cardbox();
this.gui.start_cardbox();
} else {
this.rules.start_without_send_cards();
}
};
this.end_round = function () {
new Delay({seconds:3, callback:game.gui.show_scoreboard, callback_scope:game.gui});
};
this.set_game_over = function (reason, quitin) {
if (this.gameover) {
return(undefined);
}
if (quitin == undefined) {
quitin = parseInt(game.gamedata.postdelay);
if (isNaN(quitin)) {
quitin = 0;
}
}
var _local8 = function (obj) {
soundFx.play("outroSound");
clearInterval(obj.clearIntervalId);
};
var _local5 = new Object();
_local5.clearIntervalId = setInterval(_local8, 1000, _local5);
this.gameover = true;
var _local2 = 1000 - this.table.local_player.score;
if (reason == "disconnected") {
_local2 = 0;
this.network.pause_incoming();
}
wr("post score:", _local2);
this.table.halt();
this.gui.halt();
fscommand ("gameEnd", _local2);
var _local6 = function () {
this.network.disconnect();
wr("quit");
fscommand ("gameQuit");
};
var _local4 = quitin;
_local4 = _local4 + 2;
new Delay({seconds:_local4, callback:_local6, callback_scope:this});
};
this.get_game_over = function () {
return(this.rules.get_game_over());
};
this.networkServerEvent = function (cmd, dat) {
if (net_debug) {
wr("game.networkServerEvent()", cmd, dat);
}
if (!(cmd === "SDC")) {
} else {
var _local2 = dat.split(",", 2);
var _local3 = parseInt(_local2[0]);
var _local4 = _local2[1];
this.rules.deal_cards(_local3, _local4);
}
};
this.networkGameEvent = function (cmd, playernum, playdata) {
if (net_debug) {
wr("game.networkGameEvent()", cmd, playernum, playdata);
}
switch (cmd) {
case "GPC" :
var _local5 = playdata.split(",");
var _local6 = parseInt(_local5[0]);
var _local7 = _local5[1];
this.rules.play_opponent_card(playernum, _local6, _local7);
break;
case "GCC" :
this.rules.opponent_chose_card(playernum, playdata);
break;
case "GSC" :
wr("player", playernum, "finished selecting cards.");
this.rules.player_sent_cards(playernum);
break;
case "GNR" :
this.rules.player_next_round(playernum);
break;
case "GMO" :
this.table.players[playernum].hand.mouse_over_index(parseInt(playdata));
break;
case "GSS" :
var _local3 = playdata;
wr("game.networkGameEvent GSS recieved - playdata=punish_opponents = ", _local3);
this.gui.hide_opponent_slambox();
_local3 = ((_local3 == "0") ? false : true);
this.rules.slambox_done(_local3);
}
};
this.networkEvent = function (cmd, dat) {
if (net_debug) {
wr("game.networkEvent()", cmd, dat);
}
switch (cmd) {
case "MCC" :
if (__midas_chatcontrol) {
__midas_chatcontrol.hm("MCC " + dat);
}
break;
case "MSG" :
if (!this.gui.chat) {
break;
}
this.gui.chat.msg_receive(dat);
}
};
this.handleCommError = function (msg) {
if (this.gameover) {
return(undefined);
}
this.set_game_over("disconnected");
this.gui.show_alert(this.gamedata.text[msg]);
this.gui.hide_statusbox();
};
this.init(props);
}
function startup() {
if (_game_started) {
return(undefined);
}
_game_started = true;
events = new Events();
sprites = new Sprites();
soundFx = new SoundFx();
random = new Random();
game = new Game();
}
var global_card_count = 0;
var game_version = "1.1";
var dev_mode = false;
var net_debug = false;
var netlog_wr = false;
var game;
var events;
var sprites;
var soundFx;
var random;
var _game_started = false;
Stage.showMenu = false;
Stage.scaleMode = "noScale";
_focusrect = false;
stop();
startup();
Symbol 106 MovieClip [card_fg] Frame 1
stop();
Symbol 130 MovieClip Frame 1
stop();
Symbol 130 MovieClip Frame 2
stop();
Symbol 130 MovieClip Frame 3
stop();
Symbol 130 MovieClip Frame 4
stop();
Symbol 137 MovieClip Frame 1
stop();
Symbol 137 MovieClip Frame 2
stop();
Symbol 166 MovieClip Frame 1
stop();
Symbol 187 MovieClip Frame 1
stop();