def manage_hands(life): for item in [lfe.get_inventory_item(life, item) for item in lfe.get_held_items(life)]: judgement.judge_item(life, item["uid"]) _known_item = brain.get_remembered_item(life, item["uid"]) if _known_item["score"]: # judgement.get_score_of_highest_scoring_item(life): continue _equip_action = {"action": "equipitem", "item": item["uid"]} if len(lfe.find_action(life, matches=[_equip_action])): return True if lfe.can_wear_item(life, item["uid"]): lfe.add_action(life, _equip_action, 401, delay=lfe.get_item_access_time(life, item["uid"])) return True _storage = lfe.can_put_item_in_storage(life, item["uid"]) if not "CAN_WEAR" in item["flags"] and _storage: _store_action = {"action": "storeitem", "item": item["uid"], "container": _storage} if len(lfe.find_action(life, matches=[_store_action])): continue lfe.add_action(life, _store_action, 401, delay=lfe.get_item_access_time(life, item["uid"])) return True return False
def collect_nearby_wanted_items(life, only_visible=True, matches={'type': 'gun'}): _highest = {'item': None, 'score': -100000} _nearby = sight.find_known_items(life, matches=matches, only_visible=only_visible) for item in _nearby: _item = brain.get_remembered_item(life, item) _score = _item['score'] _score -= bad_numbers.distance(life['pos'], ITEMS[item]['pos']) if not _highest['item'] or _score > _highest['score']: _highest['score'] = _score _highest['item'] = ITEMS[item] if not _highest['item']: return True _empty_hand = lfe.get_open_hands(life) if not _empty_hand: print 'No open hands, managing....' for item_uid in lfe.get_held_items(life): _container = lfe.can_put_item_in_storage(life, item_uid) lfe.add_action(life, { 'action': 'storeitem', 'item': item_uid, 'container': _container }, 200, delay=lfe.get_item_access_time(life, item_uid)) return False if life['pos'] == _highest['item']['pos']: lfe.clear_actions(life) for action in lfe.find_action(life, matches=[{ 'action': 'pickupholditem' }]): #print 'I was picking up something else...',_highest['item']['name'] return False lfe.add_action(life, { 'action': 'pickupholditem', 'item': _highest['item']['uid'], 'hand': random.choice(_empty_hand) }, 200, delay=lfe.get_item_access_time(life, _highest['item']['uid'])) lfe.lock_item(life, _highest['item']['uid']) else: lfe.walk_to(life, _highest['item']['pos']) return False
def manage_hands(life): for item in [ lfe.get_inventory_item(life, item) for item in lfe.get_held_items(life) ]: judgement.judge_item(life, item['uid']) _known_item = brain.get_remembered_item(life, item['uid']) for weapon in combat.get_equipped_weapons(life): if item['type'] == ITEMS[weapon]['feed'] and len( item['rounds']) >= 5: combat.load_feed(life, weapon, item['uid']) return True if _known_item[ 'score']: #judgement.get_score_of_highest_scoring_item(life): continue _equip_action = {'action': 'equipitem', 'item': item['uid']} if len(lfe.find_action(life, matches=[_equip_action])): return True if lfe.can_wear_item(life, item['uid']): lfe.add_action(life, _equip_action, 401, delay=lfe.get_item_access_time(life, item['uid'])) return True _storage = lfe.can_put_item_in_storage(life, item['uid']) if not 'CAN_WEAR' in item['flags'] and _storage: _store_action = { 'action': 'storeitem', 'item': item['uid'], 'container': _storage } if len(lfe.find_action(life, matches=[_store_action])): continue lfe.add_action(life, _store_action, 401, delay=lfe.get_item_access_time(life, item['uid'])) return True return False
def collect_nearby_wanted_items(life, only_visible=True, matches={"type": "gun"}): _highest = {"item": None, "score": -100000} _nearby = sight.find_known_items(life, matches=matches, only_visible=only_visible) for item in _nearby: _item = brain.get_remembered_item(life, item) _score = _item["score"] _score -= numbers.distance(life["pos"], ITEMS[item]["pos"]) if not _highest["item"] or _score > _highest["score"]: _highest["score"] = _score _highest["item"] = ITEMS[item] if not _highest["item"]: return True _empty_hand = lfe.get_open_hands(life) if not _empty_hand: print "No open hands, managing...." for item_uid in lfe.get_held_items(life): _container = lfe.can_put_item_in_storage(life, item_uid) lfe.add_action( life, {"action": "storeitem", "item": item_uid, "container": _container}, 200, delay=lfe.get_item_access_time(life, item_uid), ) return False if life["pos"] == _highest["item"]["pos"]: lfe.clear_actions(life) for action in lfe.find_action(life, matches=[{"action": "pickupholditem"}]): # print 'I was picking up something else...',_highest['item']['name'] return False lfe.add_action( life, {"action": "pickupholditem", "item": _highest["item"]["uid"], "hand": random.choice(_empty_hand)}, 200, delay=lfe.get_item_access_time(life, _highest["item"]["uid"]), ) lfe.lock_item(life, _highest["item"]["uid"]) else: lfe.walk_to(life, _highest["item"]["pos"]) return False
def collect_nearby_wanted_items(life, only_visible=True, matches={'type': 'gun'}): _highest = {'item': None,'score': -100000} _nearby = sight.find_known_items(life, matches=matches, only_visible=only_visible) for item in _nearby: _item = brain.get_remembered_item(life, item) _score = _item['score'] _score -= numbers.distance(life['pos'], ITEMS[item]['pos']) if not _highest['item'] or _score > _highest['score']: _highest['score'] = _score _highest['item'] = ITEMS[item] if not _highest['item']: return True _empty_hand = lfe.get_open_hands(life) if not _empty_hand: print 'No open hands, managing....' for item_uid in lfe.get_held_items(life): _container = lfe.can_put_item_in_storage(life, item_uid) lfe.add_action(life, {'action': 'storeitem', 'item': item_uid, 'container': _container}, 200, delay=lfe.get_item_access_time(life, item_uid)) return False if life['pos'] == _highest['item']['pos']: lfe.clear_actions(life) for action in lfe.find_action(life, matches=[{'action': 'pickupholditem'}]): #print 'I was picking up something else...',_highest['item']['name'] return False lfe.add_action(life,{'action': 'pickupholditem', 'item': _highest['item']['uid'], 'hand': random.choice(_empty_hand)}, 200, delay=lfe.get_item_access_time(life, _highest['item']['uid'])) lfe.lock_item(life, _highest['item']['uid']) else: lfe.clear_actions(life) lfe.add_action(life,{'action': 'move','to': _highest['item']['pos'][:2]},200) return False
def pick_up_item(life, item_uid): _not_moved = travel_to_position(life, ITEMS[item_uid]["pos"]) if _not_moved: lfe.add_action( life, {"action": "pickupitem_npc", "item": item_uid}, 200, delay=lfe.get_item_access_time(life, item_uid) )
def pick_up_item(life, item_uid): _not_moved = travel_to_position(life, ITEMS[item_uid]['pos']) if _not_moved: lfe.add_action(life,{'action': 'pickupitem_npc', 'item': item_uid}, 200, delay=lfe.get_item_access_time(life, item_uid))
def manage_inventory(life): if manage_hands(life): return False for weapon_uid in combat.get_equipped_weapons(life): if not combat.weapon_is_working(life, weapon_uid): if combat.weapon_is_in_preferred_working_condition(life, weapon_uid): if not len(lfe.find_action(life,matches=[{'action': 'refillammo'}])): combat.reload_weapon(life, weapon_uid) return True _item_to_wear = {'score': 0, 'item_uid': None} _item_to_equip = {'score': 0, 'item_uid': None} for item in [lfe.get_inventory_item(life, item) for item in lfe.get_all_unequipped_items(life)]: judgement.judge_item(life, item['uid']) _known_item = brain.get_remembered_item(life, item['uid']) if _known_item['score']: if lfe.can_wear_item(life, item['uid']): if _known_item['score'] > _item_to_wear['score']: _item_to_wear['score'] = _known_item['score'] _item_to_wear['item_uid'] = item['uid'] else: if rawparse.raw_has_section(life, 'items') and rawparse.raw_section_has_identifier(life, 'items', item['type']): _action = lfe.execute_raw(life, 'items', item['type']) if item['type'] == 'gun' and lfe.get_all_equipped_items(life, matches=[{'type': 'gun'}]): continue if _action == 'equip': if _known_item['score'] > _item_to_equip['score']: _item_to_equip['score'] = _known_item['score'] _item_to_equip['item_uid'] = item['uid'] _item = None if _item_to_wear['score'] > _item_to_equip['score']: _item = _item_to_wear['item_uid'] elif _item_to_equip['item_uid']: _item = _item_to_equip['item_uid'] if _item: _equip_action = {'action': 'equipitem', 'item': _item} if len(lfe.find_action(life, matches=[_equip_action])): return False lfe.add_action(life, _equip_action, 401, delay=lfe.get_item_access_time(life, _item)) return False return True
def pick_up_item(life, item_uid): _not_moved = travel_to_position(life, ITEMS[item_uid]['pos']) if _not_moved: lfe.add_action(life, { 'action': 'pickupitem_npc', 'item': item_uid }, 200, delay=lfe.get_item_access_time(life, item_uid))
def manage_hands(life): for item in [lfe.get_inventory_item(life, item) for item in lfe.get_held_items(life)]: judgement.judge_item(life, item['uid']) _known_item = brain.get_remembered_item(life, item['uid']) for weapon in combat.get_equipped_weapons(life): if item['type'] == ITEMS[weapon]['feed'] and len(item['rounds'])>=5: combat.load_feed(life, weapon, item['uid']) return True if _known_item['score']:#judgement.get_score_of_highest_scoring_item(life): continue _equip_action = {'action': 'equipitem', 'item': item['uid']} if len(lfe.find_action(life, matches=[_equip_action])): return True if lfe.can_wear_item(life, item['uid']): lfe.add_action(life, _equip_action, 401, delay=lfe.get_item_access_time(life, item['uid'])) return True _storage = lfe.can_put_item_in_storage(life, item['uid']) if not 'CAN_WEAR' in item['flags'] and _storage: _store_action = {'action': 'storeitem', 'item': item['uid'], 'container': _storage} if len(lfe.find_action(life, matches=[_store_action])): continue lfe.add_action(life,_store_action, 401, delay=lfe.get_item_access_time(life, item['uid'])) return True return False
def manage_inventory(life): if manage_hands(life): return False for weapon_uid in combat.get_equipped_weapons(life): if not combat.weapon_is_working(life, weapon_uid): if combat.weapon_is_in_preferred_working_condition(life, weapon_uid): combat.reload_weapon(life, weapon_uid) return True _item_to_wear = {"score": 0, "item_uid": None} _item_to_equip = {"score": 0, "item_uid": None} for item in [lfe.get_inventory_item(life, item) for item in lfe.get_all_unequipped_items(life)]: judgement.judge_item(life, item["uid"]) _known_item = brain.get_remembered_item(life, item["uid"]) if _known_item["score"]: if lfe.can_wear_item(life, item["uid"]): if _known_item["score"] > _item_to_wear["score"]: _item_to_wear["score"] = _known_item["score"] _item_to_wear["item_uid"] = item["uid"] else: if rawparse.raw_has_section(life, "items") and rawparse.raw_section_has_identifier( life, "items", item["type"] ): _action = lfe.execute_raw(life, "items", item["type"]) if _action == "equip": if _known_item["score"] > _item_to_equip["score"]: _item_to_equip["score"] = _known_item["score"] _item_to_equip["item_uid"] = item["uid"] _item = None if _item_to_wear["score"] > _item_to_equip["score"]: _item = _item_to_wear["item_uid"] elif _item_to_equip["item_uid"]: _item = _item_to_equip["item_uid"] if _item: _equip_action = {"action": "equipitem", "item": _item} if len(lfe.find_action(life, matches=[_equip_action])): return False lfe.add_action(life, _equip_action, 401, delay=lfe.get_item_access_time(life, _item)) return True return False
def _create_context_from_phrase(life, phrase): _reactions = [] if phrase['gist'] == 'comply': _reactions.append({'type': 'say','text': 'I give up!', 'communicate': 'surrender'}) if lfe.get_held_items(life, matches=[{'type': 'gun'}]): _reactions.append({'action': 'action', 'text': '<Shoot %s>' % ' '.join(phrase['from']['name'])}) elif phrase['gist'] == 'demand_drop_item': _reactions.append({'type': 'action','text': 'Drop the item.', 'action': {'action': 'dropitem','item': phrase['item']}, 'score': 900, 'delay': lfe.get_item_access_time(life,phrase['item']), 'communicate': 'dropped_demanded_item'}) elif phrase['gist'] == 'dialog': if not phrase['dialog_id'] in LIFE[SETTINGS['controlling']]['dialogs']: life['dialogs'].append(phrase['dialog_id']) if dialog.get_last_message(phrase['dialog_id'])['text']: logic.show_event(dialog.get_last_message(phrase['dialog_id'])['text'], life=phrase['from']) if dialog.is_turn_to_talk(LIFE[SETTINGS['controlling']], phrase['dialog_id']): dialog.process(LIFE[SETTINGS['controlling']], phrase['dialog_id']) elif phrase['gist'] == 'looks_hostile': #encounters.create_encounter(life, phrase['from']) #logic.show_event( alife.speech.start_dialog(phrase['from'], life['id'], 'encounter') #else: # logging.warning('Unhandled player context: %s' % phrase['gist']) return _reactions
def manage_inventory(life): if manage_hands(life): return False for weapon_uid in combat.get_equipped_weapons(life): if not combat.weapon_is_working(life, weapon_uid): if combat.weapon_is_in_preferred_working_condition( life, weapon_uid): if not len( lfe.find_action(life, matches=[{ 'action': 'refillammo' }])): combat.reload_weapon(life, weapon_uid) return True _item_to_wear = {'score': 0, 'item_uid': None} _item_to_equip = {'score': 0, 'item_uid': None} for item in [ lfe.get_inventory_item(life, item) for item in lfe.get_all_unequipped_items(life) ]: judgement.judge_item(life, item['uid']) _known_item = brain.get_remembered_item(life, item['uid']) if _known_item['score']: if lfe.can_wear_item(life, item['uid']): if _known_item['score'] > _item_to_wear['score']: _item_to_wear['score'] = _known_item['score'] _item_to_wear['item_uid'] = item['uid'] else: if rawparse.raw_has_section( life, 'items') and rawparse.raw_section_has_identifier( life, 'items', item['type']): _action = lfe.execute_raw(life, 'items', item['type']) if item['type'] == 'gun' and lfe.get_all_equipped_items( life, matches=[{ 'type': 'gun' }]): continue if _action == 'equip': if _known_item['score'] > _item_to_equip['score']: _item_to_equip['score'] = _known_item['score'] _item_to_equip['item_uid'] = item['uid'] _item = None if _item_to_wear['score'] > _item_to_equip['score']: _item = _item_to_wear['item_uid'] elif _item_to_equip['item_uid']: _item = _item_to_equip['item_uid'] if _item: _equip_action = {'action': 'equipitem', 'item': _item} if len(lfe.find_action(life, matches=[_equip_action])): return False lfe.add_action(life, _equip_action, 401, delay=lfe.get_item_access_time(life, _item)) return False return True