Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending the API #8

Open
GniLudio opened this issue Nov 24, 2021 · 0 comments
Open

Extending the API #8

GniLudio opened this issue Nov 24, 2021 · 0 comments

Comments

@GniLudio
Copy link

GniLudio commented Nov 24, 2021

It would be nice to have a file for extending the API.
Here is a example for extending CDOTA_BaseNPC:

export {}
declare global {
    interface CDOTA_BaseNPC {
        GetAllAbilities(): CDOTABaseAbility[];
        HasTalent(talentName: string): boolean;
        GetTalent(talentName: string): number;
        HasShard(): boolean,
        GetMissingMana(): number,
        GetAllAbilities(): CDOTABaseAbility[];
        HasTalent(talentName: string): boolean;
        GetTalent(talentName: string): number;
        FindItemByName(itemName: string): CDOTA_Item | undefined;
        RemoveItemByName(itemName: string): void;
        IsRoshan(): boolean;
        HasShard(): boolean;
    }
    interface CScriptParticleManager {
        FireParticle(particleName:string, particleAttach: ParticleAttachment, owner: CBaseEntity|undefined): void;
    }
    interface CDOTA_Buff {
        IsNull(): boolean;
    }
    interface CDOTA_PlayerResource  {
        GetAllPlayers() : CDOTAPlayer[],
    }

}

CDOTA_BaseNPC.GetAllAbilities = function() {
    let abilities: CDOTABaseAbility[] = [];
    for (let i=0; i<DOTA_MAX_ABILITIES; i++) {
        let ability = this.GetAbilityByIndex(i);
        if (ability) {
            abilities.push(ability);
        }
    }
    return abilities;
}
CDOTA_BaseNPC.HasTalent = function (talentName: string) {
    let talent = this.FindAbilityByName(talentName)
    return talent ? talent.GetLevel()>0 : false;
}
CDOTA_BaseNPC.GetTalent = function (talentName: string) {
    let talent = this.FindAbilityByName(talentName);
    return talent ? talent.GetSpecialValueFor("value") : 0;
}
CDOTA_BaseNPC.HasShard = function() {
    return this.HasModifier("modifier_item_aghanims_shard");
}
CDOTA_BaseNPC.GetMissingMana = function() {
    return this.GetMaxMana() - this.GetMana();
}
CDOTA_BaseNPC.FindItemByName = function(itemName: string) {
    for (let slot=0; slot<=16; slot++) {
        const item = this.GetItemInSlot(slot);
        if (item) return item;
    }
    return undefined;
}
CDOTA_BaseNPC.RemoveItemByName = function(itemName: string) {
    const item = this.FindItemByName(itemName);
    if (item) this.RemoveItem(item);
}
CDOTA_BaseNPC.IsRoshan = function() {
    return this.GetName() == "npc_dota_roshan";
}
CScriptParticleManager.FireParticle = function(particleName: string, particleAttach: ParticleAttachment, owner: CBaseEntity | undefined) {
    let particle = ParticleManager.CreateParticle(particleName, particleAttach, owner);
    ParticleManager.ReleaseParticleIndex(particle);
}
CDOTA_PlayerResource.GetAllPlayers = function() {
    const players = new Array<CDOTAPlayer>();
    for (let i=0; i<DOTA_MAX_PLAYERS; i++) {
        if (PlayerResource.IsValidPlayer(i)) {
            const player = PlayerResource.GetPlayer(i);
            if (player) players.push();
        }
    }
    return players;
}

P.S.: I import the extended_api-file in the GameMode.ts-file. (import "./utils/extended_api";)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant