def spawnNPC(etarget, ebody, players, npcs, items, env, npcsDB, envDB): tempVar = 0 body = ebody.split(';') # print(npcsDB) # print(body) npcs[getFreeKey(npcs, 90000)] = { 'name': npcsDB[int(body[0])]['name'], 'room': body[1], 'lvl': npcsDB[int(body[0])]['lvl'], 'exp': npcsDB[int(body[0])]['exp'], 'str': npcsDB[int(body[0])]['str'], 'per': npcsDB[int(body[0])]['per'], 'endu': npcsDB[int(body[0])]['endu'], 'cha': npcsDB[int(body[0])]['cha'], 'inte': npcsDB[int(body[0])]['inte'], 'agi': npcsDB[int(body[0])]['agi'], 'luc': npcsDB[int(body[0])]['luc'], 'cred': npcsDB[int(body[0])]['cred'], 'inv': npcsDB[int(body[0])]['inv'], 'isAttackable': int(body[2]), 'isStealable': int(body[3]), 'isKillable': int(body[4]), 'isAggressive': int(body[5]), 'clo_head': npcsDB[int(body[0])]['clo_head'], 'clo_larm': npcsDB[int(body[0])]['clo_larm'], 'clo_rarm': npcsDB[int(body[0])]['clo_rarm'], 'clo_lhand': npcsDB[int(body[0])]['clo_lhand'], 'clo_rhand': npcsDB[int(body[0])]['clo_rhand'], 'clo_chest': npcsDB[int(body[0])]['clo_chest'], 'clo_lleg': npcsDB[int(body[0])]['clo_lleg'], 'clo_rleg': npcsDB[int(body[0])]['clo_rleg'], 'clo_feet': npcsDB[int(body[0])]['clo_feet'], 'imp_head': npcsDB[int(body[0])]['imp_head'], 'imp_larm': npcsDB[int(body[0])]['imp_larm'], 'imp_rarm': npcsDB[int(body[0])]['imp_rarm'], 'imp_lhand': npcsDB[int(body[0])]['imp_lhand'], 'imp_rhand': npcsDB[int(body[0])]['imp_rhand'], 'imp_chest': npcsDB[int(body[0])]['imp_chest'], 'imp_lleg': npcsDB[int(body[0])]['imp_lleg'], 'imp_rleg': npcsDB[int(body[0])]['imp_rleg'], 'imp_feet': npcsDB[int(body[0])]['imp_feet'], 'hp': npcsDB[int(body[0])]['hp'], 'charge': npcsDB[int(body[0])]['charge'], 'corpseTTL': int(body[6]), 'respawn': int(body[7]), 'vocabulary': npcsDB[int(body[0])]['vocabulary'], 'talkDelay': npcsDB[int(body[0])]['talkDelay'], 'lookDescription': npcsDB[int(body[0])]['lookDescription'], 'timeTalked': 0, 'isInCombat': 0, 'lastCombatAction': 0, 'lastRoom': None, 'whenDied': None, 'randomizer': 0, 'randomFactor': npcsDB[int(body[0])]['randomFactor'], 'lastSaid': 0, 'combatVocabulary': npcsDB[int(body[0])]['combatVocabulary'] }
def spawnItem(etarget, ebody, players, npcs, items, env, npcsDB, envDB): tempVar = 0 body = ebody.split(';') items[getFreeKey(items, 200000)] = { 'id': int(body[0]), 'room': body[1], 'whenDropped': int(time.time()), 'lifespan': int(body[2]), 'owner': int(body[3]) }
def attack(params, mud, playersDB, players, rooms, npcsDB, npcs, itemsDB, items, envDB, env, eventDB, eventSchedule, id, fights, corpses): if players[id]['canAttack'] == 1: ## Target dict format example: ## ['Rat', 'npc', '$rid=4$', 0, 90006] isAlreadyAttacking = False #target = params #.lower() if players[id]['target'] != None: target = players[id]['target'][0] else: target = None targetFound = False #mud.send_message(id, "Target <" + str(target) + ">") #mud.send_message(id, "Params <" + str(params) + ">") if params == "": if target != None: for (fight, pl) in fights.items(): if fights[fight]['s1'] == players[id]['name']: isAlreadyAttacking = True currentTarget = fights[fight]['s2'] if isAlreadyAttacking == False: if players[id]['name'].lower() != target.lower(): ## See if target is a player for (pid, pl) in players.items(): if players[pid][ 'authenticated'] == True and players[pid][ 'name'].lower() == target.lower(): targetFound = True victimId = pid attackerId = id if players[pid]['room'] == players[id]['room']: fights[getFreeKey(fights)] = { 's1': players[id]['name'], 's2': target, 's1id': attackerId, 's2id': victimId, 's1type': 'pc', 's2type': 'pc', 'retaliated': 0, 'lastHit': int(time.time()) } mud.send_message( id, '<f214>Attacking <r><f32>' + target + '!') players[pid]['isInCombat'] = 1 # Tell others in the room a brawl has started for plr in players: if players[plr][ 'authenticated'] != None: if players[plr]['room'] == players[ id]['room'] and players[ plr]['name'].lower( ) != players[ id]['name'].lower( ) and players[plr][ 'name'].lower( ) != target.lower( ): mud.send_message( plr, '<f32>' + players[id]['name'] + '<r> has moved to attack <f32>' + target + '<r>!') if players[plr]['name'].lower( ) == target.lower(): mud.send_message( plr, '<f32>' + players[id]['name'] + '<r> has attacked you!') # addToScheduler('0|msg|<b63>You are being attacked by ' + players[id]['name'] + "!", pid, eventSchedule, eventDB) else: targetFound = False # mud.send_message(id, 'You cannot see ' + target + ' anywhere nearby.|') if (targetFound == False): ## See if target is an NPC for (nid, pl) in list(npcs.items()): if npcs[nid]['name'].lower() == target.lower(): victimId = players[id]['target'][4] #victimId = target attackerId = id # print('found target npc') if npcs[nid]['room'] == players[id][ 'room'] and targetFound == False: targetFound = True # print('target found!') if players[id]['room'] == npcs[nid][ 'room']: fights[getFreeKey(fights)] = { 's1': players[id]['name'], 's2': nid, 's1id': attackerId, 's2id': victimId, 's1type': 'pc', 's2type': 'npc', 'retaliated': 0, 'lastHit': int(time.time()) } mud.send_message( id, '<f214>Attacking <r><f220>' + npcs[nid]['name'] + '<r>!') players[pid]['isInCombat'] = 1 # Tell other is the room brawl has started for plr in players: if players[plr][ 'authenticated'] != None: if players[plr]['name'].lower( ) != players[id]['name'].lower( ) and players[plr][ 'room'] == players[ id]['room']: mud.send_message( plr, '<f32>' + players[id]['name'] + '<r> has moved to attack <f220>' + target + '<r>!') else: pass if targetFound == False: mud.send_message( id, 'You cannot see ' + target + ' anywhere nearby.') else: mud.send_message( id, 'You attempt hitting yourself and realise this might not be the most productive way of using your time.' ) else: if type(currentTarget) is not int: mud.send_message( id, 'You are already attacking ' + currentTarget) else: mud.send_message( id, 'You are already attacking ' + npcs[currentTarget]['name']) else: if params == "": mud.send_message( id, 'You need to target something before you can attack it!' ) else: mud.send_message( id, 'You need to "target ' + params + '" before you can attack it. Once targetted, simply type "attack".' ) else: mud.send_message( id, "There is no need to 'attack <target>'. Simply 'attack' to start combat with your current target." ) else: mud.send_message( id, 'Right now, you do not feel like you can force yourself to attack anyone or anything.' )
def drop(params, mud, playersDB, players, rooms, npcsDB, npcs, itemsDB, items, envDB, env, eventDB, eventSchedule, id, fights, corpses): itemInDB = False inventoryNotEmpty = False itemInInventory = False itemID = None itemName = None for (iid, pl) in list(itemsDB.items()): if itemsDB[iid]['name'].lower() == str(params).lower(): # ID of the item to be dropped itemID = iid itemName = itemsDB[iid]['name'] itemInDB = True break else: itemInDB = False itemName = None itemID = None # Check if inventory is not empty if len(list(players[id]['inv'])) > 0: inventoryNotEmpty = True else: inventoryNotEmpty = False # Check if item is in player's inventory for item in players[id]['inv']: if int(item) == itemID: itemInInventory = True break else: itemInInventory = False if itemInDB and inventoryNotEmpty and itemInInventory: inventoryCopy = deepcopy(players[id]['inv']) for i in inventoryCopy: if int(i) == itemID: # Remove first matching item from inventory players[id]['inv'].remove(i) break # Create item on the floor in the same room as the player items[getFreeKey(items)] = { 'id': itemID, 'room': players[id]['room'], 'whenDropped': int(time.time()), 'lifespan': 900000000, 'owner': id } # Print itemsInWorld to console for debugging purposes # for x in itemsInWorld: # print (x) # for y in itemsInWorld[x]: # print(y,':',itemsInWorld[x][y]) mud.send_message( id, 'You drop ' + itemsDB[int(i)]['article'] + ' ' + itemsDB[int(i)]['name'] + ' on the floor.') else: mud.send_message(id, 'You don`t have that!')
else: #mud.send_message(pid, npcs[nid]['vocabulary'][0]) msg = '<f220>' + npcs[nid]['name'] + '<r> says: <f9>' + npcs[nid]['combatVocabulary'][0] mud.send_message(pid, msg) npcs[nid]['randomizer'] = randint(0, npcs[nid]['randomFactor']) npcs[nid]['timeTalked'] = now # Iterate through fights and see if anyone is attacking an NPC - if so, attack him too if not in combat (TODO: and isAggressive = true) for (fid, pl) in list(fights.items()): if fights[fid]['s2id'] == nid and npcs[fights[fid]['s2id']]['isInCombat'] == 1 and fights[fid]['s1type'] == 'pc' and fights[fid]['retaliated'] == 0: # print('player is attacking npc') # BETA: set las combat action to now when attacking a player npcs[fights[fid]['s2id']]['lastCombatAction'] = int(time.time()) fights[fid]['retaliated'] = 1 npcs[fights[fid]['s2id']]['isInCombat'] = 1 fights[getFreeKey(fights)] = { 's1': npcs[fights[fid]['s2id']]['name'], 's2': players[fights[fid]['s1id']]['name'], 's1id': nid, 's2id': fights[fid]['s1id'], 's1type': 'npc', 's2type': 'pc', 'retaliated': 1, 'lastHit': int(time.time()) } print("NPC has retaliated") elif fights[fid]['s2id'] == nid and npcs[fights[fid]['s2id']]['isInCombat'] == 1 and fights[fid]['s1type'] == 'npc' and fights[fid]['retaliated'] == 0: # print('npc is attacking npc') # BETA: set las combat action to now when attacking a player npcs[fights[fid]['s2id']]['lastCombatAction'] = int(time.time()) fights[fid]['retaliated'] = 1 npcs[fights[fid]['s2id']]['isInCombat'] = 1 fights[getFreeKepy(fights)] = { 's1': npcs[fights[fid]['s2id']]['name'], 's2': players[fights[fid]['s1id']]['name'], 's1id': nid, 's2id': fights[fid]['s1id'], 's1type': 'npc', 's2type': 'npc', 'retaliated': 1, 'lastHit': int(time.time()) } # Check if NPC is still alive, if not, remove from room and create a corpse, set isInCombat to 0, set whenDied to now and remove any fights NPC was involved in if npcs[nid]['hp'] <= 0: npcs[nid]['isInCombat'] = 0 npcs[nid]['lastRoom'] = npcs[nid]['room'] npcs[nid]['whenDied'] = int(time.time()) fightsCopy = deepcopy(fights) for (fight, pl) in fightsCopy.items():