Permalink
Browse files

Bots will now use abilities

  • Loading branch information...
ThaPwned committed Feb 3, 2019
1 parent f45c458 commit a431094d617b2e7c35d7f0c743c32d52a75475be
@@ -47,6 +47,7 @@
'cfg_bot_bomb_explode_xp',
'cfg_bot_bomb_defuse_xp',
'cfg_bot_hostage_rescue_xp',
'cfg_bot_ability_chance',
'cfg_github_mod_update',
'cfg_github_refresh_rate'
)
@@ -87,5 +88,6 @@
cfg_bot_bomb_explode_xp = config.cvar('bot_bomb_explode_xp', '-1', config_strings['bot_bomb_explode_xp'])
cfg_bot_bomb_defuse_xp = config.cvar('bot_bomb_defuse_xp', '-1', config_strings['bot_bomb_defuse_xp'])
cfg_bot_hostage_rescue_xp = config.cvar('bot_hostage_rescue_xp', '-1', config_strings['bot_hostage_rescue_xp'])
cfg_bot_ability_chance = config.cvar('bot_ability_chance', '0.15', config_strings['bot_ability_chance'])
cfg_github_mod_update = config.cvar('github_mod_update', '0', config_strings['github_mod_update'])
cfg_github_refresh_rate = config.cvar('github_refresh_rate', '60', config_strings['github_refresh_rate'])
@@ -0,0 +1,95 @@
# ../wcs/core/emulate/__init__.py

# ============================================================================
# >> IMPORTS
# ============================================================================
# Python Imports
# Random
from random import random

# Source.Python Imports
# Listeners
from listeners import OnConVarChanged
from listeners.tick import Repeat
from listeners.tick import RepeatStatus

# AvsD Imports
# Config
from ..config import cfg_bot_ability_chance
# Constants
from ..constants import ModuleType
from ..constants import SkillReason
# Events
from ..events import FakeEvent
# Players
from ..players.filters import PlayerReadyIter


# ============================================================================
# >> ALL DECLARATION
# ============================================================================
__all__ = (
'emulate_manager',
)


# ============================================================================
# >> CLASSES
# ============================================================================
class _EmulateManager(object):
def __init__(self):
self._repeat = Repeat(self.tick)
self._filter = PlayerReadyIter(['bot', 'alive'])

def tick(self):
chance = cfg_bot_ability_chance.get_float()

for _, wcsplayer in self._filter:
active_race = wcsplayer.active_race

for skill_name in active_race.settings.config['skills']:
if random() <= chance:
skill = active_race.skills[skill_name]

for event in ('player_ultimate', 'player_ability', 'player_ability_on', 'player_ability_off'):
if event in skill.config['event']:
if skill.is_executable() is SkillReason.ALLOWED:
if event == 'player_ultimate':
if skill._type is ModuleType.ESS_INI or skill._type is ModuleType.ESS_KEY:
skill.reset_cooldown()

skill.execute('player_ultimate', define=True)
elif event == 'player_ability':
if skill._type is ModuleType.ESS_INI or skill._type is ModuleType.ESS_KEY:
skill.reset_cooldown()

skill.execute('player_ability', define=True)
elif event == 'player_ability_on':
with FakeEvent('player_ability_on' if skill._type is ModuleType.SP else f'{skill_name}_on', userid=wcsplayer.userid) as event:
skill.execute(event.name, event)
elif event == 'player_ability_off':
with FakeEvent('player_ability_off' if skill._type is ModuleType.SP else f'{skill_name}_off', userid=wcsplayer.userid) as event:
skill.execute(event.name, event)

break

def start(self):
if self._repeat.status != RepeatStatus.RUNNING:
self._repeat.start(1)

def stop(self):
if self._repeat.status == RepeatStatus.RUNNING:
self._repeat.stop()
emulate_manager = _EmulateManager()


# ============================================================================
# >> LISTENERS
# ============================================================================
@OnConVarChanged
def on_convar_changed(convar, old_value):
if convar.name == 'wcs_bot_ability_chance':
if convar.get_float():
emulate_manager.start()
else:
emulate_manager.stop()
@@ -2,5 +2,5 @@ verbose_name = "Warcraft Source"
code_name = "Reignited"
author = "Tha Pwned"
description = "Warcraft Source using Source.Python to be faster, expandable, and flexible"
version = "2019.02.03-1"
version = "2019.02.04-1"
url = "https://forums.sourcepython.com/viewtopic.php?f=7&t=1925"
@@ -25,6 +25,8 @@
from colors import Color
# Core
from core import OutputReturn
# CVars
from cvars import cvar
# Entities
from entities.constants import RenderMode
from entities.entity import Entity
@@ -79,6 +81,7 @@
from .core.config import cfg_bot_bomb_defuse_xp
from .core.config import cfg_bot_bomb_explode_xp
from .core.config import cfg_bot_hostage_rescue_xp
from .core.config import cfg_bot_ability_chance
from .core.config import cfg_github_mod_update
from .core.config import cfg_github_refresh_rate
# Constants
@@ -91,6 +94,8 @@
from .core.database.manager import database_manager
from .core.database.thread import _repeat
from .core.database.thread import _thread
# Emulate
from .core.emulate import emulate_manager
# Events
from .core.events import FakeEvent
from .core.events import _events
@@ -245,13 +250,18 @@ def load():
for settings in item_manager.values():
settings.execute('preloadcmd')

if cfg_bot_ability_chance.get_float():
emulate_manager.start()

database_manager.execute('player offline', callback=_query_refresh_offline)
database_manager.execute('rank update', callback=_query_refresh_ranks)


def unload():
database_manager._unloading = True

emulate_manager.stop()

for _, wcsplayer in PlayerReadyIter():
OnPlayerDelete.manager.notify(wcsplayer)

@@ -58,6 +58,8 @@
en = "The XP a bot will gain for defusing the bomb (0 = disable, -1 = same as players)"
[bot_hostage_rescue_xp]
en = "The XP a bot will gain for rescuing a hostage (0 = disable, -1 = same as players)"
[bot_ability_chance]
en = "The percentage (0.0-1.0) chance bots have to use one of their usable abilities (0 = disable)"
[github_mod_update]
en = "Will automatically check for core updates, and will update (reload or server restart required) if there's a newer version available (toggle)"
[github_refresh_rate]

0 comments on commit a431094

Please sign in to comment.