wow97
New Member
- Apr 14, 2019
- 6
- 0
Please, help me!
@Hypothesis
You must be registered for see links
C#:
using Plus.Collections;
using Plus.HabboHotel.GameClients;
using Plus.HabboHotel.Items;
using Plus.HabboHotel.PathFinding;
using Plus.Messages;
using Plus.Messages.Parsers;
using Plus.Util;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
namespace Plus.HabboHotel.Rooms.Games
{
internal class Soccer
{
private RoomItem[] _gates;
private Room _room;
private QueuedDictionary<uint, RoomItem> _balls;
public Soccer(Room room)
{
_room = room;
_gates = new RoomItem[4];
_balls = new QueuedDictionary<uint, RoomItem>();
}
public static int GetThreadTime(int i)
{
switch (i)
{
case 1:
return 75;
case 2:
return 100;
case 3:
return 125;
case 4:
return 150;
default:
if (i != 5)
return ((i != 6) ? 200 : 350);
return 200;
}
}
internal void AddBall(RoomItem item)
{
_balls.Add(item.Id, item);
}
internal void Destroy()
{
Array.Clear(_gates, 0, _gates.Length);
_gates = null;
_room = null;
_balls.Destroy();
_balls = null;
}
internal void OnCycle()
{
_balls.OnCycle();
}
internal void OnGateRemove(RoomItem item)
{
switch (item.GetBaseItem().InteractionType)
{
case Interaction.FootballGoalGreen:
case Interaction.FootballCounterGreen:
_room.GetGameManager().RemoveFurnitureFromTeam(item, Team.green);
return;
case Interaction.FootballGoalYellow:
case Interaction.FootballCounterYellow:
_room.GetGameManager().RemoveFurnitureFromTeam(item, Team.yellow);
return;
case Interaction.FootballGoalBlue:
case Interaction.FootballCounterBlue:
_room.GetGameManager().RemoveFurnitureFromTeam(item, Team.blue);
return;
case Interaction.FootballGoalRed:
case Interaction.FootballCounterRed:
_room.GetGameManager().RemoveFurnitureFromTeam(item, Team.red);
return;
default:
return;
}
}
private IEnumerable<RoomItem> GetFootballItemsForAllTeams()
{
var items = _room.GetGameManager().GetItems(Team.red).Values.ToList();
items.AddRange(_room.GetGameManager().GetItems(Team.green).Values);
items.AddRange(_room.GetGameManager().GetItems(Team.blue).Values);
items.AddRange(_room.GetGameManager().GetItems(Team.yellow).Values);
return items;
}
private bool GameItemOverlaps(RoomItem gameItem)
{
var gameItemCoord = gameItem.Coordinate;
return
GetFootballItemsForAllTeams()
.Any(
item =>
item.AffectedTiles.Values.Any(
tile => tile.X == gameItemCoord.X && tile.Y == gameItemCoord.Y));
}
internal void OnUserWalk(RoomUser user)
{
if (user == null)
return;
foreach (RoomItem ball in _balls.Values)
{
if (user.SetX == ball.X && user.SetY == ball.Y && user.GoalX == ball.X && user.GoalY == ball.Y && user.HandelingBallStatus == 0) // super chute.
{
var userPoint = new Point(user.X, user.Y);
ball.ExtraData = "55";
ball.BallIsMoving = true;
ball.BallValue = 1;
MoveBall(ball, user.GetClient(), userPoint);
}
else if (user.X == ball.X && user.Y == ball.Y && user.HandelingBallStatus == 0)
{
var userPoint = new Point(user.SetX, user.SetY);
ball.ExtraData = "55";
ball.BallIsMoving = true;
ball.BallValue = 1;
MoveBall(ball, user.GetClient(), userPoint);
}
else
{
if (user.HandelingBallStatus == 0 && user.GoalX == ball.X && user.GoalY == ball.Y)
return;
if (user.SetX != ball.X || user.SetY != ball.Y || !user.IsWalking ||
(user.X == user.GoalX && user.Y == user.GoalY))
return;
user.HandelingBallStatus = 1;
var comeDirection = ComeDirection.GetComeDirection(new Point(user.X, user.Y), ball.Coordinate);
if (comeDirection == IComeDirection.Null)
return;
var newX = user.SetX;
var newY = user.SetY;
if (!ball.GetRoom().GetGameMap().ValidTile2(user.SetX, user.SetY) || !ball.GetRoom().GetGameMap().ItemCanBePlacedHere(user.SetX, user.SetY))
{
comeDirection = ComeDirection.InverseDirections(_room, comeDirection, user.X, user.Y);
newX = ball.X;
newY = ball.Y;
}
ComeDirection.GetNewCoords(comeDirection, ref newX, ref newY);
ball.ExtraData = "11";
MoveBall(ball, user.GetClient(), newX, newY);
}
}
}
internal bool MoveBall(RoomItem item, GameClient mover, int newX, int newY)
{
if (item == null || item.GetBaseItem() == null /*|| mover == null || mover.GetHabbo() == null*/)
return false;
if (!_room.GetGameMap().ItemCanBePlacedHere(newX, newY))
return false;
var oldRoomCoord = item.Coordinate;
var itemIsOnGameItem = GameItemOverlaps(item);
double newZ = _room.GetGameMap().Model.SqFloorHeight[newX][newY];
var mMessage = new ServerMessage();
mMessage.Init(LibraryParser.OutgoingRequest("ItemAnimationMessageComposer")); // Cf
mMessage.AppendInteger(item.Coordinate.X);
mMessage.AppendInteger(item.Coordinate.Y);
mMessage.AppendInteger(newX);
mMessage.AppendInteger(newY);
mMessage.AppendInteger(1);
mMessage.AppendInteger(item.Id);
mMessage.AppendString(TextHandling.GetString(item.Z));
mMessage.AppendString(TextHandling.GetString(newZ));
mMessage.AppendInteger(item.Id);
_room.SendMessage(mMessage);
if (oldRoomCoord.X == newX && oldRoomCoord.Y == newY)
return false;
item.SetState(newX, newY, item.Z,
Gamemap.GetAffectedTiles(item.GetBaseItem().Length, item.GetBaseItem().Width, newX, newY, item.Rot));
if (itemIsOnGameItem || mover == null || mover.GetHabbo() == null)
return false;
HandleFootballGameItems(new Point(newX, newY),
_room.GetRoomUserManager().GetRoomUserByHabbo(mover.GetHabbo().Id));
return false;
}
internal void MoveBall(RoomItem item, GameClient client, Point user)
{
try
{
item.ComeDirection = ComeDirection.GetComeDirection(user, item.Coordinate);
if (item.ComeDirection != IComeDirection.Null)
// item.ballMover = client;
new TaskFactory().StartNew(() => MoveBallProcess(item, client));
}
catch
{
}
}
internal async void MoveBallProcess(RoomItem item, GameClient client)
{
var tryes = 0;
var newX = item.Coordinate.X;
var newY = item.Coordinate.Y;
//while (tryes < 3)
{
if (_room == null || _room.GetGameMap() == null)
return;
var total = item.ExtraData == "55" ? 6 : 1;
for (var i = 0; i != total; i++)
{
if (item.ComeDirection == IComeDirection.Null)
{
item.BallIsMoving = false;
break;
}
var resetX = newX;
var resetY = newY;
ComeDirection.GetNewCoords(item.ComeDirection, ref newX, ref newY);
var ignoreUsers = false;
if (_room.GetGameMap().SquareHasUsers(newX, newY))
{
if (item.ExtraData != "55" && item.ExtraData != "44")
{
item.BallIsMoving = false;
break;
}
ignoreUsers = true;
}
if (ignoreUsers == false)
if (!_room.GetGameMap().ItemCanBePlacedHere(newX, newY))
{
item.ComeDirection = ComeDirection.InverseDirections(_room, item.ComeDirection, newX, newY);
newX = resetX;
newY = resetY;
tryes++;
if (tryes > 2)
item.BallIsMoving = false;
continue;
}
if (MoveBall(item, client, newX, newY))
{
item.BallIsMoving = false;
break;
}
int number;
int.TryParse(item.ExtraData, out number);
if (number > 11)
item.ExtraData = (int.Parse(item.ExtraData) - 11).ToString();
await Task.Delay(90);
}
item.BallValue++;
if (item.BallValue <= 6)
return;
item.BallIsMoving = false;
item.BallValue = 1;
//break;
}
}
internal void RegisterGate(RoomItem item)
{
if (_gates[0] == null)
{
item.Team = Team.blue;
_gates[0] = item;
return;
}
if (_gates[1] == null)
{
item.Team = Team.red;
_gates[1] = item;
return;
}
if (_gates[2] == null)
{
item.Team = Team.green;
_gates[2] = item;
return;
}
if (_gates[3] != null)
return;
item.Team = Team.yellow;
_gates[3] = item;
}
internal void RemoveBall(uint itemId)
{
_balls.Remove(itemId);
}
internal void UnRegisterGate(RoomItem item)
{
switch (item.Team)
{
case Team.red:
_gates[1] = null;
return;
case Team.green:
_gates[2] = null;
return;
case Team.blue:
_gates[0] = null;
return;
case Team.yellow:
_gates[3] = null;
return;
default:
return;
}
}
private static bool Veryficball(RoomUser user, int actualx, int nexx, int actualy, int nexy)
{
return PathFinder.CalculateRotation(user.X, user.Y, actualx, actualy) == user.RotBody;
}
private void HandleFootballGameItems(Point ballItemCoord, RoomUser user)
{
if (user == null || _room == null || _room.GetGameManager() == null) return;
var serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("RoomUserActionMessageComposer"));
if (_room.GetGameManager()
.GetItems(Team.red)
.Values.SelectMany(current => current.AffectedTiles.Values)
.Any(current2 => current2.X == ballItemCoord.X && current2.Y == ballItemCoord.Y))
_room.GetGameManager().AddPointToTeam(Team.red, user);
if (
_room.GetGameManager()
.GetItems(Team.green)
.Values.SelectMany(current3 => current3.AffectedTiles.Values)
.Any(current4 => current4.X == ballItemCoord.X && current4.Y == ballItemCoord.Y))
_room.GetGameManager().AddPointToTeam(Team.green, user);
if (
_room.GetGameManager()
.GetItems(Team.blue)
.Values.SelectMany(current5 => current5.AffectedTiles.Values)
.Any(current6 => current6.X == ballItemCoord.X && current6.Y == ballItemCoord.Y))
_room.GetGameManager().AddPointToTeam(Team.blue, user);
if (!_room.GetGameManager()
.GetItems(Team.yellow)
.Values.SelectMany(current7 => current7.AffectedTiles.Values)
.Any(current8 => current8.X == ballItemCoord.X && current8.Y == ballItemCoord.Y))
_room.GetGameManager().AddPointToTeam(Team.yellow, user);
serverMessage.AppendInteger(user.VirtualId);
serverMessage.AppendInteger(0);
user.GetClient().GetHabbo().CurrentRoom.SendMessage(serverMessage);
}
}
}
@Hypothesis
Last edited: