skadistats.clarity.model.Entity Java Examples

The following examples show how to use skadistats.clarity.model.Entity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 6 votes vote down vote up
@OnEntityEntered
public void onEntityEntered(Context ctx, Entity e) {
    if (e.getDtClass().getDtName().equals("CDOTAWearableItem")) {
    	Integer accountId = getEntityProperty(e, "m_iAccountID", null);
    	Integer itemDefinitionIndex = getEntityProperty(e, "m_iItemDefinitionIndex", null);
    	Integer ownerHandle = getEntityProperty(e, "m_hOwnerEntity", null);
        Entity owner = ctx.getProcessor(Entities.class).getByHandle(ownerHandle);
    	//System.err.format("%s,%s\n", accountId, itemDefinitionIndex);
    	if (accountId > 0)
    	{
        	// Get the owner (a hero entity)
        	Integer playerId = getEntityProperty(owner, "m_iPlayerID", null);
    	    Long accountId64 = 76561197960265728L + accountId;
    	    Integer playerSlot = steamid_to_playerslot.get(accountId64);
    		cosmeticsMap.put(itemDefinitionIndex, playerSlot);
    	}
    }
}
 
Example #2
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 6 votes vote down vote up
private List<Item> getHeroInventory(Context ctx, Entity eHero) {
    List<Item> inventoryList = new ArrayList<>(6);

    for (int i = 0; i < 6; i++) {
        try {
            Item item = getHeroItem(ctx, eHero, i);
            if(item != null) {
                inventoryList.add(item);
            }
        }
        catch (Exception e) {
            System.err.println(e);
        }
    }

    return inventoryList;
}
 
Example #3
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 6 votes vote down vote up
private Entry buildWardEntry(Context ctx, Entity e) { 
    Entry entry = new Entry(time); 
        boolean isObserver = !e.getDtClass().getDtName().contains("TrueSight"); 
    Integer x = getEntityProperty(e, "CBodyComponent.m_cellX", null); 
    Integer y = getEntityProperty(e, "CBodyComponent.m_cellY", null); 
    Integer z = getEntityProperty(e, "CBodyComponent.m_cellZ", null); 
    Integer life_state = getEntityProperty(e, "m_lifeState", null); 
    Integer[] pos = {x, y}; 
    entry.x = x; 
    entry.y = y; 
    entry.z = z; 
    entry.type = isObserver ? "obs" : "sen"; 
    entry.entityleft = life_state == 1; 
    entry.key = Arrays.toString(pos); 
    entry.ehandle = e.getHandle(); 
 
    if (entry.entityleft) { 
        entry.type += "_left"; 
    }
    
    Integer owner = getEntityProperty(e, "m_hOwnerEntity", null); 
    Entity ownerEntity = ctx.getProcessor(Entities.class).getByHandle(owner); 
    entry.slot = ownerEntity != null ? (Integer) getEntityProperty(ownerEntity, "m_iPlayerID", null) : null; 
    
    return entry; 
}
 
Example #4
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@OnEntityUpdated
public void onUpdated(Entity e, FieldPath[] updatedPaths, int updateCount) {
    if (!isHero(e)) {
        return;
    }
    ensureFieldPaths(e);
    boolean update = false;
    for (int i = 0; i < updateCount; i++) {
        if (updatedPaths[i].equals(mana) || updatedPaths[i].equals(maxMana)) {
            update = true;
            break;
        }
    }
    if (update) {
        System.out.format("%s (%s/%s)\n", e.getDtClass().getDtName(), e.getPropertyForFieldPath(mana), e.getPropertyForFieldPath(maxMana));
    }
}
 
Example #5
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void logCreate(DotaUserMessages.CDOTAUserMsg_ParticleManager message) {
        int entityHandle = message.getCreateParticle().getEntityHandle();
//        int entityIndex = Handle.indexForHandle(entityHandle);
//        int entitySerial = Handle.serialForHandle(entityHandle);
        Entity parent = entities.getByHandle(entityHandle);
        log.info("{} {} [index={}, entity={}({}), effect={}, attach={}]",
            getTick(),
            "PARTICLE_CREATE",
            message.getIndex(),
            entityHandle,
            parent == null ? "NOT_FOUND" : parent.getDtClass().getDtName(),
            message.getCreateParticle().getParticleNameIndex(),
            message.getCreateParticle().getAttachType()
        );
        //log.info(message.toString());
    }
 
Example #6
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void logUpdateEnt(DotaUserMessages.CDOTAUserMsg_ParticleManager message) {
    int entityHandle = message.getUpdateParticleEnt().getEntityHandle();
    Entity parent = entities.getByHandle(entityHandle);
    log.info("{} {} [index={}, entity={}({}), controlPoint={}, attachmentType={}, attachment={}, includeWearables={}]",
        getTick(),
        "PARTICLE_UPDATE_ENT",
        message.getIndex(),
        entityHandle,
        parent == null ? "NOT_FOUND" : parent.getDtClass().getDtName(),
        message.getUpdateParticleEnt().getControlPoint(),
        ParticleAttachmentType.forId(message.getUpdateParticleEnt().getAttachType()),
        message.getUpdateParticleEnt().getAttachment(),
        message.getUpdateParticleEnt().getIncludeWearables()
    );
    //log.info(message.toString());
}
 
Example #7
Source Project: clarity   Author: skadistats   File: Entities.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void processEntityCreate(int eIdx, int serial, DTClass dtClass, NetMessages.CSVCMsg_PacketEntities message, BitStream stream) {
    Baseline baseline = getBaseline(dtClass.getClassId(), message.getBaseline(), eIdx, message.getIsDelta());
    EntityState newState = baseline.state.copy();
    fieldReader.readFields(stream, dtClass, newState, null, debug);
    Entity entity = entityRegistry.create(
            eIdx, serial,
            engineType.handleForIndexAndSerial(eIdx, serial),
            dtClass);
    entity.setExistent(true);
    entity.setState(newState);
    entities.setEntity(entity);
    logModification("CREATE", entity);
    emitCreatedEvent(entity);
    processEntityEnter(entity);
    if (message.getUpdateBaseline()) {
        Baseline updatedBaseline = entityBaselines[eIdx][1 - message.getBaseline()];
        updatedBaseline.dtClassId = dtClass.getClassId();
        updatedBaseline.state = newState.copy();
    }
}
 
Example #8
Source Project: clarity   Author: skadistats   File: Entities.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Iterator<Entity> getAllByPredicate(final Predicate<Entity> predicate) {
    return new SimpleIterator<Entity>() {
        int i = -1;

        @Override
        public Entity readNext() {
            while (++i < entityCount) {
                Entity e = getByIndex(i);
                if (e != null && predicate.apply(e)) {
                    return e;
                }
            }
            return null;
        }
    };
}
 
Example #9
Source Project: clarity   Author: skadistats   File: PropertyChange.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
boolean applyInternal(Object[] value) {
    Entity e = (Entity) value[0];
    int eIdx = e.getIndex();
    TriState classMatchState = classMatchesForEntity.get(eIdx);
    if (classMatchState == TriState.UNSET) {
        classMatchState = TriState.fromBoolean(classPattern.matcher(e.getDtClass().getDtName()).matches());
        classMatchesForEntity.set(eIdx, classMatchState);
    }
    if (classMatchState != TriState.YES) {
        return false;
    }
    FieldPath fp = (FieldPath) value[1];
    TriState propertyMatchState = propertyMatchesForEntity[eIdx].get(fp);
    if (propertyMatchState == null) {
        propertyMatchState = TriState.fromBoolean(propertyPattern.matcher(e.getDtClass().getNameForFieldPath(fp)).matches());
        propertyMatchesForEntity[eIdx].put(fp, propertyMatchState);
    }
    if (propertyMatchState != TriState.YES) {
        return false;
    }
    return true;
}
 
Example #10
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
@OnMessage(CDOTAUserMsg_SpectatorPlayerUnitOrders.class)
public void onSpectatorPlayerUnitOrders(Context ctx, CDOTAUserMsg_SpectatorPlayerUnitOrders message) {
    Entry entry = new Entry(time);
    entry.type = "actions";
    //the entindex points to a CDOTAPlayer.  This is probably the player that gave the order.
    Entity e = ctx.getProcessor(Entities.class).getByIndex(message.getEntindex());
    entry.slot = getEntityProperty(e, "m_iPlayerID", null);
    //Integer handle = (Integer)getEntityProperty(e, "m_hAssignedHero", null);
    //Entity h = ctx.getProcessor(Entities.class).getByHandle(handle);
    //System.err.println(h.getDtClass().getDtName());
    //break actions into types?
    entry.key = String.valueOf(message.getOrderType());
    //System.err.println(message);
    output(entry);
}
 
Example #11
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
@OnMessage(CUserMessageSayText2.class)
public void onAllChatS2(Context ctx, CUserMessageSayText2 message) {
    Entry entry = new Entry(time);
    entry.unit = String.valueOf(message.getParam1());
    entry.key = String.valueOf(message.getParam2());
    Entity e = ctx.getProcessor(Entities.class).getByIndex(message.getEntityindex());
    entry.slot = getEntityProperty(e, "m_iPlayerID", null);
    entry.type = "chat";
    output(entry);
}
 
Example #12
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
/**
 * Uses "EntityNames" string table and Entities processor
 * @param ctx Context
 * @param eHero Hero entity
 * @param idx 0-5 - inventory, 6-8 - backpack, 9-16 - stash
 * @return {@code null} - empty slot. Throws @{@link UnknownItemFoundException} if item information can't be extracted
 */
private Item getHeroItem(Context ctx, Entity eHero, int idx) throws UnknownItemFoundException {
    StringTable stEntityNames = ctx.getProcessor(StringTables.class).forName("EntityNames");
    Entities entities = ctx.getProcessor(Entities.class);

    Integer hItem = eHero.getProperty("m_hItems." + Util.arrayIdxToString(idx));
    if (hItem == 0xFFFFFF) {
        return null;
    }
    Entity eItem = entities.getByHandle(hItem);
    if(eItem == null) {
        throw new UnknownItemFoundException(String.format("Can't find item by its handle (%d)", hItem));
    }
    String itemName = stEntityNames.getNameByIndex(eItem.getProperty("m_pEntity.m_nameStringableIndex"));
    if(itemName == null) {
        throw new UnknownItemFoundException("Can't get item name from EntityName string table");
    }

    Item item = new Item();
    item.id = itemName;
    int numCharges = eItem.getProperty("m_iCurrentCharges");
    if(numCharges != 0) {
        item.num_charges = numCharges;
    }
    int numSecondaryCharges = eItem.getProperty("m_iSecondaryCharges");
    if(numSecondaryCharges != 0) {
        item.num_secondary_charges = numSecondaryCharges;
    }

    return item;
}
 
Example #13
Source Project: parser   Author: odota   File: Parse.java    License: MIT License 5 votes vote down vote up
public <T> T getEntityProperty(Entity e, String property, Integer idx) {
	try {
     if (e == null) {
         return null;
     }
     if (idx != null) {
         property = property.replace("%i", Util.arrayIdxToString(idx));
     }
     FieldPath fp = e.getDtClass().getFieldPathForName(property);
     return e.getPropertyForFieldPath(fp);
	}
	catch (Exception ex) {
		return null;
	}
}
 
Example #14
Source Project: parser   Author: odota   File: Wards.java    License: MIT License 5 votes vote down vote up
@OnEntityCreated
public void onCreated(Context ctx, Entity e) {      
    if (!isWard(e)) return;
    
    FieldPath lifeStatePath;
    
    clearCachedState(e);
    ensureFieldPathForEntityInitialized(e);
    if ((lifeStatePath = getFieldPathForEntity(e)) != null) {
        processLifeStateChange(e, lifeStatePath);
    }
}
 
Example #15
Source Project: parser   Author: odota   File: Wards.java    License: MIT License 5 votes vote down vote up
@OnEntityUpdated
public void onUpdated(Context ctx, Entity e, FieldPath[] fieldPaths, int num) {
    FieldPath p;
    if ((p = getFieldPathForEntity(e)) != null) {
        for (int i = 0; i < num; i++) {
            if (fieldPaths[i].equals(p)) {
                toProcess.add(new ProcessEntityCommand(e, p));
                break;
            }
        }
    }
}
 
Example #16
Source Project: parser   Author: odota   File: Wards.java    License: MIT License 5 votes vote down vote up
public  void processLifeStateChange(Entity e, FieldPath p) {
    int oldState = currentLifeState.containsKey(e.getIndex()) ? currentLifeState.get(e.getIndex()) : 2;
    int newState = e.getPropertyForFieldPath(p);
    if (oldState != newState) {
        switch(newState) {
            case 0:
                if (evPlaced != null) {
                    evPlaced.raise(e);
                }
                break;
            case 1:
                String killer;
                if ((killer = wardKillersByWardClass.get(getWardTargetName(e.getDtClass().getDtName())).poll()) != null) {
                    if (evKilled != null) {
                        evKilled.raise(e, killer);
                    }
                } else {
                    if (evExpired != null) {
                        evExpired.raise(e);
                    }
                }
                break;
        }
    }
    
    currentLifeState.put(e.getIndex(), newState);
}
 
Example #17
Source Project: clarity-analyzer   Author: spheenik   File: MapControl.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void add(int from, List<? extends ObservableEntity> entities) {
    for (int i = 0; i < entities.size(); i++) {
        ObservableEntity oe = entities.get(i);
        Entity e = oe.getEntity();
        if (e == null) {
            continue;
        }
        FieldPath fp = e.getDtClass().getFieldPathForName("CBodyComponent.m_cellX");
        if (fp == null) {
            continue;
        }

        String name = oe.getEntity().getDtClass().getDtName();
        EntityIcon icon;
        if (name.equals("CDOTAPlayer")) {
            icon = new CameraIcon(oe);
        } else if (name.equals("CDOTA_BaseNPC_Barracks")) {
            icon = new BuildingIcon(oe, 250);
        } else if (name.equals("CDOTA_BaseNPC_Tower")) {
            icon = new BuildingIcon(oe, 200);
        } else if (name.equals("CDOTA_BaseNPC_Building")) {
            icon = new BuildingIcon(oe, 150);
        } else if (name.equals("CDOTA_BaseNPC_Fort")) {
            icon = new BuildingIcon(oe, 300);
        } else if (name.startsWith("CDOTA_Unit_Hero_")) {
            icon = new HeroIcon(oe);
        } else {
            icon = new DefaultIcon(oe);
        }

        mapEntities[from + i] = icon;
        icons.getChildren().add(icon.getShape());
    }
}
 
Example #18
Source Project: clarity-analyzer   Author: spheenik   File: ObservableEntity.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ObservableEntity(Entity entity) {
    this.entity = entity;
    index = new ReadOnlyStringWrapper(String.valueOf(entity.getIndex()));
    name = new ReadOnlyStringWrapper(entity.getDtClass().getDtName());
    Iterator<FieldPath> iter = entity.getState().fieldPathIterator();
    while (iter.hasNext()) {
        FieldPath fp = iter.next();
        indices.add(fp);
        properties.add(new ObservableEntityProperty(entity, fp));
    }
}
 
Example #19
Source Project: clarity-analyzer   Author: spheenik   File: ObservableEntityList.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityCreated
public void onCreate(Entity entity) {
    lock.lock();
    try {
        markChange(CF_LIST);
        int i = entity.getIndex();
        //System.out.println("create " + i);
        changes[i] = new ObservableEntity(entity);
    } finally {
        lock.unlock();
    }
}
 
Example #20
Source Project: clarity-analyzer   Author: spheenik   File: ObservableEntityList.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityUpdated
public void onUpdate(Entity entity, FieldPath[] fieldPaths, int num) {
    lock.lock();
    try {
        markChange(CF_PROP);
        int i = entity.getIndex();
        ObservableEntity e = changes[i] == null ? entities[i] : changes[i];
        e.update(fieldPaths, num);
    } finally {
        lock.unlock();
    }
}
 
Example #21
Source Project: clarity-analyzer   Author: spheenik   File: ObservableEntityList.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityDeleted
public void onDelete(Entity entity) {
    lock.lock();
    try {
        markChange(CF_LIST);
        int i = entity.getIndex();
        //System.out.println("delete " + i);
        changes[i] = new ObservableEntity(i);
    } finally {
        lock.unlock();
    }
}
 
Example #22
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityCreated
public void onCreated(Entity e) {
    if (!isHero(e)) {
        return;
    }
    ensureFieldPaths(e);
    System.out.format("%s (%s/%s)\n", e.getDtClass().getDtName(), e.getPropertyForFieldPath(mana), e.getPropertyForFieldPath(maxMana));
}
 
Example #23
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public V resolveValue(int index, int team, int pos) {
    String fieldPathString = pattern
            .replaceAll("%i", Util.arrayIdxToString(index))
            .replaceAll("%t", Util.arrayIdxToString(team))
            .replaceAll("%p", Util.arrayIdxToString(pos));
    String compiledName = entityName.replaceAll("%n", getTeamName(team));
    Entity entity = getEntity(compiledName);
    FieldPath fieldPath = entity.getDtClass().getFieldPathForName(fieldPathString);
    return entity.getPropertyForFieldPath(fieldPath);
}
 
Example #24
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityCreated
public void onCreated(Entity e) {
    FieldPath fp = e.getDtClass().getFieldPathForName("CBodyComponent.m_hModel");
    if (fp == null) {
        return;
    }
    Long resourceHandle = e.getPropertyForFieldPath(fp);
    if (resourceHandle == null || resourceHandle == 0L) {
        return;
    }
    Resources.Entry entry = resources.getEntryForResourceHandle(resourceHandle);
    System.out.format("model for entity at %d (%d): %s\n", e.getIndex(), resourceHandle, entry);
}
 
Example #25
Source Project: clarity-examples   Author: skadistats   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityPropertyChanged(classPattern = "CDOTA_Unit_Hero_.*", propertyPattern = "m_lifeState")
public void onEntityPropertyChanged(Context ctx, Entity e, FieldPath fp) {
    System.out.format(
            "%6d %s: %s = %s\n",
            ctx.getTick(),
            e.getDtClass().getDtName(),
            e.getDtClass().getNameForFieldPath(fp),
            e.getPropertyForFieldPath(fp)
    );
}
 
Example #26
Source Project: clarity-examples   Author: skadistats   File: SpawnsAndDeaths.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityCreated
public void onCreated(Context ctx, Entity e) {
    clearCachedState(e);
    ensureFieldPathForEntityInitialized(e);
    FieldPath p = getFieldPathForEntity(e);
    if (p != null) {
        processLifeStateChange(e, p);
    }
}
 
Example #27
Source Project: clarity-examples   Author: skadistats   File: SpawnsAndDeaths.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityUpdated
public void onUpdated(Context ctx, Entity e, FieldPath[] fieldPaths, int num) {
    FieldPath p = getFieldPathForEntity(e);
    if (p != null) {
        for (int i = 0; i < num; i++) {
            if (fieldPaths[i].equals(p)) {
                processLifeStateChange(e, p);
                break;
            }
        }
    }
}
 
Example #28
Source Project: clarity   Author: skadistats   File: PropertyChange.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityDeleted
@Order(1000)
public void onDeleted(Entity e) {
    for (ListenerAdapter adapter : adapters) {
        adapter.clear(e);
    }
}
 
Example #29
Source Project: clarity   Author: skadistats   File: ClientFrame.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Capsule(ClientFrame frame) {
    int size = frame.getSize();
    handle = new int[size];
    active = new boolean[size];
    for (int i = 0; i < size; i++) {
        Entity e = frame.entity[i];
        handle[i] = e != null ? e.getHandle() : -1;
        active[i] = e != null && e.isActive();
    }
}
 
Example #30
Source Project: clarity   Author: skadistats   File: TempEntities.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnMessage(S1NetMessages.CSVCMsg_TempEntities.class)
public void onTempEntities(S1NetMessages.CSVCMsg_TempEntities message) {
    if (evTempEntity.isListenedTo()) {
        BitStream stream = BitStream.createBitStream(message.getEntityData());
        S1DTClass cls = null;
        ReceiveProp[] receiveProps = null;
        int count = message.getNumEntries();
        while (count-- > 0) {
            stream.readUBitInt(1); // seems to be always 0
            if (stream.readBitFlag()) {
                cls = (S1DTClass) dtClasses.forClassId(stream.readUBitInt(dtClasses.getClassBits()) - 1);
                receiveProps = cls.getReceiveProps();
            }
            EntityState state = EntityStateFactory.forS1(receiveProps);
            fieldReader.readFields(stream, cls, state, null, false);

            int handle = engineType.emptyHandle();
            Entity te = new Entity(
                    engineType.indexForHandle(handle),
                    engineType.serialForHandle(handle),
                    handle,
                    cls);
            te.setExistent(true);
            te.setActive(true);
            te.setState(state);
            evTempEntity.raise(te);
        }
    }
}