コード例 #1
0
 def __init__(self, what="", range=30):
     Goal.__init__(self,
                   desc="Fight something.",
                   sub_goals=[
                       Condition(condition_fn=self.has_enemy_in_range,
                                 goals_true=[
                                     Condition(
                                         condition_fn=self.should_use_melee,
                                         goals_true=[
                                             self.equip_melee_weapon,
                                             self.equip_shield,
                                             self.attack_melee,
                                             MoveMe(location=self.get_enemy,
                                                    radius=0,
                                                    speed=0.5)
                                         ],
                                         goals_false=[
                                             self.equip_ranged_weapon,
                                             self.stop_moving,
                                             self.attack_ranged,
                                         ])
                                 ],
                                 goals_false=[self.stop_attack_task])
                   ])
     self.what = what
     self.filter = entity_filter.Filter(what)
     self.range = range
     self.square_range = range * range
     self.vars = ["what", "range"]
     self.weapon_usage = None
     self.use_ranged = False
     self.closest_enemy = None
     self.distance_to_enemy = None
コード例 #2
0
 def stop_usage(self, args):
     # Check that the usage still is valid
     (valid, _) = self.usage.is_valid()
     self.irrelevant()
     res = Oplist()
     if valid and self.fish_on_hook:
         worms = self.usage.actor.find_in_contains(
             entity_filter.Filter("entity instance_of types.annelid"))
         if len(worms):
             fish_type = self.fishes[randint(0, len(self.fishes) - 1)]
             res.append(
                 Operation("create",
                           Entity(parent=fish_type,
                                  loc=self.usage.actor.id,
                                  mind=None),
                           to=self.usage.tool))
             # Delete the worm
             res.append(
                 Operation("delete", Entity(id=worms[0].id),
                           to=worms[0].id))
             res.append(
                 Operation(
                     "imaginary",
                     Entity(
                         description="You caught a {}.".format(fish_type)),
                     to=self.usage.actor.id,
                     from_=self.usage.actor.id))
     return server.OPERATION_HANDLED, res
コード例 #3
0
    def __init__(self,
                 what="",
                 range=30,
                 condition=lambda a: 1,
                 seconds_until_forgotten=30):
        Goal.__init__(self,
                      desc="spot a thing",
                      fulfilled=self.do_i_have,
                      sub_goals=[self.do])
        if isinstance(what, str):
            self.what = what
        else:
            self.what = str(what)

        self.filter = entity_filter.Filter(what)

        self.range = range
        self.condition = condition
        # Keep track of when we've spotted things, so that we can ignore them
        # seconds_until_forgotten is used to forget about spotted things. That way we can re-discover things
        # we've previously focused on after a while.
        self.spotted = {}
        # How many seconds until we've forgotten something we've previously focused on.
        self.seconds_until_forgotten = seconds_until_forgotten
        self.vars = ["what", "range", "seconds_until_forgotten"]
コード例 #4
0
ファイル: combat.py プロジェクト: zkactivity-dev/cyphesis
 def __init__(self, what="", range=30):
     Goal.__init__(
         self,
         "fight something",
         self.none_in_range,
         [
             SpotSomething(what=what, range=range),
             Condition(self.should_use_melee, [
                 self.equip_melee_weapon, self.equip_shield,
                 self.attack_melee,
                 MoveMeToFocus(what=what, radius=0, speed=0.5)
             ], [
                 self.equip_ranged_weapon,
                 self.stop_moving,
                 self.attack_ranged,
             ])
             #                       hunt_for(what=what, range=range, proximity=3),
         ])
     self.what = what
     self.filter = entity_filter.Filter(what)
     self.range = range
     self.square_range = range * range
     self.vars = ["what", "range"]
     self.weapon_usage = None
     self.use_ranged = False
コード例 #5
0
ファイル: mason.py プロジェクト: MasterMann/cyphesis
 def __init__(self, message="", what=""):
     DynamicGoal.__init__(self,
                          trigger="sight_create",
                          desc="welcome new players")
     self.what = what
     self.message = message
     self.filter = entity_filter.Filter(self.what)
コード例 #6
0
ファイル: NPCMind.py プロジェクト: digimax20/cyphesis
    def relations_updated(self, entity):
        print('Relations updated.')
        self.relation_rules.clear()
        if entity.has_prop_list('_relations'):
            relations = entity.get_prop_list('_relations')
            for relation_element in relations:
                rule = {}
                if "filter" in relation_element:
                    rule["filter"] = entity_filter.Filter(
                        relation_element.filter)
                if "disposition" in relation_element:
                    rule["disposition"] = relation_element.disposition
                else:
                    rule["disposition"] = 0

                if "threat" in relation_element:
                    rule["threat"] = relation_element.threat
                else:
                    rule["threat"] = 0

                self.relation_rules.append(rule)

            # update relations for existing entities
            for (_, entity) in self.entities.items():
                self.update_relation_for_entity(entity)
コード例 #7
0
 def __init__(self, what, range):
     Goal.__init__(self, "defend against something",
                   self.none_in_sight,
                   [spot_something(what),
                    hunt_for(what, range),
                    self.fight])
     self.what = what
     self.filter = entity_filter.Filter(what)
     self.range = range
     self.vars = ["what", "range"]
コード例 #8
0
 def __init__(self, what):
     Goal.__init__(
         self, "gather a thing", self.is_there_none_around,
         [spot_something(what), pick_up_focus(what)])
     if isinstance(what, str):
         self.what = what
     else:
         self.what = str(what)
     # FIXME: This goal shares the same filter as spot_something
     self.filter = entity_filter.Filter(self.what)
     self.vars = ["what"]
コード例 #9
0
ファイル: misc_goal.py プロジェクト: worldforge/cyphesis
 def __init__(self, weapon, what, range):
     Goal.__init__(self, "hunt something",
                   self.none_in_range,
                   [SpotSomething(what, range),
                    AcquireThing(weapon),
                    HuntFor(what, range, 7),
                    self.fight])
     self.weapon = weapon
     self.what = what
     self.filter = entity_filter.Filter(what)
     self.range = range
     self.vars = ["weapon", "what", "range"]
コード例 #10
0
 def __init__(self, weapon, what, range):
     Goal.__init__(self, "hunt something", self.none_in_range, [
         spot_something(what, range),
         acquire_thing(weapon),
         hunt_for(what, range, 7), self.fight
     ])
     self.weapon = weapon
     self.what = what
     self.filter = entity_filter.Filter(what)
     self.range = range
     self.square_range = range * range
     self.vars = ["weapon", "what", "range"]
コード例 #11
0
 def __init__(self, what, max_amount=1, distance=30):
     Goal.__init__(
         self, "gather a thing", self.is_there_none_around,
         [SpotSomething(what), PickUpFocus(what)])
     if isinstance(what, str):
         self.what = what
     else:
         self.what = str(what)
     # FIXME: This goal shares the same filter as spot_something
     self.filter = entity_filter.Filter(self.what)
     self.max_amount = max_amount
     self.distance = distance
     self.vars = ["what", "max_amount", "distance"]
コード例 #12
0
    def __init__(self, desc="pursue something", what="", range=0, direction=1):
        Goal.__init__(self, desc, self.not_visible, [self.run])

        if isinstance(what, str):
            self.what = what
        elif isinstance(what, list) and len(what) > 0:
            # Try to use the first element as a query.
            # Queries should never really be passed as a list
            self.what = str(what[0])
        else:
            self.what = str(what)
        self.filter = entity_filter.Filter(self.what)
        self.range = range
        self.direction = direction
        self.vars = ["what", "range", "direction"]
コード例 #13
0
ファイル: combat.py プロジェクト: AreebDurrani/cyphesis
 def __init__(self, what="", range=30):
     Goal.__init__(
         self,
         "fight something",
         self.none_in_range,
         [
             spot_something(what=what, range=range),
             self.equip_weapon,
             self.attack,
             move_me_to_focus(what=what, radius=0, speed=0.5),
             #                       hunt_for(what=what, range=range, proximity=3),
         ])
     self.what = what
     self.filter = entity_filter.Filter(what)
     self.range = range
     self.square_range = range * range
     self.vars = ["what", "range"]
コード例 #14
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.temporaries["inputs"] = []
        self.temporaries["outputs"] = []

        inputs_list = self.usage.tool.get_prop_list("craft_input")

        if inputs_list:
            for input_def in inputs_list:
                amount = 1
                if "amount" in input_def:
                    amount = input_def["amount"]
                criteria = entity_filter.Filter(input_def["criteria"])
                input_def = {"criteria": criteria, "amount": amount}
                self.temporaries["inputs"].append(input_def)

        self.temporaries["outputs"] = self.usage.tool.get_prop_list("craft_output")
コード例 #15
0
 def __init__(self, seed, source, place, tool, range=30, spacing=4):
     Goal.__init__(self, "Plant seed to grow plants",
                   false,
                   [AcquireThing(tool),
                    MoveMeArea(place, range=range),
                    SpotSomethingInArea(seed, place, range=range, seconds_until_forgotten=360),
                    MoveMeToFocus(seed),
                    self.do,
                    SpotSomethingInArea(source, place, range=range),
                    MoveMeNearFocus(source, allowed_movement_radius=5),
                    ClearFocus(source)])
     self.seed = seed
     self.source = source
     self.source_filter = entity_filter.Filter(source)
     self.place = place
     self.tool = tool
     self.range = range
     self.spacing = spacing
     self.vars = ["seed", "source", "place", "tool", "range", "spacing"]
コード例 #16
0
 def __init__(self, seed, source, place, tool, range=30, spacing=4):
     Goal.__init__(self, "Plant seed to grow plants", false, [
         acquire_thing(tool),
         move_me_area(place, range=range),
         spot_something_in_area(
             seed, place, range=range, seconds_until_forgotten=360),
         move_me_to_focus(seed), self.do,
         spot_something_in_area(source, place, range=range),
         move_me_near_focus(source, allowed_movement_radius=5),
         clear_focus(source)
     ])
     self.seed = seed
     self.source = source
     self.source_filter = entity_filter.Filter(source)
     self.place = place
     self.tool = tool
     self.range = range
     self.spacing = spacing
     self.vars = ["seed", "source", "place", "tool", "range", "spacing"]
コード例 #17
0
# This file is distributed under the terms of the GNU General Public license.
# Copyright (C) 2019 Erik Ogenvik (See the file COPYING for details).

import entity_filter
import server
from atlas import Operation, Entity, Oplist
from physics import Vector3D, Quaternion

from world.StoppableTask import StoppableTask
from world.utils import Usage

arrow_filter = entity_filter.Filter("entity instance_of types.arrow")


def shoot_in_direction(direction, instance, res):
    Usage.set_cooldown_on_attached(instance.tool, instance.actor)

    arrows = instance.actor.find_in_contains(arrow_filter)
    if len(arrows):
        direction.normalize()

        # Adjust the start position of the arrow, so it's outside of the actor, at mid height
        start_adjust = Vector3D(direction)
        start_adjust.y = 0
        start_adjust.normalize()
        start_adjust.y = instance.actor.location.bbox.high_corner.y * 0.8

        new_loc = instance.actor.location.copy()
        new_loc.pos += start_adjust

        new_loc.orientation = Quaternion(Vector3D(0, 0, 1), direction, Vector3D(1, 0, 0))
コード例 #18
0
 def __init__(self, what):
     Goal.__init__(self, "move this thing from my inventory and disown",
                   self.is_it_not_with_me, [self.drop_it])
     self.what = what
     self.what_filter = entity_filter.Filter(what)
コード例 #19
0
 def create_criteria(self):
     criteria_string = self.get_prop_string("__spawner_criteria")
     if criteria_string:
         self.criteria = entity_filter.Filter(criteria_string)
コード例 #20
0
ファイル: Bloomery.py プロジェクト: worldforge/cyphesis
import entity_filter
import server
from atlas import Operation, Entity, Oplist

from world.StoppableTask import StoppableTask

# Allow both charcoal and lumber to feed the fire. Charcoal is preferable since it weights less
# (in the future we could also only allow charcoal, on the basis that it allows higher temperatures).
charcoal_filter = entity_filter.Filter(
    "entity instance_of types.charcoal or entity instance_of types.lumber")
ores = {
    "iron_ingot": entity_filter.Filter("entity instance_of types.hematite"),
    "copper_ingot": entity_filter.Filter("entity instance_of types.copper_ore")
}


def craft(instance):
    task = Smelt(instance, duration=5, tick_interval=1, name="Smelting")

    instance.actor.send_world(Operation("sight", instance.op))

    return server.OPERATION_BLOCKED, instance.actor.start_task("smelt", task)


class Smelt(StoppableTask):
    """ Smelting iron from iron ore """
    def setup(self, task_id):
        # TODO: match with animation in client
        self.start_action("smelting")

    def tick(self):
コード例 #21
0
 def __init__(self, message: string, what: string, distance=10):
     Goal.__init__(self, desc="welcome new players")
     self.what = what
     self.message = message
     self.filter = entity_filter.Filter(self.what)
     self.distance = distance
コード例 #22
0
import entity_filter
import server
from atlas import Operation, Entity, Oplist

from world.StoppableTask import StoppableTask

#Allow both charcoal and lumber to feed the fire. Charcoal is preferable since it weights less (in the future we could also only allow charcoal, on the basis that it allows higher temperatures).
charcoal_filter = entity_filter.Filter("entity instance_of types.charcoal or entity instance_of types.lumber")
hematite_filter = entity_filter.Filter("entity instance_of types.hematite")


def craft(instance):
    task = Smelt(instance, duration=5, tick_interval=1, name="Smelting")

    instance.actor.send_world(Operation("sight", instance.op))

    return server.OPERATION_BLOCKED, instance.actor.start_task("smelt", task)


class Smelt(StoppableTask):
    """ Smelting iron from iron ore """

    def setup(self, task_id):
        """ Setup code, could do something """
        pass

    def tick(self):
        (valid, err) = self.usage.is_valid()
        if not valid:
            return self.irrelevant(err)