public void BackToGame() { Menu.SetActive(false); pauseB.enabled = true; //game resumes, same as method in the PauseGame script PetUtility.ContinueGame(); }
IEnumerator LaunchAttack() { //if (unit.enemy.transform.position.x - gameObject.transform.position.x > 0) { // enemyDirection = Direction.right; //} else { // enemyDirection = Direction.left; //} unit.launchingAttack = true; Vector2 current = gameObject.transform.position; //todo: get direction needs to be updated when chasing from behind Vector2 newPosition = unit.GetFaceDirection().normalized *attackDistance + current; if (gameObject != null) { PetUtility.Coroutine(PetUtility.LinearMove(current, newPosition, 0.15f, gameObject.transform)); } yield return(new WaitForSeconds(0.15f)); if (gameObject != null) { PetUtility.Coroutine(PetUtility.LinearMove(newPosition, current, 0.15f, gameObject.transform)); } yield return(new WaitForSeconds(0.15f)); yield return(null); }
//Every time a unit dies, check if there are any ghosts or pets left public void checkForUnits(object obj) { void Check() { Ghost[] ghosts = FindObjectsOfType <Ghost>(); Pet[] pets = FindObjectsOfType <Pet>(); Debug.Log("ghost array:" + ghosts.Length); Debug.Log("pet array:" + pets.Length); if (ghosts.Length - 1 < 0) { EventManager.TriggerEvent(GameEvent.levelFinished); EventManager.TriggerEvent(GameEvent.playerWon); Debug.Log("player won triggered, level finsihed trigger"); } else if (pets.Length - 1 < 0) { EventManager.TriggerEvent(GameEvent.levelFinished); EventManager.TriggerEvent(GameEvent.playerLost); Debug.Log("player lost triggered, level finish triggered"); } } PetUtility.WaitAndDo(0.03f, Check); //because the unit is destroied later }
public void StepTwo() { if (twoDone) { return; } if (!started) { started = true; if (target == null) { target = FindObjectOfType <Pet>(); } tutor.ShowStepTwo(); PetUtility.TutorialPause(); EventManager.TriggerEvent(GameEvent.scrollFreezed); } if (target.rest) { tutor.CloseStepTwo(); started = false; PetUtility.ContinueGame(); EventManager.TriggerEvent(GameEvent.scrollUnfreezed); twoDone = true; } }
public void OpenMenu() { Menu.SetActive(true); //pause all game content (ghosts, pets) PetUtility.PauseGame(); }
private void UpdataRoute() { if (RouteRangeCheck() && nextPoint.Equals(unit.destination)) { arrive = true; rigid.velocity = Vector2.zero; } else { arrive = false; } if (arrive) { return; } if (!oldValue.Equals(unit.destination)) { nextPoint = PetUtility.FindNextWayPoint(unit.transform.position, unit.destination); oldValue.Set(unit.destination.x, unit.destination.y); } DoorCheck(); if (nearDoor) { nextPoint = PetUtility.FindNextWayPoint(unit.transform.position, unit.destination); //Debug.Log(nextPoint); } nextPoint = PetUtility.FindNextWayPoint(unit.transform.position, unit.destination); //control the patroling of the unit if (nearDoor && RouteRangeCheck()) { //Debug.Log("try go next floor"); rigid.velocity = Vector2.zero; enterDoor = true; unit.enterDoor = true; return; } else if (RouteRangeCheck()) { nextPoint = PetUtility.FindNextWayPoint(unit.transform.position, unit.destination); } if (!enterDoor) { if (nextPoint.x > transform.position.x) { rigid.velocity = Vector2.right * unit.velocity; //todo:maybe the flip could be done by unitbehaviour transform.rotation = Quaternion.Euler(0, 0, 0); } else { rigid.velocity = Vector2.left * unit.velocity; transform.rotation = Quaternion.Euler(0, 180, 0); } } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Log("Creating Health Bar"); //create a health bar for this object PetUtility.CreateHealthBar(animator.gameObject.GetComponent <UnitBehaviour>()); EventManager.TriggerEvent(ParameterizedGameEvent.unitRespawn, animator.GetComponent <UnitBehaviour>()); }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (fish.launchingAttack) { //checking hit RaycastHit2D hit2D; //if hit a wall, change direction hit2D = Cast("Wall"); if (hit2D) { direction = -direction; PetUtility.FlipTransform(fish.transform); passedEnemies.Clear(); } //if hit an enemy, attack enemy hit2D = Cast("Ghost"); if (hit2D) { Ghost ghost = hit2D.collider.GetComponent <Ghost>(); if (!passedEnemies.Contains(ghost)) { ghost.TakeDamage(fish.damage); passedEnemies.Add(ghost); } } //if comeback to origin position, stop launching attack and set the timer for next attack if (Mathf.Abs(fish.transform.position.x - start.x) <= fish.rollingSpeed / 29 && (PetUtility.GetSameFloorGhost(fish.transform.position) == null) && rolling) { fish.GetComponent <Rigidbody2D>().velocity = Vector2.zero; //Debug.Log("Back To Start!"); rolling = false; void FinishAttack() { fish.launchingAttack = false; stopTime = Time.time; } PetUtility.WaitAndDo(fish.rollingGap, FinishAttack); return; } else if (rolling) { //setting velocity Vector2 velocity = fish.GetComponent <Rigidbody2D>().velocity; velocity.x = fish.rollingSpeed * direction; fish.GetComponent <Rigidbody2D>().velocity = velocity; } } else if (Time.time - fish.rollingGap >= stopTime) { //start Rolling fish.launchingAttack = true; rolling = true; Init(animator); } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { transform = animator.transform; rigid = transform.GetComponent <Rigidbody2D>(); unit = animator.GetComponent <UnitBehaviour>(); nextPoint = PetUtility.FindNextWayPoint(unit.transform.position, unit.destination); enterDoor = false; unit.enterDoor = false; UpdataRoute(); }
public void levelLost() { loseScreen.SetActive(true); toTown.gameObject.SetActive(true); retry.gameObject.SetActive(true); nightTime.SetActive(false); dayTime.SetActive(true); PetUtility.PauseGame(); }
private void Exit() { void startWalking() { unit.enterDoor = false; } PetUtility.Coroutine(PetUtility.LinearZoom(Vector3.zero, originScale, exitTime, gameObject.transform)); PetUtility.WaitAndDo(exitTime, startWalking); }
public void Parse(GameClient Session, ClientPacket Packet) { string str = Packet.PopString(); ServerPacket Response = new ServerPacket(ServerPacketHeader.CheckPetNameMessageComposer); Response.WriteInteger(PetUtility.CheckPetName(str) ? 0 : 2); Response.WriteString(str); Session.SendPacket(Response); }
void Release() { selected = false; if (iAmPet && TryFindOffer()) { ActiveUnit(); Destroy(gameObject); PetUtility.WaitAndDo(0.1f, scroller.RerangeCards); } //put down the pet once its released }
protected virtual void Attack() { unit.launchingAttack = true; PetUtility.Coroutine(LaunchAttack()); //Debug.Log("try get enemy"); UnitBehaviour enemy = unit.enemy.GetComponent <UnitBehaviour>(); //Debug.Log(enemy != null); int damage = unit.damage; enemy.TakeDamage(damage); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { unit = animator.GetComponent <UnitBehaviour>(); direction = -PetUtility.GetFloorDirection(unit.transform.position); if (direction == Vector2.left) { unit.transform.rotation = Quaternion.Euler(0, 180, 0); } else { unit.transform.rotation = Quaternion.Euler(0, 0, 0); } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { bool close = Mathf.Abs(pet.GetBed().transform.position.x - pet.transform.position.x) <= tolerence; bool sameFloor = PetUtility.GetFloorNumber(pet.GetBed().transform.position) == PetUtility.GetFloorNumber(pet.transform.position); if (close && sameFloor) { pet.bedNearby = true; } else { pet.bedNearby = false; } }
protected virtual void OnSceneGUI() { UnitBehaviour unit = (UnitBehaviour)target; if (unit.routePoints.Length <= 0) { return; } Handles.color = Color.red; Handles.DrawLine(unit.transform.position, unit.routePoints[0]); for (int i = 0; i < unit.routePoints.Length - 1; i++) { Handles.DrawLine(unit.routePoints[i], unit.routePoints[i + 1]); } //change target position EditorGUI.BeginChangeCheck(); Vector3 newTargetPosition = Handles.PositionHandle(unit.destination, Quaternion.identity); if (!lastDes.Equals(unit.destination)) { unit.routePoints = PetUtility.FindRoute(unit.transform.position, unit.destination); } lastDes.x = unit.destination.x; lastDes.y = unit.destination.y; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(unit, "change routes"); unit.destination = newTargetPosition; unit.routePoints = PetUtility.FindRoute(unit.transform.position, unit.destination); //spider.Update() } Handles.Label(unit.destination, unit.gameObject.name + " destination"); Handles.DrawLine(unit.destination, unit.transform.position); //for (int i = 0; i < whiteGhost.routePoints.Length; i++) { // EditorGUI.BeginChangeCheck(); // Vector3 newTargetPosition = Handles.PositionHandle(whiteGhost.routePoints[i], Quaternion.identity); // if (EditorGUI.EndChangeCheck()) { // Undo.RecordObject(whiteGhost, "change routes"); // whiteGhost.routePoints[i] = newTargetPosition; // //spider.Update() // } //} }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { pet = animator.gameObject.GetComponent <Pet>(); //Debug.Log("bed position: " + pet.GetBed().transform.position); bool close = Mathf.Abs(pet.GetBed().transform.position.x - pet.transform.position.x) <= tolerence; bool sameFloor = PetUtility.GetFloorNumber(pet.GetBed().transform.position) == PetUtility.GetFloorNumber(pet.transform.position); if (close && sameFloor) { pet.bedNearby = true; } else { pet.bedNearby = false; } }
private void Split() { Debug.Log("try to split"); //split into 2 small ghosts, move from center to 2 sides. GameObject leftGhost, rightGhost; leftGhost = Instantiate(blueGhost, transform.position, Quaternion.identity); rightGhost = Instantiate(redGhost, transform.position, Quaternion.identity); float heightDifference = 0.3f; Vector2 from = (Vector2)transform.position + Vector2.down * heightDifference; Vector2 leftDes = from + Vector2.left * (splitDistance / 2f); Vector2 rightDes = from + Vector2.right * (splitDistance / 2f); PetUtility.Coroutine(PetUtility.SublinearMove(from, leftDes, 0.25f, leftGhost.transform)); PetUtility.Coroutine(PetUtility.SublinearMove(from, rightDes, 0.25f, rightGhost.transform)); }
public static bool CanGiftItem(CatalogItem Item) { if (!Item.Data.AllowGift || Item.IsLimited || Item.Amount > 1 || Item.Data.ItemName.ToLower().StartsWith("cf_") || Item.Data.ItemName.ToLower().StartsWith("cfc_") || Item.Data.InteractionType == InteractionType.BADGE || (Item.Data.Type != 's' && Item.Data.Type != 'i') || Item.CostDiamonds > 0 || Item.Data.InteractionType == InteractionType.TELEPORT || Item.Data.InteractionType == InteractionType.DEAL) { return(false); } if (Item.Data.IsRare) { return(false); } if (PetUtility.IsPet(Item.Data.InteractionType)) { return(false); } return(true); }
private void Enter() { //Debug.Log("enter door"); //you want play the animation, wait, teleport and change state if (!entering) { entering = true; void exitDoor() { gameObject.transform.position = door.OtherEndPos(); entering = false; Exit(); } PetUtility.Coroutine (PetUtility.LinearZoom(originScale, Vector3.zero, enterTime, gameObject.transform)); PetUtility.WaitAndDo(enterTime, exitDoor); } }
public void levelWon() { if (levelNumber < 6) { winScreen.SetActive(true); toTown.gameObject.SetActive(true); nextLvl.gameObject.SetActive(true); nightTime.SetActive(false); dayTime.SetActive(true); PetUtility.PauseGame(); } else { //all levels are finished winScreen.SetActive(true); resetButton.SetActive(true); nightTime.SetActive(false); dayTime.SetActive(true); PetUtility.PauseGame(); } }
public void StepFour() { if (fourDone) { return; } if (!started) { //disable all other beds deactivated.Clear(); foreach (Bed bed in FindObjectsOfType <Bed>()) { if (bed != desiredBed2 && !bed.IsOccupied()) { bed.gameObject.SetActive(false); deactivated.Add(bed); } } //cover up all other cards //a pommy is draged into desired beds tutor.ShowStepFour(); PetUtility.TutorialPause(); started = true; EventManager.TriggerEvent(GameEvent.scrollFreezed); } if (desiredBed2.IsOccupied()) { //reactivate all other beds foreach (Bed bed in deactivated) { bed.gameObject.SetActive(true); } tutor.CloseStepFour(); PetUtility.ContinueGame(); started = false; fourDone = true; EventManager.TriggerEvent(GameEvent.scrollUnfreezed); } }
private void CheckGhost() { Ghost ghost = null; if (!pet.upstairFirst) { if (pet.checkDownstair) { ghost = PetUtility.GetDownstairGhost(pet.transform.position); } if (pet.checkUpstair && (ghost == null)) { ghost = PetUtility.GetUpstairGhost(pet.transform.position); //Debug.Log("check downstair"); } } else { if (pet.checkUpstair) { ghost = PetUtility.GetUpstairGhost(pet.transform.position); } if (pet.checkDownstair && (ghost == null)) { ghost = PetUtility.GetDownstairGhost(pet.transform.position); //Debug.Log("check downstair"); } } if (ghost != null) { //Debug.Log("we found ghost: " + ghost.name); pet.enemyInHouse = true; pet.enemy = ghost.gameObject; } else { pet.enemyInHouse = false; pet.enemy = null; } }
public void StepThree() { if (threeDone) { return; } if (!started) { tutor.ShowStepThree(); PetUtility.TutorialPause(); started = true; EventManager.TriggerEvent(GameEvent.scrollFreezed); } if (InputManager.InputIsPressing()) { tutor.CloseStepThree(); PetUtility.ContinueGame(); started = false; threeDone = true; EventManager.TriggerEvent(GameEvent.scrollUnfreezed); } }
public virtual void TakeDamage(float damage) { float changeColorTime = 0.08f; foreach (SpriteRenderer r in gameObject.GetComponentsInChildren <SpriteRenderer>()) { if (r.gameObject.layer == 1) { continue; } r.color = Color.red; } lastDamageTime = Time.time; void restoreColor() { if (renderer != null && Time.time - lastDamageTime > changeColorTime) { foreach (SpriteRenderer r in gameObject.GetComponentsInChildren <SpriteRenderer>()) { if (r.gameObject.layer == 1) { continue; //layer 1 is transparentFX, should be ignored } r.color = originColors[r]; } } } PetUtility.WaitAndDo(changeColorTime, restoreColor); health -= damage; EventManager.TriggerEvent(ParameterizedGameEvent.unitHealthChange, this); if (health <= 0) { Kill(); } }
private bool btnLastState = false; //the last state of the toggle, so we don't repeatly continue the game public void Update() { if (toggle.isOn == true) { background.sprite = pauseImage; pauseCentreText.SetActive(false); FadePanel.SetActive(false); //resume all game content (ghosts, pets) (same as a method in the MenuPopup script) if (!btnLastState) { PetUtility.ContinueGame(); } btnLastState = true; menuB.enabled = true; } if (toggle.isOn == false) { background.sprite = playImage; FadePanel.SetActive(true); pauseCentreText.SetActive(true); //pause all game content (ghosts, pets) (same as a method in the MenuPopup script) PetUtility.PauseGame(); if (btnLastState) { PetUtility.PauseGame(); } btnLastState = false; menuB.enabled = false; } }
public void StepSix() { if (sixDone) { return; } if (!started) { tutor.ShowStepSix(); PetUtility.TutorialPause(); started = true; EventManager.TriggerEvent(GameEvent.scrollUnfreezed); } if (InputManager.InputIsPressing()) { tutor.CloseStepSix(); PetUtility.ContinueGame(); started = false; sixDone = true; Destroy(gameObject); EventManager.TriggerEvent(GameEvent.scrollUnfreezed); } }
public void Parse(GameClient session, ClientPacket packet) { int pageId = packet.PopInt(); int itemId = packet.PopInt(); string data = packet.PopString(); string giftUser = StringCharFilter.Escape(packet.PopString()); string giftMessage = StringCharFilter.Escape(packet.PopString().Replace(Convert.ToChar(5), ' ')); int spriteId = packet.PopInt(); int ribbon = packet.PopInt(); int colour = packet.PopInt(); packet.PopBoolean(); if (PlusEnvironment.GetSettingsManager().TryGetValue("room.item.gifts.enabled") != "1") { session.SendNotification("The hotel managers have disabled gifting"); return; } if (!PlusEnvironment.GetGame().GetCatalog().TryGetPage(pageId, out CatalogPage page)) { return; } if (!page.Enabled || !page.Visible || page.MinimumRank > session.GetHabbo().Rank || page.MinimumVIP > session.GetHabbo().VIPRank&& session.GetHabbo().Rank == 1) { return; } if (!page.Items.TryGetValue(itemId, out CatalogItem item)) { if (page.ItemOffers.ContainsKey(itemId)) { item = page.ItemOffers[itemId]; if (item == null) { return; } } else { return; } } if (!ItemUtility.CanGiftItem(item)) { return; } if (!PlusEnvironment.GetGame().GetItemManager().GetGift(spriteId, out ItemData presentData) || presentData.InteractionType != InteractionType.GIFT) { return; } if (session.GetHabbo().Credits < item.CostCredits) { session.SendPacket(new PresentDeliverErrorMessageComposer(true, false)); return; } if (session.GetHabbo().Duckets < item.CostPixels) { session.SendPacket(new PresentDeliverErrorMessageComposer(false, true)); return; } Habbo habbo = PlusEnvironment.GetHabboByUsername(giftUser); if (habbo == null) { session.SendPacket(new GiftWrappingErrorComposer()); return; } if (!habbo.AllowGifts) { session.SendNotification("Oops, this user doesn't allow gifts to be sent to them!"); return; } if ((DateTime.Now - session.GetHabbo().LastGiftPurchaseTime).TotalSeconds <= 15.0) { session.SendNotification("You're purchasing gifts too fast! Please wait 15 seconds!"); session.GetHabbo().GiftPurchasingWarnings += 1; if (session.GetHabbo().GiftPurchasingWarnings >= 25) { session.GetHabbo().SessionGiftBlocked = true; } return; } if (session.GetHabbo().SessionGiftBlocked) { return; } string ed = giftUser + Convert.ToChar(5) + giftMessage + Convert.ToChar(5) + session.GetHabbo().Id + Convert.ToChar(5) + item.Data.Id + Convert.ToChar(5) + spriteId + Convert.ToChar(5) + ribbon + Convert.ToChar(5) + colour; int newItemId; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { //Insert the dummy item. dbClient.SetQuery("INSERT INTO `items` (`base_item`,`user_id`,`extra_data`) VALUES (@baseId, @habboId, @extra_data)"); dbClient.AddParameter("baseId", presentData.Id); dbClient.AddParameter("habboId", habbo.Id); dbClient.AddParameter("extra_data", ed); newItemId = Convert.ToInt32(dbClient.InsertQuery()); string itemExtraData = null; switch (item.Data.InteractionType) { case InteractionType.NONE: itemExtraData = ""; break; #region Pet handling case InteractionType.PET: try { string[] bits = data.Split('\n'); string petName = bits[0]; string race = bits[1]; string color = bits[2]; if (PetUtility.CheckPetName(petName)) { return; } if (race.Length > 2) { return; } if (color.Length != 6) { return; } PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(session, "ACH_PetLover", 1); } catch { return; } break; #endregion case InteractionType.FLOOR: case InteractionType.WALLPAPER: case InteractionType.LANDSCAPE: double number = 0; try { number = string.IsNullOrEmpty(data) ? 0 : double.Parse(data, PlusEnvironment.CultureInfo); } catch { //ignored } itemExtraData = number.ToString(CultureInfo.CurrentCulture).Replace(',', '.'); break; // maintain extra data // todo: validate case InteractionType.POSTIT: itemExtraData = "FFFF33"; break; case InteractionType.MOODLIGHT: itemExtraData = "1,1,1,#000000,255"; break; case InteractionType.TROPHY: itemExtraData = session.GetHabbo().Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + Convert.ToChar(9) + data; break; case InteractionType.MANNEQUIN: itemExtraData = "m" + Convert.ToChar(5) + ".ch-210-1321.lg-285-92" + Convert.ToChar(5) + "Default Mannequin"; break; case InteractionType.BADGE_DISPLAY: if (!session.GetHabbo().GetBadgeComponent().HasBadge(data)) { session.SendPacket(new BroadcastMessageAlertComposer("Oops, it appears that you do not own this badge.")); return; } itemExtraData = data + Convert.ToChar(9) + session.GetHabbo().Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year; break; default: itemExtraData = data; break; } //Insert the present, forever. dbClient.SetQuery("INSERT INTO `user_presents` (`item_id`,`base_id`,`extra_data`) VALUES (@itemId, @baseId, @extra_data)"); dbClient.AddParameter("itemId", newItemId); dbClient.AddParameter("baseId", item.Data.Id); dbClient.AddParameter("extra_data", string.IsNullOrEmpty(itemExtraData) ? "" : itemExtraData); dbClient.RunQuery(); //Here we're clearing up a record, this is dumb, but okay. dbClient.SetQuery("DELETE FROM `items` WHERE `id` = @deleteId LIMIT 1"); dbClient.AddParameter("deleteId", newItemId); dbClient.RunQuery(); } Item giveItem = ItemFactory.CreateGiftItem(presentData, habbo, ed, ed, newItemId); if (giveItem != null) { GameClient receiver = PlusEnvironment.GetGame().GetClientManager().GetClientByUserId(habbo.Id); if (receiver != null) { receiver.GetHabbo().GetInventoryComponent().TryAddItem(giveItem); receiver.SendPacket(new FurniListNotificationComposer(giveItem.Id, 1)); receiver.SendPacket(new PurchaseOKComposer()); receiver.SendPacket(new FurniListAddComposer(giveItem)); receiver.SendPacket(new FurniListUpdateComposer()); } if (habbo.Id != session.GetHabbo().Id&& !string.IsNullOrWhiteSpace(giftMessage)) { PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(session, "ACH_GiftGiver", 1); if (receiver != null) { PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(receiver, "ACH_GiftReceiver", 1); } PlusEnvironment.GetGame().GetQuestManager().ProgressUserQuest(session, QuestType.GiftOthers); } } session.SendPacket(new PurchaseOKComposer(item, presentData)); if (item.CostCredits > 0) { session.GetHabbo().Credits -= item.CostCredits; session.SendPacket(new CreditBalanceComposer(session.GetHabbo().Credits)); } if (item.CostPixels > 0) { session.GetHabbo().Duckets -= item.CostPixels; session.SendPacket(new HabboActivityPointNotificationComposer(session.GetHabbo().Duckets, session.GetHabbo().Duckets)); } session.GetHabbo().LastGiftPurchaseTime = DateTime.Now; }
public void Parse(GameClient Session, ClientPacket Packet) { if (PlusEnvironment.GetDBConfig().DBData["catalogue_enabled"] != "1") { Session.SendNotification("The hotel managers have disabled the catalogue"); return; } int PageId = Packet.PopInt(); int ItemId = Packet.PopInt(); string ExtraData = Packet.PopString(); int Amount = Packet.PopInt(); CatalogPage Page = null; if (!PlusEnvironment.GetGame().GetCatalog().TryGetPage(PageId, out Page)) { return; } if (!Page.Enabled || !Page.Visible || Page.MinimumRank > Session.GetHabbo().Rank || (Page.MinimumVIP > Session.GetHabbo().VIPRank&& Session.GetHabbo().Rank == 1)) { return; } CatalogItem Item = null; if (!Page.Items.TryGetValue(ItemId, out Item)) { if (Page.ItemOffers.ContainsKey(ItemId)) { Item = (CatalogItem)Page.ItemOffers[ItemId]; if (Item == null) { return; } } else { return; } } if (Amount < 1 || Amount > 100 || !Item.HaveOffer) { Amount = 1; } int AmountPurchase = Item.Amount > 1 ? Item.Amount : Amount; int TotalCreditsCost = Amount > 1 ? ((Item.CostCredits * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostCredits)) : Item.CostCredits; int TotalPixelCost = Amount > 1 ? ((Item.CostPixels * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostPixels)) : Item.CostPixels; int TotalDiamondCost = Amount > 1 ? ((Item.CostDiamonds * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostDiamonds)) : Item.CostDiamonds; if (Session.GetHabbo().Credits < TotalCreditsCost || Session.GetHabbo().Duckets < TotalPixelCost || Session.GetHabbo().Diamonds < TotalDiamondCost) { return; } int LimitedEditionSells = 0; int LimitedEditionStack = 0; #region Create the extradata switch (Item.Data.InteractionType) { case InteractionType.NONE: ExtraData = ""; break; case InteractionType.GUILD_ITEM: case InteractionType.GUILD_GATE: break; #region Pet handling case InteractionType.pet0: case InteractionType.pet1: case InteractionType.pet2: case InteractionType.pet3: case InteractionType.pet4: case InteractionType.pet5: case InteractionType.pet6: case InteractionType.pet7: case InteractionType.pet8: case InteractionType.pet9: case InteractionType.pet10: case InteractionType.pet11: case InteractionType.pet12: case InteractionType.pet13: //Caballo case InteractionType.pet14: case InteractionType.pet15: case InteractionType.pet16: //Mascota agregada case InteractionType.pet17: //Mascota agregada case InteractionType.pet18: //Mascota agregada case InteractionType.pet19: //Mascota agregada case InteractionType.pet20: //Mascota agregada case InteractionType.pet21: //Mascota agregada case InteractionType.pet22: //Mascota agregada case InteractionType.pet28: case InteractionType.pet29: case InteractionType.pet30: try { string[] Bits = ExtraData.Split('\n'); string PetName = Bits[0]; string Race = Bits[1]; string Color = Bits[2]; int.Parse(Race); // to trigger any possible errors if (!PetUtility.CheckPetName(PetName)) { return; } if (Race.Length > 2) { return; } if (Color.Length != 6) { return; } PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(Session, "ACH_PetLover", 1); } catch (Exception e) { Logging.LogException(e.ToString()); return; } break; #endregion case InteractionType.FLOOR: case InteractionType.WALLPAPER: case InteractionType.LANDSCAPE: Double Number = 0; try { if (string.IsNullOrEmpty(ExtraData)) { Number = 0; } else { Number = Double.Parse(ExtraData, PlusEnvironment.CultureInfo); } } catch (Exception e) { Logging.HandleException(e, "Catalog.HandlePurchase: " + ExtraData); } ExtraData = Number.ToString().Replace(',', '.'); break; // maintain extra data // todo: validate case InteractionType.POSTIT: ExtraData = "FFFF33"; break; case InteractionType.MOODLIGHT: ExtraData = "1,1,1,#000000,255"; break; case InteractionType.TROPHY: ExtraData = Session.GetHabbo().Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + Convert.ToChar(9) + ExtraData; break; case InteractionType.MANNEQUIN: ExtraData = "m" + Convert.ToChar(5) + ".ch-210-1321.lg-285-92" + Convert.ToChar(5) + "Default Mannequin"; break; case InteractionType.BADGE_DISPLAY: if (!Session.GetHabbo().GetBadgeComponent().HasBadge(ExtraData)) { Session.SendMessage(new BroadcastMessageAlertComposer("Oops, it appears that you do not own this badge.")); return; } ExtraData = ExtraData + Convert.ToChar(9) + Session.GetHabbo().Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year; break; case InteractionType.BADGE: { if (Session.GetHabbo().GetBadgeComponent().HasBadge(Item.Data.ItemName)) { Session.SendMessage(new PurchaseErrorComposer(1)); return; } break; } default: ExtraData = ""; break; } #endregion if (Item.IsLimited) { if (Item.LimitedEditionStack <= Item.LimitedEditionSells) { Session.SendNotification("This item has sold out!\n\n" + "Please note, you have not recieved another item (You have also not been charged for it!)"); Session.SendMessage(new CatalogUpdatedComposer()); Session.SendMessage(new PurchaseOKComposer()); return; } Item.LimitedEditionSells++; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.RunQuery("UPDATE `catalog_items` SET `limited_sells` = '" + Item.LimitedEditionSells + "' WHERE `id` = '" + Item.Id + "' LIMIT 1"); LimitedEditionSells = Item.LimitedEditionSells; LimitedEditionStack = Item.LimitedEditionStack; } } if (Item.CostCredits > 0) { Session.GetHabbo().Credits -= TotalCreditsCost; Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits)); } if (Item.CostPixels > 0) { Session.GetHabbo().Duckets -= TotalPixelCost; Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Duckets, Session.GetHabbo().Duckets));//Love you, Tom. } if (Item.CostDiamonds > 0) { Session.GetHabbo().Diamonds -= TotalDiamondCost; Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Diamonds, 0, 5)); } Item NewItem = null; switch (Item.Data.Type.ToString().ToLower()) { default: List <Item> GeneratedGenericItems = new List <Item>(); switch (Item.Data.InteractionType) { default: if (AmountPurchase > 1) { List <Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase); if (Items != null) { GeneratedGenericItems.AddRange(Items); } } else { NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData, 0, LimitedEditionSells, LimitedEditionStack); if (NewItem != null) { GeneratedGenericItems.Add(NewItem); } } break; case InteractionType.GUILD_GATE: case InteractionType.GUILD_ITEM: case InteractionType.GUILD_FORUM: if (AmountPurchase > 1) { List <Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase, Convert.ToInt32(ExtraData)); if (Items != null) { GeneratedGenericItems.AddRange(Items); } } else { NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData, Convert.ToInt32(ExtraData)); if (NewItem != null) { GeneratedGenericItems.Add(NewItem); } } break; case InteractionType.ARROW: case InteractionType.TELEPORT: for (int i = 0; i < AmountPurchase; i++) { List <Item> TeleItems = ItemFactory.CreateTeleporterItems(Item.Data, Session.GetHabbo()); if (TeleItems != null) { GeneratedGenericItems.AddRange(TeleItems); } } break; case InteractionType.MOODLIGHT: { if (AmountPurchase > 1) { List <Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase); if (Items != null) { GeneratedGenericItems.AddRange(Items); foreach (Item I in Items) { ItemFactory.CreateMoodlightData(I); } } } else { NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData); if (NewItem != null) { GeneratedGenericItems.Add(NewItem); ItemFactory.CreateMoodlightData(NewItem); } } } break; case InteractionType.TONER: { if (AmountPurchase > 1) { List <Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase); if (Items != null) { GeneratedGenericItems.AddRange(Items); foreach (Item I in Items) { ItemFactory.CreateTonerData(I); } } } else { NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData); if (NewItem != null) { GeneratedGenericItems.Add(NewItem); ItemFactory.CreateTonerData(NewItem); } } } break; case InteractionType.DEAL: { //Fetch the deal where the ID is this items ID. var DealItems = (from d in Page.Deals.Values.ToList() where d.Id == Item.Id select d); //This bit, iterating ONE item? How can I make this simpler foreach (CatalogDeal DealItem in DealItems) { //Here I loop the DealItems ItemDataList. foreach (CatalogItem CatalogItem in DealItem.ItemDataList.ToList()) { List <Item> Items = ItemFactory.CreateMultipleItems(CatalogItem.Data, Session.GetHabbo(), "", AmountPurchase); if (Items != null) { GeneratedGenericItems.AddRange(Items); } } } break; } } foreach (Item PurchasedItem in GeneratedGenericItems) { if (Session.GetHabbo().GetInventoryComponent().TryAddItem(PurchasedItem)) { //Session.SendMessage(new FurniListAddComposer(PurchasedItem)); Session.SendMessage(new FurniListNotificationComposer(PurchasedItem.Id, 1)); } } break; case "e": AvatarEffect Effect = null; if (Session.GetHabbo().Effects().HasEffect(Item.Data.SpriteId)) { Effect = Session.GetHabbo().Effects().GetEffectNullable(Item.Data.SpriteId); if (Effect != null) { Effect.AddToQuantity(); } } else { Effect = AvatarEffectFactory.CreateNullable(Session.GetHabbo(), Item.Data.SpriteId, 3600); } if (Effect != null) // && Session.GetHabbo().Effects().TryAdd(Effect)) { Session.SendMessage(new AvatarEffectAddedComposer(Item.Data.SpriteId, 3600)); } break; case "r": Bot Bot = BotUtility.CreateBot(Item.Data, Session.GetHabbo().Id); if (Bot != null) { Session.GetHabbo().GetInventoryComponent().TryAddBot(Bot); Session.SendMessage(new BotInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetBots())); Session.SendMessage(new FurniListNotificationComposer(Bot.Id, 5)); } else { Session.SendNotification("Oops! There was an error whilst purchasing this bot. It seems that there is no bot data for the bot!"); } break; case "b": { Session.GetHabbo().GetBadgeComponent().GiveBadge(Item.Data.ItemName, true, Session); Session.SendMessage(new FurniListNotificationComposer(0, 4)); break; } case "p": { switch (Item.Data.InteractionType) { #region Pets #region Pet 0 case InteractionType.pet0: string[] PetData = ExtraData.Split('\n'); Pet GeneratedPet = PetUtility.CreatePet(Session.GetHabbo().Id, PetData[0], 0, PetData[1], PetData[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet); break; #endregion #region Pet 1 case InteractionType.pet1: string[] PetData1 = ExtraData.Split('\n'); Pet GeneratedPet1 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData1[0], 1, PetData1[1], PetData1[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet1); break; #endregion #region Pet 2 case InteractionType.pet2: string[] PetData5 = ExtraData.Split('\n'); Pet GeneratedPet5 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData5[0], 2, PetData5[1], PetData5[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet5); break; #endregion #region Pet 3 case InteractionType.pet3: string[] PetData2 = ExtraData.Split('\n'); Pet GeneratedPet2 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData2[0], 3, PetData2[1], PetData2[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet2); break; #endregion #region Pet 4 case InteractionType.pet4: string[] PetData3 = ExtraData.Split('\n'); Pet GeneratedPet3 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData3[0], 4, PetData3[1], PetData3[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet3); break; #endregion #region Pet 5 case InteractionType.pet5: string[] PetData7 = ExtraData.Split('\n'); Pet GeneratedPet7 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData7[0], 5, PetData7[1], PetData7[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet7); break; #endregion #region Pet 6 (wrong?) case InteractionType.pet6: string[] PetData4 = ExtraData.Split('\n'); Pet GeneratedPet4 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData4[0], 6, PetData4[1], PetData4[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet4); break; #endregion #region Pet 7 (wrong?) case InteractionType.pet7: string[] PetData6 = ExtraData.Split('\n'); Pet GeneratedPet6 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData6[0], 7, PetData6[1], PetData6[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet6); break; #endregion #region Pet 8 case InteractionType.pet8: string[] PetData8 = ExtraData.Split('\n'); Pet GeneratedPet8 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData8[0], 8, PetData8[1], PetData8[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet8); break; #endregion #region Pet 8 case InteractionType.pet9: string[] PetData9 = ExtraData.Split('\n'); Pet GeneratedPet9 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData9[0], 9, PetData9[1], PetData9[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet9); break; #endregion #region Pet 10 case InteractionType.pet10: string[] PetData10 = ExtraData.Split('\n'); Pet GeneratedPet10 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData10[0], 10, PetData10[1], PetData10[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet10); break; #endregion #region Pet 11 case InteractionType.pet11: string[] PetData11 = ExtraData.Split('\n'); Pet GeneratedPet11 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData11[0], 11, PetData11[1], PetData11[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet11); break; #endregion #region Pet 12 case InteractionType.pet12: string[] PetData12 = ExtraData.Split('\n'); Pet GeneratedPet12 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData12[0], 12, PetData12[1], PetData12[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet12); break; #endregion #region Pet 13 case InteractionType.pet13: //Caballo - Horse string[] PetData13 = ExtraData.Split('\n'); Pet GeneratedPet13 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData13[0], 13, PetData13[1], PetData13[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet13); break; #endregion #region Pet 14 case InteractionType.pet14: string[] PetData14 = ExtraData.Split('\n'); Pet GeneratedPet14 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData14[0], 14, PetData14[1], PetData14[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet14); break; #endregion #region Pet 15 case InteractionType.pet15: string[] PetData15 = ExtraData.Split('\n'); Pet GeneratedPet15 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData15[0], 15, PetData15[1], PetData15[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet15); break; #endregion #region Pet 16 case InteractionType.pet16: // Mascota Agregada string[] PetData16 = ExtraData.Split('\n'); Pet GeneratedPet16 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData16[0], 16, PetData16[1], PetData16[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet16); break; #endregion #region Pet 17 case InteractionType.pet17: // Mascota Agregada string[] PetData17 = ExtraData.Split('\n'); Pet GeneratedPet17 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData17[0], 17, PetData17[1], PetData17[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet17); break; #endregion #region Pet 18 case InteractionType.pet18: // Mascota Agregada string[] PetData18 = ExtraData.Split('\n'); Pet GeneratedPet18 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData18[0], 18, PetData18[1], PetData18[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet18); break; #endregion #region Pet 19 case InteractionType.pet19: // Mascota Agregada string[] PetData19 = ExtraData.Split('\n'); Pet GeneratedPet19 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData19[0], 19, PetData19[1], PetData19[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet19); break; #endregion #region Pet 20 case InteractionType.pet20: // Mascota Agregada string[] PetData20 = ExtraData.Split('\n'); Pet GeneratedPet20 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData20[0], 20, PetData20[1], PetData20[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet20); break; #endregion #region Pet 21 case InteractionType.pet21: // Mascota Agregada string[] PetData21 = ExtraData.Split('\n'); Pet GeneratedPet21 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData21[0], 21, PetData21[1], PetData21[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet21); break; #endregion #region Pet 22 case InteractionType.pet22: // Mascota Agregada string[] PetData22 = ExtraData.Split('\n'); Pet GeneratedPet22 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData22[0], 22, PetData22[1], PetData22[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet22); break; #endregion #region Pet 28 case InteractionType.pet28: // Mascota Agregada string[] PetData28 = ExtraData.Split('\n'); Pet GeneratedPet28 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData28[0], 28, PetData28[1], PetData28[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet28); break; #endregion #region Pet 29 case InteractionType.pet29: string[] PetData29 = ExtraData.Split('\n'); Pet GeneratedPet29 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData29[0], 29, PetData29[1], PetData29[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet29); break; #endregion #region Pet 30 case InteractionType.pet30: string[] PetData30 = ExtraData.Split('\n'); Pet GeneratedPet30 = PetUtility.CreatePet(Session.GetHabbo().Id, PetData30[0], 30, PetData30[1], PetData30[2]); Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet30); break; #endregion #endregion } Session.SendMessage(new FurniListNotificationComposer(0, 3)); Session.SendMessage(new PetInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetPets())); ItemData PetFood = null; if (PlusEnvironment.GetGame().GetItemManager().GetItem(320, out PetFood)) { Item Food = ItemFactory.CreateSingleItemNullable(PetFood, Session.GetHabbo(), "", ""); if (Food != null) { Session.GetHabbo().GetInventoryComponent().TryAddItem(Food); Session.SendMessage(new FurniListNotificationComposer(Food.Id, 1)); } } break; } } Session.SendMessage(new PurchaseOKComposer(Item, Item.Data)); Session.SendMessage(new FurniListUpdateComposer()); }