feat(pets): play as your pet in any room, from the pet chooser

A switch in the pet chooser (the settings menu's own On/Off switch, at
the top left of the pet's picture) puts the pet that is out in the
avatar's place, for everyone, as at a Play-As-Your-Pet party: the pet
at the party's size where the avatar stands, turning as it walks, its
name on the name bar, chat balloons and emotes over it, the pet in the
HUD. Hidden at the party itself.

- kept as user var 9008 (9007 is the performance profile), so it holds
  through rooms and logins and is kept for the next pet when the pet is
  put away. the server tells the room by user communication type 13,
  also to players coming in later.
- WorldPet and AvatarWorldView ask the avatar's own form instead of the
  room-wide party test; a pet that cannot come into the room leaves the
  avatar shown.
- the type-13 handler read a variable it never set, so every client took
  every message for "off" and nobody else saw the form.
- the action menu's pet button does the pet's trick again (5c9b2e0 had
  made it the switch, which only hid the avatar).

Flying pets keep to the ground's walls (the party lets them over).
buildVersion 74.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
BurrowdevandClaude Opus 5.5 committed 2026-10-20 15:25:35 +03:00
1 parent 2344270291
commit 096ceafea7
12 files changed
+627 -67

No files matched your search

+1 -1
View File
@@ -155,7 +155,7 @@ module.exports = {
// 49 and 50: its link to a colour picker.
// 61: the Owner, Moderator and Verified name tag badges seen by everyone.
// 62: "Custom pictures" in the settings menu, to hide players' item pictures.
buildVersion: env.AJ_BUILD_VERSION || "71",
buildVersion: env.AJ_BUILD_VERSION || "74",
// what the official CDN is asked for; not ours to change.
upstreamBuildVersion: "3",
+36 -17
View File
@@ -3,7 +3,7 @@
const accounts = require("./accounts.js");
const achievements = require("./achievements.js");
const defpacks = require("./defpacks.js");
const {activeAvatar, isUint} = require("./player.js");
const {activeAvatar, activePet, isUint} = require("./player.js");
// pets (client side: PetManager, PetXtCommManager). A pet's species and look
// are packed into three integers by PetManager.packPetBits; the species is
@@ -30,6 +30,13 @@ const MASTERY_FULL = 100;
const MASTERY_PER_ROOM = 5;
const MASTERY_BITS = 0xF00; // the part of uBits PetInventory writes
const SECONDS_TO_HATCH = 259200; // PetManager.hasHatched
// not one of the game's: the pet chooser's "play as your pet" switch
// (gui.PetInventory), kept with the user vars so it reaches the client at
// login. on, whichever pet is out stands in for the avatar, in any room, as
// at a Play-As-Your-Pet party.
const USER_VAR_PET_FORM = 9008;
const inPetForm = account => Number(account.userVars[USER_VAR_PET_FORM]) === 1 && Boolean(activePet(account));
const random = (min, max) => min + Math.floor(Math.random() * (max - min + 1));
@@ -106,6 +113,24 @@ module.exports = ({others, findOnline, petFields}) => {
const ownPet = (account, invIdx) => account.pets.find(candidate => candidate.inv === Number(invIdx));
// tells the player and everyone who sees them whether the pet stands in
// for the avatar (UserCommXtCommManager, user communication type 13).
const sendPetForm = session => {
if (session.pos) {
const state = inPetForm(session.account) ? "on" : "off";
for (const other of [session, ...others(session)]) {
other.sendXt("uc", session.room.id, session.id, state, "13");
}
}
};
// the pet chooser's switch. on with no pet out is kept for the next pet.
const setPetForm = (session, on) => {
achievements.set(session.account, USER_VAR_PET_FORM, on ? 1 : 0);
accounts.save(session.account);
sendPetForm(session);
};
const handlers = {
// PetManager.onPetListResponse: [found, username, count, (invIdx,
// createdTs, name, lBits, uBits, eBits, mastery, personality, toy, food,
@@ -146,15 +171,8 @@ module.exports = ({others, findOnline, petFields}) => {
session.sendXt("ps", -1, 0);
return;
}
const wasPetForm = inPetForm(account);
activeAvatar(account).petInvId = pet ? pet.inv : 0;
if (!pet && session.petPlayerMode) {
session.petPlayerMode = false;
if (session.pos) {
for (const other of [session, ...others(session)]) {
other.sendXt("uc", session.room.id, session.id, "off", "13");
}
}
}
accounts.save(account);
const messageRoom = session.room ? session.room.id : -1;
session.sendXt("ps", messageRoom, 1, session.id, pet ? pet.inv : 0);
@@ -163,6 +181,11 @@ module.exports = ({others, findOnline, petFields}) => {
other.sendXt("ps", messageRoom, 1, session.id, ...petFields(pet));
}
}
// with no pet out the avatar comes back; the next pet out takes its
// place again while the switch is on.
if (wasPetForm !== inPetForm(account)) {
sendPetForm(session);
}
},
// PetManager.onPetDismissResponse: [success, invIdx]
@@ -173,14 +196,10 @@ module.exports = ({others, findOnline, petFields}) => {
session.sendXt("pd", -1, 0, invIdx);
return;
}
const wasPetForm = inPetForm(account);
account.pets = account.pets.filter(candidate => candidate !== pet);
if (session.petPlayerMode && activeAvatar(account).petInvId === pet.inv) {
session.petPlayerMode = false;
if (session.pos) {
for (const other of [session, ...others(session)]) {
other.sendXt("uc", session.room.id, session.id, "off", "13");
}
}
if (wasPetForm && !inPetForm(account)) {
sendPetForm(session);
}
for (const avatar of account.avatars) {
if (avatar.petInvId === pet.inv) {
@@ -251,5 +270,5 @@ module.exports = ({others, findOnline, petFields}) => {
},
};
return {handlers, walked, giveCharacter, favouritesList, personalityList, PERSONALITY_LIST};
return {handlers, walked, giveCharacter, favouritesList, personalityList, PERSONALITY_LIST, inPetForm, setPetForm};
};
+6 -9
View File
@@ -469,7 +469,7 @@ const sendAvatarCreate = (to, target) => {
if (target.invisible) {
to.sendXt("xiv", -1, target.id, 1);
}
if (target.petPlayerMode) {
if (pets.inPetForm(account)) {
to.sendXt("uc", room.id, target.id, "on", "13");
}
// `ac` only creates the avatar. Actions normally travel as live `uc`
@@ -1772,15 +1772,12 @@ module.exports = {
minigames.bubble(session, fields[0], fields[2]);
return;
}
// Per-player pet form. It is deliberately a user-communication
// message so every client already in the room updates the same
// avatar, while the normal pet-out state stays unchanged.
// Per-player pet form (the pet chooser's switch, lib/pets.js). It
// is deliberately a user-communication message so every client
// already in the room updates the same avatar, while the normal
// pet-out state stays unchanged.
if (fields[1] === "13") {
const enabled = fields[0] === "on" && Boolean(activePet(session.account));
session.petPlayerMode = enabled;
for (const other of [session, ...watchers(session)]) {
other.sendXt("uc", session.room.id, session.id, enabled ? "on" : "off", "13");
}
pets.setPetForm(session, fields[0] === "on");
return;
}
// Type 3 is the action packet. It used to be sent only to people
+9
View File
@@ -608,6 +608,14 @@ package
return settingOf(9006) != 1;
}
// the pet chooser's "play as your pet" switch (gui.PetInventory): the
// pet that is out stands in for the avatar in any room. user var 9008,
// which the server also reads to show the pet form to everyone.
public static function petFormOn() : Boolean
{
return settingOf(9008) == 1;
}
// an item's picture version, or null for none or with them hidden
private static function artOf(param1:String, param2:int) : String
{
@@ -1542,6 +1550,7 @@ package
// 9007 Performance profile: 1 Low-end, 2 High, unset Balanced. A
// profile changes only optional rendering work, never the
// game's native 24 FPS (which would slow its animations).
// 9008 Play as your pet (gui.PetInventory, lib/pets.js): 1 on.
private static var _smoothTimer:Timer;
-13
View File
@@ -700,19 +700,6 @@ package gui
{
var _loc2_:WorldPet = null;
param1.stopPropagation();
// Outside a play-as-your-pet event this button is the personal
// pet-form switch. The server echoes the change to everybody in
// the room, so this is not merely a local visual effect.
if(!GuiManager.isBeYourPetRoom())
{
if(AvatarManager.playerAvatarWorldView && AvatarManager.playerAvatarWorldView.getActivePet())
{
UserCommXtCommManager.sendPetPlayerMode(!GuiManager.isPlayingAsPet());
}
actionBtn.dispatchEvent(new MouseEvent("mouseDown"));
param1.currentTarget.downToUpState();
return;
}
if(AvatarManager.playerAvatarWorldView)
{
_loc2_ = AvatarManager.playerAvatarWorldView.getActivePet();
+73 -15
View File
@@ -335,6 +335,12 @@ package avatar
private var _currPetName:String;
private var _shouldShowPetOnly:Boolean;
// the pet chooser's switch as last heard for this avatar (type-13 user
// communication), and the pet last set, to make it again in either form
private var _petPlayerMode:Boolean;
private var _petArgs:Array;
private var _emitParticles:Boolean;
@@ -552,7 +558,7 @@ package avatar
_loc12_ = 1;
}
_chatBalloon = GETDEFINITIONBYNAME("ChatBalloonAsset",false);
_chatBalloon.init(_avatar.avTypeId,AvatarUtility.getAvatarEmoteBgOffset,false,_loc12_,RoomManagerWorld.instance.layerManager.bkg.scaleX,SBTextField,onChatBallonAdventureDown,onChatBalloonPVPDown);
_chatBalloon.init(_avatar.avTypeId,emoteBgOffset,false,_loc12_,RoomManagerWorld.instance.layerManager.bkg.scaleX,SBTextField,onChatBallonAdventureDown,onChatBalloonPVPDown);
_chatLayer.addChild(_chatBalloon);
_moving = 0;
_lastMoveAngle = 2;
@@ -605,7 +611,7 @@ package avatar
_hudViewHolder.mouse.gotoAndStop(offScreenDefaultMouseFrameLabel());
}
}
_shouldShowPetOnly = GuiManager.isBeYourPetRoom() || userId == AvatarManager.playerSfsUserId && GuiManager.isPlayingAsPet();
_shouldShowPetOnly = GuiManager.isBeYourPetRoom() || (userId == AvatarManager.playerSfsUserId ? GuiManager.isPlayingAsPet() : _petPlayerMode);
if(_shouldShowPetOnly)
{
_layerAnim.alpha = 0;
@@ -2066,6 +2072,7 @@ package avatar
public function setActivePet(param1:Number, param2:uint, param3:uint, param4:uint, param5:String, param6:int, param7:int, param8:int, param9:int = 0) : void
{
_petArgs = [param1,param2,param3,param4,param5,param6,param7,param8,param9];
if(_pet)
{
if(_pet.parent == this)
@@ -2094,6 +2101,17 @@ package avatar
{
_splash.showShadow(true);
}
// another pet out in the pet form: the HUD shows the new one
if(_shouldShowPetOnly && userId == AvatarManager.playerSfsUserId)
{
GuiManager.setPersonalPetMode(true);
}
}
// a pet that cannot come into this room leaves the avatar shown
if(_shouldShowPetOnly && !_pet && !GuiManager.isBeYourPetRoom())
{
_shouldShowPetOnly = false;
showPetForm();
}
}
@@ -2102,8 +2120,30 @@ package avatar
// own state instead of asking the room-wide GuiManager predicate.
public function setPetPlayerMode(param1:Boolean) : void
{
var _loc2_:Boolean = param1 && _pet != null;
_shouldShowPetOnly = _loc2_ || GuiManager.isBeYourPetRoom();
var _loc2_:Boolean = false;
_petPlayerMode = param1;
_loc2_ = GuiManager.isBeYourPetRoom() || param1 && _petArgs != null && _petArgs[1] != 0;
if(_loc2_ != _shouldShowPetOnly)
{
_shouldShowPetOnly = _loc2_;
// WorldPet takes its size and place from the form when it is
// made, so the pet is made again
if(_petArgs != null)
{
setActivePet.apply(this,_petArgs);
}
}
showPetForm();
if(userId == AvatarManager.playerSfsUserId)
{
GuiManager.setPersonalPetMode(_shouldShowPetOnly);
}
}
// the avatar or its pet, as _shouldShowPetOnly says
private function showPetForm() : void
{
var _loc1_:UserInfo = null;
_layerAnim.alpha = _shouldShowPetOnly ? 0 : 1;
_layerAnim.avatarEnabled = !_shouldShowPetOnly;
if(_shouldShowPetOnly && _pet)
@@ -2117,12 +2157,32 @@ package avatar
else
{
_splash.showShadow(true);
_namebar.setAvName(_avatar.avName);
}
if(userId == AvatarManager.playerSfsUserId)
{
GuiManager.setPersonalPetMode(_loc2_);
_loc1_ = gMainFrame.userInfo.getUserInfoByUserName(_avatar.userName);
_namebar.setAvName(_avatar,Utility.isSettingOn(MySettings.SETTINGS_USERNAME_BADGE),_loc1_);
}
placeChatBalloon();
updateChatBallonBgOffsets();
}
// the pet stands in for this avatar: the party's or quest's form, or
// the pet chooser's switch (WorldPet asks)
public function isPetForm() : Boolean
{
return _shouldShowPetOnly;
}
// chat balloons and emotes sit over the pet in its form, as the
// party's do (AvatarUtility's pet offsets)
private function placeChatBalloon() : void
{
var _loc1_:Point = _shouldShowPetOnly ? new Point(10,-80) : AvatarUtility.getAvatarChatOffset(_avatar.avTypeId);
_chatBalloon.x = this.x + _loc1_.x;
_chatBalloon.y = this.y + _loc1_.y;
}
private function emoteBgOffset(param1:int) : Point
{
return _shouldShowPetOnly ? new Point(-5,-25) : AvatarUtility.getAvatarEmoteBgOffset(param1);
}
public function getActivePet() : WorldPet
@@ -2281,9 +2341,7 @@ package avatar
param2 *= _scale.y;
this.x = param1;
this.y = param2;
var _loc3_:Point = AvatarUtility.getAvatarChatOffset(_avatar.avTypeId);
_chatBalloon.x = this.x + _loc3_.x;
_chatBalloon.y = this.y + _loc3_.y;
placeChatBalloon();
if(_avSwitchedNPC)
{
_avSwitchedNPC.x = param1;
@@ -2359,9 +2417,9 @@ package avatar
{
_hudViewHolder.mouse.gotoAndStop(offScreenDefaultMouseFrameLabel());
}
if(GuiManager.isBeYourPetRoom())
_loc7_ = gMainFrame.userInfo.getAvatarInfoByUsernamePerUserAvId(userName,perUserAvId);
if(_shouldShowPetOnly && _loc7_ && _loc7_.currPet)
{
_loc7_ = gMainFrame.userInfo.getAvatarInfoByUsernamePerUserAvId(userName,perUserAvId);
_hudAvtOrPetView = new GuiPet(_loc7_.currPet.createdTs,0,_loc7_.currPet.lBits,_loc7_.currPet.uBits,_loc7_.currPet.eBits,_loc7_.currPet.type,_loc7_.currPet.name,_loc7_.currPet.personalityDefId,_loc7_.currPet.favoriteToyDefId,_loc7_.currPet.favoriteFoodDefId,onHudAvtOrPetView);
}
else
@@ -2479,7 +2537,7 @@ package avatar
var _loc3_:Number = NaN;
if(_hudAvtOrPetView)
{
if(GuiManager.isBeYourPetRoom())
if(_hudAvtOrPetView is GuiPet)
{
_hudAvtOrPetView.y = 15;
}
+5 -11
View File
@@ -181,10 +181,6 @@ package gui
private static var _petInventory:PetInventory;
// A player's voluntary pet form. Party and quest pet forms remain
// room-wide and are still reported by isBeYourPetRoom().
private static var _personalPetMode:Boolean = false;
private static var _joeyPopup:MovieClip;
private static var _secondaryJoeyPopup:MovieClip;
@@ -2616,7 +2612,7 @@ package gui
{
mainHud.charWindow.charLayer.removeChildAt(0);
}
if(isBeYourPetRoom())
if(isPlayingAsPet())
{
_loc1_ = PetManager.myActivePet;
if(_loc1_)
@@ -2911,18 +2907,16 @@ package gui
return QuestManager.isBeYourPetQuest() || PartyManager.isBeYourPetParty();
}
// A player's own pet form: the party's and the quest's for everyone in
// the room, or the pet chooser's switch with a pet out.
public static function isPlayingAsPet() : Boolean
{
return _personalPetMode || isBeYourPetRoom();
return isBeYourPetRoom() || AJClient.petFormOn() && PetManager.myActivePet != null;
}
// the player's own avatar came into or out of its pet form
public static function setPersonalPetMode(param1:Boolean) : void
{
if(_personalPetMode == param1)
{
return;
}
_personalPetMode = param1;
if(mainHud)
{
showHudAvt();
+74
View File
@@ -3,6 +3,7 @@ package gui
import Party.PartyManager;
import adoptAPet.AdoptAPetManager;
import avatar.AvatarManager;
import avatar.UserCommXtCommManager;
import com.sbi.analytics.SBTracker;
import com.sbi.popup.SBOkPopup;
import com.sbi.popup.SBYesNoPopup;
@@ -43,6 +44,12 @@ package gui
private var _inventoryMC:MovieClip;
private var _loadingMediaHelper:MediaHelper;
// "play as your pet": the settings menu's on/off switch, in any room
// but a Play-As-Your-Pet party's (AJClient.petFormOn)
private var _petFormSwitch:MovieClip;
private var _petFormOn:Boolean;
private var _loadingSpiralBig:LoadingSpiral;
@@ -222,6 +229,7 @@ package gui
_guiLayer.addChild(_inventoryMC);
DarkenManager.darken(_inventoryMC);
createItemWindows();
addPetFormSwitch();
addEventListeners();
if(_openCheckListImmediately)
{
@@ -246,6 +254,58 @@ package gui
}
// A double click on the big pet's name lets the player type another.
// the switch sits at the top left of the pet's picture, across from
// the certificate. on, whichever pet is out stands in for the avatar,
// for everyone (the server keeps it with the user vars and tells the
// room: UserCommXtCommManager type 13).
private function addPetFormSwitch() : void
{
var _loc1_:MovieClip = null;
if(GuiManager.isBeYourPetRoom())
{
return;
}
_loc1_ = GETDEFINITIONBYNAME("mySettingsToggle",false);
_petFormSwitch = _loc1_.toggleBtn;
_loc1_.removeChild(_petFormSwitch);
_petFormSwitch.x = 78;
_petFormSwitch.y = -143;
_petFormSwitch.buttonMode = true;
_petFormSwitch.useHandCursor = true;
_petFormSwitch.toggleBtn.toggleKnob.gotoAndStop("up");
_petFormSwitch.toggleBtn.toggleBG.gotoAndStop("up");
_petFormOn = AJClient.petFormOn();
_petFormSwitch.toggleBtn.gotoAndStop(_petFormOn ? "startingOn" : "startingOff");
LocalizationManager.translateId(_petFormSwitch.toggleBtn.valueTxt.onTxt,6324);
LocalizationManager.translateId(_petFormSwitch.toggleBtn.valueTxt.offTxt,6322);
_inventoryMC.addChild(_petFormSwitch);
}
private function onPetFormSwitch(param1:MouseEvent) : void
{
param1.stopPropagation();
_petFormOn = !_petFormOn;
_petFormSwitch.toggleBtn.gotoAndPlay(_petFormOn ? "on" : "off");
UserCommXtCommManager.sendPetPlayerMode(_petFormOn);
}
private function onPetFormSwitchOver(param1:MouseEvent) : void
{
param1.stopPropagation();
_petFormSwitch.toggleBtn.toggleBG.gotoAndStop("over");
_petFormSwitch.toggleBtn.toggleKnob.gotoAndStop("over");
GuiManager.toolTip.init(_petFormSwitch,"Play as your pet",58,-10);
GuiManager.toolTip.startTimer(param1);
}
private function onPetFormSwitchOut(param1:MouseEvent) : void
{
param1.stopPropagation();
_petFormSwitch.toggleBtn.toggleBG.gotoAndStop("up");
_petFormSwitch.toggleBtn.toggleKnob.gotoAndStop("up");
GuiManager.toolTip.resetTimerAndSetVisibility();
}
private function onPetRenamed(param1:String) : void
{
var _loc2_:int = 0;
@@ -852,6 +912,12 @@ package gui
_inventoryMC.salonBtn.addEventListener("mouseDown",onSalonBtn,false,0,true);
_inventoryMC.checklistBtn.addEventListener("mouseDown",onChecklistBtn,false,0,true);
_inventoryMC.certBtn.addEventListener("mouseDown",onCertBtn,false,0,true);
if(_petFormSwitch)
{
_petFormSwitch.addEventListener("mouseDown",onPetFormSwitch,false,0,true);
_petFormSwitch.addEventListener("rollOver",onPetFormSwitchOver,false,0,true);
_petFormSwitch.addEventListener("rollOut",onPetFormSwitchOut,false,0,true);
}
}
private function removeEventListeners() : void
@@ -866,6 +932,14 @@ package gui
_inventoryMC.salonBtn.removeEventListener("mouseDown",onSalonBtn);
_inventoryMC.checklistBtn.removeEventListener("mouseDown",onChecklistBtn);
_inventoryMC.certBtn.removeEventListener("mouseDown",onCertBtn);
if(_petFormSwitch)
{
_petFormSwitch.removeEventListener("mouseDown",onPetFormSwitch);
_petFormSwitch.removeEventListener("rollOver",onPetFormSwitchOver);
_petFormSwitch.removeEventListener("rollOut",onPetFormSwitchOut);
GuiManager.toolTip.resetTimerAndSetVisibility();
_petFormSwitch = null;
}
}
}
}
+1 -1
View File
@@ -725,7 +725,7 @@ package avatar
{
if(AvatarManager.avatarViewList[_loc19_])
{
AvatarManager.avatarViewList[_loc19_].setPetPlayerMode(_loc2_ == "on");
AvatarManager.avatarViewList[_loc19_].setPetPlayerMode(param1[3] == "on");
}
}
else
+421
View File
@@ -0,0 +1,421 @@
package pet
{
import avatar.AvatarWorldView;
import avatar.UserCommXtCommManager;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import gui.GuiManager;
public class WorldPet extends PetBase
{
public static const ANIM_IDLE:int = 0;
public static const ANIM_MOVE:int = 1;
public static const ANIM_IDLE_UP:int = 2;
public static const ANIM_MOVE_UP:int = 3;
public static const ANIM_CLICK:int = 4;
public static const ANIM_IDLE_WATER:int = 10;
public static const ANIM_IDLE_MUD:int = 20;
public static const ANIM_DANCE:int = 31;
public static const ANIM_SLEEP_OR_DIVE:int = 32;
public static const ANIM_HOP_OR_SWIRL:int = 33;
public static const ANIM_PLAY:int = 34;
public static const ANIM_SIT_OR_POSE:int = 35;
public static const ACTION_CLICK:int = 0;
public static const ACTION_SPARKLE:int = 1;
public static const PET_SPARKLE_TIME:int = 7200;
public static var _actionLookup:Array = [{
"name":":dance:",
"animId":31
},{
"name":":sleep:",
"animId":32
},{
"name":":dive:",
"animId":32
},{
"name":":hop:",
"animId":33
},{
"name":":swirl:",
"animId":33
},{
"name":":play:",
"animId":34
},{
"name":":sit:",
"animId":35
},{
"name":":sitNW:",
"animId":35
},{
"name":":sitSW:",
"animId":35
},{
"name":":sitSE:",
"animId":35
},{
"name":":sitNE:",
"animId":35
},{
"name":":pose:",
"animId":35
},{
"name":":poseLeft:",
"animId":35
},{
"name":":poseRight:",
"animId":35
}];
private var _parent:AvatarWorldView;
private var _mode:int;
private var _x:int;
private var _y:int;
private var _targetX:int;
private var _targetY:int;
private var _bNewTarget:Boolean;
private var _dirX:Number;
private var _dirY:Number;
private var _speed:Number;
private var _lastAnim:int;
private var _bFlip:Boolean;
private var _bBack:Boolean;
private var _bUpdateState:Boolean;
private var _parentLastX:Number;
private var _parentLastY:Number;
private var _bSpecialMove:Boolean;
private var _petLoaded:Boolean;
private var _sparkle:int;
private var _offsetX:int = 100;
private var _offsetY:int = -50;
private var _maxSpeed:Number = 1;
private var _accel:Number = 0.03;
private var _scale:Number = 1;
private var _minX:Number = -70;
private var _maxX:Number = 55;
private var _airPetYOffest:Number = -80;
private var _oceanPetXOffset:Number = 55;
private var _petLandLowXOffset:Number = 30;
public function WorldPet(param1:AvatarWorldView, param2:Number, param3:uint, param4:uint, param5:uint, param6:uint, param7:uint, param8:uint, param9:int = 0)
{
super(param2,param3,param4,param5,param6,param7,param8,onPetLoaded);
_sparkle = param9;
_parent = param1;
_targetX = 0;
_bNewTarget = true;
_mode = 1;
_lastAnim = -1;
_bUpdateState = true;
_bFlip = false;
_bBack = false;
_bSpecialMove = false;
_parent.addChild(this);
if(param1.userName.toLowerCase() == gMainFrame.server.userName.toLowerCase() && !_parent.isPetForm())
{
this.addEventListener("mouseDown",onClick,false,0,true);
}
else
{
this.mouseChildren = false;
this.mouseEnabled = false;
}
if(isEggAndHasNotHatched || (getType() == 0 || getType() == 2 || getType() == 4))
{
if(_parent.isPetForm())
{
_y = -5;
GuiManager.actionMgr.grayOutPetDanceBtn(false);
}
else
{
_y = 0;
}
}
else
{
GuiManager.actionMgr.grayOutPetDanceBtn(true);
if(_parent.isPetForm())
{
_y = -5;
}
else
{
_y = _airPetYOffest;
}
}
_parentLastX = _parent.x;
_parentLastY = _parent.y;
if(_parent.isPetForm())
{
_minX = 25;
_maxX = -30;
_x = _maxX;
_parentLastX = 0;
}
else
{
if(getType() == 2)
{
_minX -= _oceanPetXOffset;
_maxX += _oceanPetXOffset;
}
else if(getType() == 0)
{
if(param1.avTypeId != 5)
{
_minX -= _petLandLowXOffset;
}
}
_x = 0;
}
_targetX = 0;
}
override public function destroy() : void
{
super.destroy();
this.removeEventListener("mouseDown",onClick);
}
public function heartbeat(param1:int, param2:Boolean) : void
{
var _loc5_:int = 0;
var _loc3_:Matrix = null;
var _loc4_:int = 0;
if(_content && _parent && !_parent.isOffScreen)
{
if(_parent.isPetForm())
{
if(_parentLastX != _parent.x)
{
if(_parent.x > _parentLastX)
{
if(!_bFlip)
{
_parent.flipSplash(true);
_bFlip = true;
_x = _minX;
}
}
else if(_bFlip)
{
_parent.flipSplash(false);
_bFlip = false;
_x = _maxX;
}
_parentLastX = _parent.x;
}
}
else
{
if(_targetX == 0)
{
_targetX = _parent.hFlip ? _minX : _maxX;
}
if(_parentLastX != _parent.x)
{
_bFlip = _parent.x > _parentLastX ? true : false;
if(Math.abs(_parentLastX - _parent.x) > 13)
{
_targetX = _bFlip ? _minX : _maxX;
}
_parentLastX = _parent.x;
}
if(_parentLastY != _parent.y)
{
_bBack = _parent.y < _parentLastY - 10 ? true : false;
_parentLastY = _parent.y;
}
if(_x > _targetX)
{
_x -= 10;
if(_x <= _targetX)
{
_x = _targetX;
}
_bFlip = _x == _targetX ? true : false;
}
if(_x < _targetX)
{
_x += 10;
if(_x > _targetX)
{
_x = _targetX;
}
_bFlip = _x == _targetX ? false : true;
}
}
if(_bUpdateState)
{
PetManager.setPetState(_content,_lBits,_uBits,_eBits);
_bUpdateState = false;
}
_loc5_ = _parent.inSplashVolume() ? 10 : 0;
if(_loc5_ && _parent.splashLiquid == "mud")
{
_loc5_ = 20;
}
if(_parent.splashLiquid != "mud" && _parent.splashLiquid != "water")
{
_loc5_ = 0;
}
_loc3_ = _content.transform.matrix;
_loc3_.identity();
_loc3_.scale(_bFlip ? -_scale : _scale,_scale);
_loc3_.translate(_x,_y - param1);
_content.transform.matrix = _loc3_;
_loc4_ = _loc5_ + param2;
if(_bBack)
{
_loc4_ += 2;
}
if((param2 || _lastAnim <= 4) && _lastAnim != _loc4_)
{
_lastAnim = _loc4_;
_content.pet.setAnim(_loc4_);
}
if(_bSpecialMove)
{
_bSpecialMove = false;
if(!param2)
{
_content.pet.setAnim(4 + _loc5_);
}
}
}
}
public function setState(param1:Array) : void
{
_lBits = param1[0];
_uBits = param1[1];
_eBits = param1[2];
_bUpdateState = true;
}
public function setAction(param1:int, param2:int = 0) : void
{
switch(param1)
{
case 0:
onClick();
break;
case 1:
setSparkle(param2);
}
}
public function setActionByName(param1:String) : void
{
var _loc2_:int = 0;
for each(var _loc3_:Object in _actionLookup)
{
if(_loc3_.name == param1)
{
_loc2_ = int(_loc3_.animId);
if(_loc2_ > 0)
{
_lastAnim = _loc2_;
if(_content)
{
_content.pet.setAnim(_loc2_);
}
}
break;
}
}
}
public function onClick(param1:MouseEvent = null) : void
{
if(param1)
{
param1.stopPropagation();
UserCommXtCommManager.sendPetAction(0);
}
_bSpecialMove = true;
}
private function onPetLoaded(param1:MovieClip) : void
{
if(_parent.isPetForm())
{
_content.pet.scaleX = _content.pet.scaleY = 2;
}
_content.pet.setSparkle(_sparkle);
}
private function convertAvtAnimToPetAnim() : int
{
switch(_parent.animId)
{
case 23:
case 38:
return 31;
case 22:
case 41:
return 32;
case 17:
case 33:
return 33;
case 6:
case 39:
return 34;
case 2:
case 4:
case 40:
break;
default:
return _parent.isPetMovingTest() ? 0 : 1;
}
return 35;
}
}
}
BIN
View File
Binary file not shown.
+1
View File
@@ -60,6 +60,7 @@ set -- \
gui.RecycleItems RecycleItems.as \
gui.AvatarEditor AvatarEditor.as \
gui.PetInventory PetInventory.as \
pet.WorldPet WorldPet.as \
gui.DenEditor DenEditor.as \
gui.TradeManager TradeManager.as \
avatar.AvatarView AvatarView.as \