mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 07:26:19 +00:00
🆙 Init V3
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
export class FurniCategory
|
||||
{
|
||||
public static DEFAULT: number = 1;
|
||||
public static WALL_PAPER: number = 2;
|
||||
public static FLOOR: number = 3;
|
||||
public static LANDSCAPE: number = 4;
|
||||
public static POST_IT: number = 5;
|
||||
public static POSTER: number = 6;
|
||||
public static SOUND_SET: number = 7;
|
||||
public static TRAX_SONG: number = 8;
|
||||
public static PRESENT: number = 9;
|
||||
public static ECOTRON_BOX: number = 10;
|
||||
public static TROPHY: number = 11;
|
||||
public static CREDIT_FURNI: number = 12;
|
||||
public static PET_SHAMPOO: number = 13;
|
||||
public static PET_CUSTOM_PART: number = 14;
|
||||
public static PET_CUSTOM_PART_SHAMPOO: number = 15;
|
||||
public static PET_SADDLE: number = 16;
|
||||
public static GUILD_FURNI: number = 17;
|
||||
public static GAME_FURNI: number = 18;
|
||||
public static MONSTERPLANT_SEED: number = 19;
|
||||
public static MONSTERPLANT_REVIVAL: number = 20;
|
||||
public static MONSTERPLANT_REBREED: number = 21;
|
||||
public static MONSTERPLANT_FERTILIZE: number = 22;
|
||||
public static FIGURE_PURCHASABLE_SET: number = 23;
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
import { GetTickerTime, IFurnitureItemData, IObjectData } from '@nitrots/nitro-renderer';
|
||||
import { IFurnitureItem } from './IFurnitureItem';
|
||||
|
||||
export class FurnitureItem implements IFurnitureItem
|
||||
{
|
||||
private _expirationTimeStamp: number;
|
||||
private _isWallItem: boolean;
|
||||
private _songId: number;
|
||||
private _locked: boolean;
|
||||
private _id: number;
|
||||
private _ref: number;
|
||||
private _category: number;
|
||||
private _type: number;
|
||||
private _stuffData: IObjectData;
|
||||
private _extra: number;
|
||||
private _recyclable: boolean;
|
||||
private _tradeable: boolean;
|
||||
private _groupable: boolean;
|
||||
private _sellable: boolean;
|
||||
private _secondsToExpiration: number;
|
||||
private _hasRentPeriodStarted: boolean;
|
||||
private _creationDay: number;
|
||||
private _creationMonth: number;
|
||||
private _creationYear: number;
|
||||
private _slotId: string;
|
||||
private _isRented: boolean;
|
||||
private _flatId: number;
|
||||
|
||||
constructor(parser: IFurnitureItemData)
|
||||
{
|
||||
if(!parser) return;
|
||||
|
||||
this._locked = false;
|
||||
this._id = parser.itemId;
|
||||
this._type = parser.spriteId;
|
||||
this._ref = parser.ref;
|
||||
this._category = parser.category;
|
||||
this._groupable = ((parser.isGroupable) && (!(parser.rentable)));
|
||||
this._tradeable = parser.tradable;
|
||||
this._recyclable = parser.isRecycleable;
|
||||
this._sellable = parser.sellable;
|
||||
this._stuffData = parser.stuffData;
|
||||
this._extra = parser.extra;
|
||||
this._secondsToExpiration = parser.secondsToExpiration;
|
||||
this._expirationTimeStamp = parser.expirationTimeStamp;
|
||||
this._hasRentPeriodStarted = parser.hasRentPeriodStarted;
|
||||
this._creationDay = parser.creationDay;
|
||||
this._creationMonth = parser.creationMonth;
|
||||
this._creationYear = parser.creationYear;
|
||||
this._slotId = parser.slotId;
|
||||
this._songId = parser.songId;
|
||||
this._flatId = parser.flatId;
|
||||
this._isRented = parser.rentable;
|
||||
this._isWallItem = parser.isWallItem;
|
||||
}
|
||||
|
||||
public get rentable(): boolean
|
||||
{
|
||||
return this._isRented;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get ref(): number
|
||||
{
|
||||
return this._ref;
|
||||
}
|
||||
|
||||
public get category(): number
|
||||
{
|
||||
return this._category;
|
||||
}
|
||||
|
||||
public get type(): number
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get stuffData(): IObjectData
|
||||
{
|
||||
return this._stuffData;
|
||||
}
|
||||
|
||||
public set stuffData(k: IObjectData)
|
||||
{
|
||||
this._stuffData = k;
|
||||
}
|
||||
|
||||
public get extra(): number
|
||||
{
|
||||
return this._extra;
|
||||
}
|
||||
|
||||
public get recyclable(): boolean
|
||||
{
|
||||
return this._recyclable;
|
||||
}
|
||||
|
||||
public get isTradable(): boolean
|
||||
{
|
||||
return this._tradeable;
|
||||
}
|
||||
|
||||
public get isGroupable(): boolean
|
||||
{
|
||||
return this._groupable;
|
||||
}
|
||||
|
||||
public get sellable(): boolean
|
||||
{
|
||||
return this._sellable;
|
||||
}
|
||||
|
||||
public get secondsToExpiration(): number
|
||||
{
|
||||
if(this._secondsToExpiration === -1) return -1;
|
||||
|
||||
let time = -1;
|
||||
|
||||
if(this._hasRentPeriodStarted)
|
||||
{
|
||||
time = (this._secondsToExpiration - ((GetTickerTime() - this._expirationTimeStamp) / 1000));
|
||||
|
||||
if(time < 0) time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
time = this._secondsToExpiration;
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
public get creationDay(): number
|
||||
{
|
||||
return this._creationDay;
|
||||
}
|
||||
|
||||
public get creationMonth(): number
|
||||
{
|
||||
return this._creationMonth;
|
||||
}
|
||||
|
||||
public get creationYear(): number
|
||||
{
|
||||
return this._creationYear;
|
||||
}
|
||||
|
||||
public get slotId(): string
|
||||
{
|
||||
return this._slotId;
|
||||
}
|
||||
|
||||
public get songId(): number
|
||||
{
|
||||
return this._songId;
|
||||
}
|
||||
|
||||
public get locked(): boolean
|
||||
{
|
||||
return this._locked;
|
||||
}
|
||||
|
||||
public set locked(k: boolean)
|
||||
{
|
||||
this._locked = k;
|
||||
}
|
||||
|
||||
public get flatId(): number
|
||||
{
|
||||
return this._flatId;
|
||||
}
|
||||
|
||||
public get isWallItem(): boolean
|
||||
{
|
||||
return this._isWallItem;
|
||||
}
|
||||
|
||||
public get hasRentPeriodStarted(): boolean
|
||||
{
|
||||
return this._hasRentPeriodStarted;
|
||||
}
|
||||
|
||||
public get expirationTimeStamp(): number
|
||||
{
|
||||
return this._expirationTimeStamp;
|
||||
}
|
||||
|
||||
public update(parser: IFurnitureItemData): void
|
||||
{
|
||||
this._type = parser.spriteId;
|
||||
this._ref = parser.ref;
|
||||
this._category = parser.category;
|
||||
this._groupable = (parser.isGroupable && !parser.rentable);
|
||||
this._tradeable = parser.tradable;
|
||||
this._recyclable = parser.isRecycleable;
|
||||
this._sellable = parser.sellable;
|
||||
this._stuffData = parser.stuffData;
|
||||
this._extra = parser.extra;
|
||||
this._secondsToExpiration = parser.secondsToExpiration;
|
||||
this._expirationTimeStamp = parser.expirationTimeStamp;
|
||||
this._hasRentPeriodStarted = parser.hasRentPeriodStarted;
|
||||
this._creationDay = parser.creationDay;
|
||||
this._creationMonth = parser.creationMonth;
|
||||
this._creationYear = parser.creationYear;
|
||||
this._slotId = parser.slotId;
|
||||
this._songId = parser.songId;
|
||||
this._flatId = parser.flatId;
|
||||
this._isRented = parser.rentable;
|
||||
this._isWallItem = parser.isWallItem;
|
||||
}
|
||||
|
||||
public clone(): FurnitureItem
|
||||
{
|
||||
const item = new FurnitureItem(null);
|
||||
|
||||
item._expirationTimeStamp = this._expirationTimeStamp;
|
||||
item._isWallItem = this._isWallItem;
|
||||
item._songId = this._songId;
|
||||
item._locked = this._locked;
|
||||
item._id = this._id;
|
||||
item._ref = this._ref;
|
||||
item._category = this._category;
|
||||
item._type = this._type;
|
||||
item._stuffData = this._stuffData;
|
||||
item._extra = this._extra;
|
||||
item._recyclable = this._recyclable;
|
||||
item._tradeable = this._tradeable;
|
||||
item._groupable = this._groupable;
|
||||
item._sellable = this._sellable;
|
||||
item._secondsToExpiration = this._secondsToExpiration;
|
||||
item._hasRentPeriodStarted = this._hasRentPeriodStarted;
|
||||
item._creationDay = this._creationDay;
|
||||
item._creationMonth = this._creationMonth;
|
||||
item._creationYear = this._creationYear;
|
||||
item._slotId = this._slotId;
|
||||
item._isRented = this._isRented;
|
||||
item._flatId = this._flatId;
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import { FurnitureListItemParser, GetRoomEngine, IObjectData } from '@nitrots/nitro-renderer';
|
||||
import { FurniCategory } from './FurniCategory';
|
||||
import { FurnitureItem } from './FurnitureItem';
|
||||
import { GroupItem } from './GroupItem';
|
||||
|
||||
export const createGroupItem = (type: number, category: number, stuffData: IObjectData, extra: number = NaN) => new GroupItem(type, category, GetRoomEngine(), stuffData, extra);
|
||||
|
||||
const addSingleFurnitureItem = (set: GroupItem[], item: FurnitureItem, unseen: boolean) =>
|
||||
{
|
||||
const groupItems: GroupItem[] = [];
|
||||
|
||||
for(const groupItem of set)
|
||||
{
|
||||
if(groupItem.type === item.type) groupItems.push(groupItem);
|
||||
}
|
||||
|
||||
for(const groupItem of groupItems)
|
||||
{
|
||||
if(groupItem.getItemById(item.id)) return groupItem;
|
||||
}
|
||||
|
||||
const groupItem = createGroupItem(item.type, item.category, item.stuffData, item.extra);
|
||||
|
||||
groupItem.push(item);
|
||||
|
||||
if(unseen)
|
||||
{
|
||||
groupItem.hasUnseenItems = true;
|
||||
|
||||
set.unshift(groupItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
set.push(groupItem);
|
||||
}
|
||||
|
||||
return groupItem;
|
||||
};
|
||||
|
||||
const addGroupableFurnitureItem = (set: GroupItem[], item: FurnitureItem, unseen: boolean) =>
|
||||
{
|
||||
let existingGroup: GroupItem = null;
|
||||
|
||||
for(const groupItem of set)
|
||||
{
|
||||
if((groupItem.type === item.type) && (groupItem.isWallItem === item.isWallItem) && groupItem.isGroupable)
|
||||
{
|
||||
if(item.category === FurniCategory.POSTER)
|
||||
{
|
||||
if(groupItem.stuffData.getLegacyString() === item.stuffData.getLegacyString())
|
||||
{
|
||||
existingGroup = groupItem;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if(item.category === FurniCategory.GUILD_FURNI)
|
||||
{
|
||||
if(item.stuffData.compare(groupItem.stuffData))
|
||||
{
|
||||
existingGroup = groupItem;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
existingGroup = groupItem;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(existingGroup)
|
||||
{
|
||||
existingGroup.push(item);
|
||||
|
||||
if(unseen)
|
||||
{
|
||||
existingGroup.hasUnseenItems = true;
|
||||
|
||||
const index = set.indexOf(existingGroup);
|
||||
|
||||
if(index >= 0) set.splice(index, 1);
|
||||
|
||||
set.unshift(existingGroup);
|
||||
}
|
||||
|
||||
return existingGroup;
|
||||
}
|
||||
|
||||
existingGroup = createGroupItem(item.type, item.category, item.stuffData, item.extra);
|
||||
|
||||
existingGroup.push(item);
|
||||
|
||||
if(unseen)
|
||||
{
|
||||
existingGroup.hasUnseenItems = true;
|
||||
|
||||
set.unshift(existingGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
set.push(existingGroup);
|
||||
}
|
||||
|
||||
return existingGroup;
|
||||
};
|
||||
|
||||
export const addFurnitureItem = (set: GroupItem[], item: FurnitureItem, unseen: boolean) =>
|
||||
{
|
||||
if(!item.isGroupable)
|
||||
{
|
||||
addSingleFurnitureItem(set, item, unseen);
|
||||
}
|
||||
else
|
||||
{
|
||||
addGroupableFurnitureItem(set, item, unseen);
|
||||
}
|
||||
};
|
||||
|
||||
export const mergeFurniFragments = (fragment: Map<number, FurnitureListItemParser>, totalFragments: number, fragmentNumber: number, fragments: Map<number, FurnitureListItemParser>[]) =>
|
||||
{
|
||||
if(totalFragments === 1) return fragment;
|
||||
|
||||
fragments[fragmentNumber] = fragment;
|
||||
|
||||
for(const frag of fragments)
|
||||
{
|
||||
if(!frag) return null;
|
||||
}
|
||||
|
||||
const merged: Map<number, FurnitureListItemParser> = new Map();
|
||||
|
||||
for(const frag of fragments)
|
||||
{
|
||||
for(const [ key, value ] of frag) merged.set(key, value);
|
||||
|
||||
frag.clear();
|
||||
}
|
||||
|
||||
fragments = null;
|
||||
|
||||
return merged;
|
||||
};
|
||||
|
||||
export const getAllItemIds = (groupItems: GroupItem[]) =>
|
||||
{
|
||||
const itemIds: number[] = [];
|
||||
|
||||
for(const groupItem of groupItems)
|
||||
{
|
||||
let totalCount = groupItem.getTotalCount();
|
||||
|
||||
if(groupItem.category === FurniCategory.POST_IT) totalCount = 1;
|
||||
|
||||
let i = 0;
|
||||
|
||||
while(i < totalCount)
|
||||
{
|
||||
itemIds.push(groupItem.getItemByIndex(i).id);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return itemIds;
|
||||
};
|
||||
@@ -0,0 +1,461 @@
|
||||
import { IObjectData, IRoomEngine } from '@nitrots/nitro-renderer';
|
||||
import { LocalizeText } from '../utils';
|
||||
import { FurniCategory } from './FurniCategory';
|
||||
import { FurnitureItem } from './FurnitureItem';
|
||||
import { IFurnitureItem } from './IFurnitureItem';
|
||||
|
||||
export class GroupItem
|
||||
{
|
||||
private _type: number;
|
||||
private _category: number;
|
||||
private _roomEngine: IRoomEngine;
|
||||
private _stuffData: IObjectData;
|
||||
private _extra: number;
|
||||
private _isWallItem: boolean;
|
||||
private _iconUrl: string;
|
||||
private _name: string;
|
||||
private _description: string;
|
||||
private _locked: boolean;
|
||||
private _selected: boolean;
|
||||
private _hasUnseenItems: boolean;
|
||||
private _items: FurnitureItem[];
|
||||
|
||||
constructor(type: number = -1, category: number = -1, roomEngine: IRoomEngine = null, stuffData: IObjectData = null, extra: number = -1)
|
||||
{
|
||||
this._type = type;
|
||||
this._category = category;
|
||||
this._roomEngine = roomEngine;
|
||||
this._stuffData = stuffData;
|
||||
this._extra = extra;
|
||||
this._isWallItem = false;
|
||||
this._iconUrl = null;
|
||||
this._name = null;
|
||||
this._description = null;
|
||||
this._locked = false;
|
||||
this._selected = false;
|
||||
this._hasUnseenItems = false;
|
||||
this._items = [];
|
||||
}
|
||||
|
||||
public clone(): GroupItem
|
||||
{
|
||||
const groupItem = new GroupItem();
|
||||
|
||||
groupItem._type = this._type;
|
||||
groupItem._category = this._category;
|
||||
groupItem._roomEngine = this._roomEngine;
|
||||
groupItem._stuffData = this._stuffData;
|
||||
groupItem._extra = this._extra;
|
||||
groupItem._isWallItem = this._isWallItem;
|
||||
groupItem._iconUrl = this._iconUrl;
|
||||
groupItem._name = this._name;
|
||||
groupItem._description = this._description;
|
||||
groupItem._locked = this._locked;
|
||||
groupItem._selected = this._selected;
|
||||
groupItem._hasUnseenItems = this._hasUnseenItems;
|
||||
groupItem._items = this._items;
|
||||
|
||||
return groupItem;
|
||||
}
|
||||
|
||||
public prepareGroup(): void
|
||||
{
|
||||
this.setIcon();
|
||||
this.setName();
|
||||
this.setDescription();
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public getItemByIndex(index: number): FurnitureItem
|
||||
{
|
||||
return this._items[index];
|
||||
}
|
||||
|
||||
public getItemById(id: number): FurnitureItem
|
||||
{
|
||||
for(const item of this._items)
|
||||
{
|
||||
if(item.id !== id) continue;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getTradeItems(count: number): IFurnitureItem[]
|
||||
{
|
||||
const items: IFurnitureItem[] = [];
|
||||
|
||||
const furnitureItem = this.getLastItem();
|
||||
|
||||
if(!furnitureItem) return items;
|
||||
|
||||
let found = 0;
|
||||
let i = 0;
|
||||
|
||||
while(i < this._items.length)
|
||||
{
|
||||
if(found >= count) break;
|
||||
|
||||
const item = this.getItemByIndex(i);
|
||||
|
||||
if(!item.locked && item.isTradable && (item.type === furnitureItem.type))
|
||||
{
|
||||
items.push(item);
|
||||
|
||||
found++;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
public push(item: FurnitureItem): void
|
||||
{
|
||||
const items = [ ...this._items ];
|
||||
|
||||
let index = 0;
|
||||
|
||||
while(index < items.length)
|
||||
{
|
||||
let existingItem = items[index];
|
||||
|
||||
if(existingItem.id === item.id)
|
||||
{
|
||||
existingItem = existingItem.clone();
|
||||
|
||||
existingItem.locked = false;
|
||||
|
||||
items.splice(index, 1);
|
||||
|
||||
items.push(existingItem);
|
||||
|
||||
this._items = items;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
items.push(item);
|
||||
|
||||
this._items = items;
|
||||
|
||||
if(this._items.length === 1) this.prepareGroup();
|
||||
}
|
||||
|
||||
public pop(): FurnitureItem
|
||||
{
|
||||
const items = [ ...this._items ];
|
||||
|
||||
let item: FurnitureItem = null;
|
||||
|
||||
if(items.length > 0)
|
||||
{
|
||||
const index = (items.length - 1);
|
||||
|
||||
item = items[index];
|
||||
|
||||
items.splice(index, 1);
|
||||
}
|
||||
|
||||
this._items = items;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public remove(k: number): FurnitureItem
|
||||
{
|
||||
const items = [ ...this._items ];
|
||||
|
||||
let index = 0;
|
||||
|
||||
while(index < items.length)
|
||||
{
|
||||
let existingItem = items[index];
|
||||
|
||||
if(existingItem.id === k)
|
||||
{
|
||||
items.splice(index, 1);
|
||||
|
||||
this._items = items;
|
||||
|
||||
return existingItem;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getTotalCount(): number
|
||||
{
|
||||
if(this._category === FurniCategory.POST_IT)
|
||||
{
|
||||
let count = 0;
|
||||
let index = 0;
|
||||
|
||||
while(index < this._items.length)
|
||||
{
|
||||
const item = this.getItemByIndex(index);
|
||||
|
||||
count = (count + parseInt(item.stuffData.getLegacyString()));
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
return this._items.length;
|
||||
}
|
||||
|
||||
public getUnlockedCount(): number
|
||||
{
|
||||
if(this.category === FurniCategory.POST_IT) return this.getTotalCount();
|
||||
|
||||
let count = 0;
|
||||
let index = 0;
|
||||
|
||||
while(index < this._items.length)
|
||||
{
|
||||
const item = this.getItemByIndex(index);
|
||||
|
||||
if(!item.locked) count++;
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public getLastItem(): FurnitureItem
|
||||
{
|
||||
if(!this._items.length) return null;
|
||||
|
||||
const item = this.getItemByIndex((this._items.length - 1));
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public unlockAllItems(): void
|
||||
{
|
||||
const items = [ ...this._items ];
|
||||
|
||||
let index = 0;
|
||||
|
||||
while(index < items.length)
|
||||
{
|
||||
const item = items[index];
|
||||
|
||||
if(item.locked)
|
||||
{
|
||||
const newItem = item.clone();
|
||||
|
||||
newItem.locked = false;
|
||||
|
||||
items[index] = newItem;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
this._items = items;
|
||||
}
|
||||
|
||||
public lockItemIds(itemIds: number[]): boolean
|
||||
{
|
||||
const items = [ ...this._items ];
|
||||
|
||||
let index = 0;
|
||||
let updated = false;
|
||||
|
||||
while(index < items.length)
|
||||
{
|
||||
const item = items[index];
|
||||
const locked = (itemIds.indexOf(item.ref) >= 0);
|
||||
|
||||
if(item.locked !== locked)
|
||||
{
|
||||
updated = true;
|
||||
|
||||
const newItem = item.clone();
|
||||
|
||||
newItem.locked = locked;
|
||||
|
||||
items[index] = newItem;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
this._items = items;
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
private setName(): void
|
||||
{
|
||||
const k = this.getLastItem();
|
||||
|
||||
if(!k)
|
||||
{
|
||||
this._name = '';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let key = '';
|
||||
|
||||
switch(this._category)
|
||||
{
|
||||
case FurniCategory.POSTER:
|
||||
key = (('poster_' + k.stuffData.getLegacyString()) + '_name');
|
||||
break;
|
||||
case FurniCategory.TRAX_SONG:
|
||||
this._name = 'SONG_NAME';
|
||||
return;
|
||||
default:
|
||||
if(this.isWallItem)
|
||||
{
|
||||
key = ('wallItem.name.' + k.type);
|
||||
}
|
||||
else
|
||||
{
|
||||
key = ('roomItem.name.' + k.type);
|
||||
}
|
||||
}
|
||||
|
||||
this._name = LocalizeText(key);
|
||||
}
|
||||
|
||||
private setDescription(): void
|
||||
{
|
||||
this._description = '';
|
||||
}
|
||||
|
||||
private setIcon(): void
|
||||
{
|
||||
if(this._iconUrl) return;
|
||||
|
||||
let url = null;
|
||||
|
||||
if(this.isWallItem)
|
||||
{
|
||||
url = this._roomEngine.getFurnitureWallIconUrl(this._type, this._stuffData.getLegacyString());
|
||||
}
|
||||
else
|
||||
{
|
||||
url = this._roomEngine.getFurnitureFloorIconUrl(this._type);
|
||||
}
|
||||
|
||||
if(!url) return;
|
||||
|
||||
this._iconUrl = url;
|
||||
}
|
||||
|
||||
public get type(): number
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get category(): number
|
||||
{
|
||||
return this._category;
|
||||
}
|
||||
|
||||
public get stuffData(): IObjectData
|
||||
{
|
||||
return this._stuffData;
|
||||
}
|
||||
|
||||
public get extra(): number
|
||||
{
|
||||
return this._extra;
|
||||
}
|
||||
|
||||
public get iconUrl(): string
|
||||
{
|
||||
return this._iconUrl;
|
||||
}
|
||||
|
||||
public get name(): string
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public get description(): string
|
||||
{
|
||||
return this._description;
|
||||
}
|
||||
|
||||
public get hasUnseenItems(): boolean
|
||||
{
|
||||
return this._hasUnseenItems;
|
||||
}
|
||||
|
||||
public set hasUnseenItems(flag: boolean)
|
||||
{
|
||||
this._hasUnseenItems = flag;
|
||||
}
|
||||
|
||||
public get locked(): boolean
|
||||
{
|
||||
return this._locked;
|
||||
}
|
||||
|
||||
public set locked(flag: boolean)
|
||||
{
|
||||
this._locked = flag;
|
||||
}
|
||||
|
||||
public get selected(): boolean
|
||||
{
|
||||
return this._selected;
|
||||
}
|
||||
|
||||
public set selected(flag: boolean)
|
||||
{
|
||||
this._selected = flag;
|
||||
}
|
||||
|
||||
public get isWallItem(): boolean
|
||||
{
|
||||
const item = this.getItemByIndex(0);
|
||||
|
||||
return (item ? item.isWallItem : false);
|
||||
}
|
||||
|
||||
public get isGroupable(): boolean
|
||||
{
|
||||
const item = this.getItemByIndex(0);
|
||||
|
||||
return (item ? item.isGroupable : false);
|
||||
}
|
||||
|
||||
public get isSellable(): boolean
|
||||
{
|
||||
const item = this.getItemByIndex(0);
|
||||
|
||||
return (item ? item.sellable : false);
|
||||
}
|
||||
|
||||
public get items(): FurnitureItem[]
|
||||
{
|
||||
return this._items;
|
||||
}
|
||||
|
||||
public set items(items: FurnitureItem[])
|
||||
{
|
||||
this._items = items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { BotData } from '@nitrots/nitro-renderer';
|
||||
|
||||
export interface IBotItem
|
||||
{
|
||||
botData: BotData;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { IObjectData } from '@nitrots/nitro-renderer';
|
||||
|
||||
export interface IFurnitureItem
|
||||
{
|
||||
id: number;
|
||||
ref: number;
|
||||
type: number;
|
||||
stuffData: IObjectData;
|
||||
extra: number;
|
||||
category: number;
|
||||
recyclable: boolean;
|
||||
isTradable: boolean;
|
||||
isGroupable: boolean;
|
||||
sellable: boolean;
|
||||
locked: boolean;
|
||||
isWallItem: boolean;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { PetData } from '@nitrots/nitro-renderer';
|
||||
|
||||
export interface IPetItem
|
||||
{
|
||||
petData: PetData;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export interface IUnseenItemTracker
|
||||
{
|
||||
dispose(): void;
|
||||
resetCategory(category: number): boolean;
|
||||
resetItems(category: number, itemIds: number[]): boolean;
|
||||
isUnseen(category: number, itemId: number): boolean;
|
||||
removeUnseen(category: number, itemId: number): boolean;
|
||||
getIds(category: number): number[];
|
||||
getCount(category: number): number;
|
||||
getFullCount(): number;
|
||||
addItems(category: number, itemIds: number[]): void;
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import { CreateLinkEvent, FurniturePlacePaintComposer, GetRoomEngine, GetRoomSessionManager, RoomObjectCategory, RoomObjectPlacementSource, RoomObjectType } from '@nitrots/nitro-renderer';
|
||||
import { SendMessageComposer } from '../nitro';
|
||||
import { FurniCategory } from './FurniCategory';
|
||||
import { GroupItem } from './GroupItem';
|
||||
import { IBotItem } from './IBotItem';
|
||||
import { IPetItem } from './IPetItem';
|
||||
|
||||
let objectMoverRequested = false;
|
||||
let itemIdInPlacing = -1;
|
||||
|
||||
export const isObjectMoverRequested = () => objectMoverRequested;
|
||||
|
||||
export const setObjectMoverRequested = (flag: boolean) => objectMoverRequested = flag;
|
||||
|
||||
export const getPlacingItemId = () => itemIdInPlacing;
|
||||
|
||||
export const setPlacingItemId = (id: number) => (itemIdInPlacing = id);
|
||||
|
||||
export const cancelRoomObjectPlacement = () =>
|
||||
{
|
||||
if(getPlacingItemId() === -1) return;
|
||||
|
||||
GetRoomEngine().cancelRoomObjectPlacement();
|
||||
|
||||
setPlacingItemId(-1);
|
||||
setObjectMoverRequested(false);
|
||||
};
|
||||
|
||||
export const attemptPetPlacement = (petItem: IPetItem, flag: boolean = false) =>
|
||||
{
|
||||
const petData = petItem.petData;
|
||||
|
||||
if(!petData) return false;
|
||||
|
||||
const session = GetRoomSessionManager().getSession(1);
|
||||
|
||||
if(!session) return false;
|
||||
|
||||
if(!session.isRoomOwner && !session.allowPets) return false;
|
||||
|
||||
CreateLinkEvent('inventory/hide');
|
||||
|
||||
if(GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, -(petData.id), RoomObjectCategory.UNIT, RoomObjectType.PET, petData.figureData.figuredata))
|
||||
{
|
||||
setPlacingItemId(petData.id);
|
||||
setObjectMoverRequested(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const attemptItemPlacement = (groupItem: GroupItem, flag: boolean = false) =>
|
||||
{
|
||||
if(!groupItem || !groupItem.getUnlockedCount()) return false;
|
||||
|
||||
const item = groupItem.getLastItem();
|
||||
|
||||
if(!item) return false;
|
||||
|
||||
if((item.category === FurniCategory.FLOOR) || (item.category === FurniCategory.WALL_PAPER) || (item.category === FurniCategory.LANDSCAPE))
|
||||
{
|
||||
if(flag) return false;
|
||||
|
||||
SendMessageComposer(new FurniturePlacePaintComposer(item.id));
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateLinkEvent('inventory/hide');
|
||||
|
||||
let category = 0;
|
||||
let isMoving = false;
|
||||
|
||||
if(item.isWallItem) category = RoomObjectCategory.WALL;
|
||||
else category = RoomObjectCategory.FLOOR;
|
||||
|
||||
if((item.category === FurniCategory.POSTER)) // or external image from furnidata
|
||||
{
|
||||
isMoving = GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, item.id, category, item.type, item.stuffData.getLegacyString());
|
||||
}
|
||||
else
|
||||
{
|
||||
isMoving = GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, item.id, category, item.type, item.extra.toString(), item.stuffData);
|
||||
}
|
||||
|
||||
if(isMoving)
|
||||
{
|
||||
setPlacingItemId(item.ref);
|
||||
setObjectMoverRequested(true);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
export const attemptBotPlacement = (botItem: IBotItem, flag: boolean = false) =>
|
||||
{
|
||||
const botData = botItem.botData;
|
||||
|
||||
if(!botData) return false;
|
||||
|
||||
const session = GetRoomSessionManager().getSession(1);
|
||||
|
||||
if(!session || !session.isRoomOwner) return false;
|
||||
|
||||
CreateLinkEvent('inventory/hide');
|
||||
|
||||
if(GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, -(botData.id), RoomObjectCategory.UNIT, RoomObjectType.RENTABLE_BOT, botData.figure))
|
||||
{
|
||||
setPlacingItemId(botData.id);
|
||||
setObjectMoverRequested(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
@@ -0,0 +1,103 @@
|
||||
import { CreateLinkEvent, PetData } from '@nitrots/nitro-renderer';
|
||||
import { IPetItem } from './IPetItem';
|
||||
import { cancelRoomObjectPlacement, getPlacingItemId } from './InventoryUtilities';
|
||||
import { UnseenItemCategory } from './UnseenItemCategory';
|
||||
|
||||
export const getAllPetIds = (petItems: IPetItem[]) => petItems.map(item => item.petData.id);
|
||||
|
||||
export const addSinglePetItem = (petData: PetData, set: IPetItem[], unseen: boolean = true) =>
|
||||
{
|
||||
const petItem = { petData };
|
||||
|
||||
if(unseen)
|
||||
{
|
||||
//petItem.isUnseen = true;
|
||||
|
||||
set.unshift(petItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
set.push(petItem);
|
||||
}
|
||||
|
||||
return petItem;
|
||||
};
|
||||
|
||||
export const removePetItemById = (id: number, set: IPetItem[]) =>
|
||||
{
|
||||
let index = 0;
|
||||
|
||||
while(index < set.length)
|
||||
{
|
||||
const petItem = set[index];
|
||||
|
||||
if(petItem && (petItem.petData.id === id))
|
||||
{
|
||||
if(getPlacingItemId() === petItem.petData.id)
|
||||
{
|
||||
cancelRoomObjectPlacement();
|
||||
|
||||
CreateLinkEvent('inventory/open');
|
||||
}
|
||||
|
||||
set.splice(index, 1);
|
||||
|
||||
return petItem;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const processPetFragment = (set: IPetItem[], fragment: Map<number, PetData>, isUnseen: (category: number, itemId: number) => boolean) =>
|
||||
{
|
||||
const existingIds = getAllPetIds(set);
|
||||
const addedIds: number[] = [];
|
||||
const removedIds: number[] = [];
|
||||
|
||||
for(const key of fragment.keys()) (existingIds.indexOf(key) === -1) && addedIds.push(key);
|
||||
|
||||
for(const itemId of existingIds) (!fragment.get(itemId)) && removedIds.push(itemId);
|
||||
|
||||
const emptyExistingSet = (existingIds.length === 0);
|
||||
|
||||
for(const id of removedIds) removePetItemById(id, set);
|
||||
|
||||
for(const id of addedIds)
|
||||
{
|
||||
const parser = fragment.get(id);
|
||||
|
||||
if(!parser) continue;
|
||||
|
||||
addSinglePetItem(parser, set, isUnseen(UnseenItemCategory.PET, parser.id));
|
||||
}
|
||||
|
||||
return set;
|
||||
};
|
||||
|
||||
export const mergePetFragments = (fragment: Map<number, PetData>, totalFragments: number, fragmentNumber: number, fragments: Map<number, PetData>[]) =>
|
||||
{
|
||||
if(totalFragments === 1) return fragment;
|
||||
|
||||
fragments[fragmentNumber] = fragment;
|
||||
|
||||
for(const frag of fragments)
|
||||
{
|
||||
if(!frag) return null;
|
||||
}
|
||||
|
||||
const merged: Map<number, PetData> = new Map();
|
||||
|
||||
for(const frag of fragments)
|
||||
{
|
||||
for(const [ key, value ] of frag) merged.set(key, value);
|
||||
|
||||
frag.clear();
|
||||
}
|
||||
|
||||
fragments = null;
|
||||
|
||||
return merged;
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
export class TradeState
|
||||
{
|
||||
public static TRADING_STATE_READY: number = 0;
|
||||
public static TRADING_STATE_RUNNING: number = 1;
|
||||
public static TRADING_STATE_COUNTDOWN: number = 2;
|
||||
public static TRADING_STATE_CONFIRMING: number = 3;
|
||||
public static TRADING_STATE_CONFIRMED: number = 4;
|
||||
public static TRADING_STATE_COMPLETED: number = 5;
|
||||
public static TRADING_STATE_CANCELLED: number = 6;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { AdvancedMap } from '@nitrots/nitro-renderer';
|
||||
import { GroupItem } from './GroupItem';
|
||||
|
||||
export class TradeUserData
|
||||
{
|
||||
constructor(
|
||||
public userId: number = -1,
|
||||
public userName: string = '',
|
||||
public userItems: AdvancedMap<string, GroupItem> = new AdvancedMap(),
|
||||
public itemCount: number = 0,
|
||||
public creditsCount: number = 0,
|
||||
public accepts: boolean = false,
|
||||
public canTrade: boolean = false)
|
||||
{}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export class TradingNotificationType
|
||||
{
|
||||
public static ALERT_SCAM: number = 0;
|
||||
public static HOTEL_TRADING_DISABLED = 1;
|
||||
public static YOU_NOT_ALLOWED: number = 2;
|
||||
public static THEY_NOT_ALLOWED: number = 4;
|
||||
public static ROOM_DISABLED: number = 6;
|
||||
public static YOU_OPEN: number = 7;
|
||||
public static THEY_OPEN: number = 8;
|
||||
public static ERROR_WHILE_COMMIT: number = 9;
|
||||
public static THEY_CANCELLED: number = 10;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { AdvancedMap, GetSessionDataManager, IObjectData, ItemDataStructure, StringDataType } from '@nitrots/nitro-renderer';
|
||||
import { FurniCategory } from './FurniCategory';
|
||||
import { FurnitureItem } from './FurnitureItem';
|
||||
import { createGroupItem } from './FurnitureUtilities';
|
||||
import { GroupItem } from './GroupItem';
|
||||
|
||||
const isExternalImage = (spriteId: number) => GetSessionDataManager().getWallItemData(spriteId)?.isExternalImage || false;
|
||||
|
||||
export const parseTradeItems = (items: ItemDataStructure[]) =>
|
||||
{
|
||||
const existingItems = new AdvancedMap<string, GroupItem>();
|
||||
const totalItems = items.length;
|
||||
|
||||
if(totalItems)
|
||||
{
|
||||
for(const item of items)
|
||||
{
|
||||
const spriteId = item.spriteId;
|
||||
const category = item.category;
|
||||
|
||||
let name = (item.furniType + spriteId);
|
||||
|
||||
if(!item.isGroupable || isExternalImage(spriteId))
|
||||
{
|
||||
name = ('itemid' + item.itemId);
|
||||
}
|
||||
|
||||
if(item.category === FurniCategory.POSTER)
|
||||
{
|
||||
name = (item.itemId + 'poster' + item.stuffData.getLegacyString());
|
||||
}
|
||||
|
||||
else if(item.category === FurniCategory.GUILD_FURNI)
|
||||
{
|
||||
name = '';
|
||||
}
|
||||
|
||||
let groupItem = ((item.isGroupable && !isExternalImage(item.spriteId)) ? existingItems.getValue(name) : null);
|
||||
|
||||
if(!groupItem)
|
||||
{
|
||||
groupItem = createGroupItem(spriteId, category, item.stuffData);
|
||||
|
||||
existingItems.add(name, groupItem);
|
||||
}
|
||||
|
||||
groupItem.push(new FurnitureItem(item));
|
||||
}
|
||||
}
|
||||
|
||||
return existingItems;
|
||||
};
|
||||
|
||||
export const getGuildFurniType = (spriteId: number, stuffData: IObjectData) =>
|
||||
{
|
||||
let type = spriteId.toString();
|
||||
|
||||
if(!(stuffData instanceof StringDataType)) return type;
|
||||
|
||||
let i = 1;
|
||||
|
||||
while(i < 5)
|
||||
{
|
||||
type = (type + (',' + stuffData.getValue(i)));
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return type;
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
export class UnseenItemCategory
|
||||
{
|
||||
public static FURNI: number = 1;
|
||||
public static RENTABLE: number = 2;
|
||||
public static PET: number = 3;
|
||||
public static BADGE: number = 4;
|
||||
public static BOT: number = 5;
|
||||
public static GAMES: number = 6;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export * from './FurniCategory';
|
||||
export * from './FurnitureItem';
|
||||
export * from './FurnitureUtilities';
|
||||
export * from './GroupItem';
|
||||
export * from './IBotItem';
|
||||
export * from './IFurnitureItem';
|
||||
export * from './IPetItem';
|
||||
export * from './IUnseenItemTracker';
|
||||
export * from './InventoryUtilities';
|
||||
export * from './PetUtilities';
|
||||
export * from './TradeState';
|
||||
export * from './TradeUserData';
|
||||
export * from './TradingNotificationType';
|
||||
export * from './TradingUtilities';
|
||||
export * from './UnseenItemCategory';
|
||||
Reference in New Issue
Block a user