Actor.pm
上传用户:market2
上传日期:2018-11-18
资源大小:18786k
文件大小:10k
- #########################################################################
- # OpenKore - Base class for all actor objects
- # Copyright (c) 2005 OpenKore Team
- #
- # This software is open source, licensed under the GNU General Public
- # License, version 2.
- # Basically, this means that you're allowed to modify and distribute
- # this software. However, if you distribute modified versions, you MUST
- # also distribute the source code.
- # See http://www.gnu.org/licenses/gpl.html for the full license.
- #
- # $Revision: 6776 $
- # $Id: Actor.pm 6776 2009-07-19 15:22:22Z eternalharvest $
- #
- #########################################################################
- ##
- # MODULE DESCRIPTION: Base class for all actor objects
- #
- # The Actor class is a base class for all actor objects.
- # An actor object is a monster or player (all members of %monsters and
- # %players). Do not create an object of this class; use one of the
- # subclasses instead.
- #
- # An actor object is also a hash.
- #
- # Child classes: @MODULE(Actor::Monster), @MODULE(Actor::Player), @MODULE(Actor::You),
- # @MODULE(Actor::Item), @MODULE(Actor::Pet), @MODULE(Actor::Party), @MODULE(Actor::NPC),
- # @MODULE(Actor::Portal)
- package Actor;
- use strict;
- use Carp::Assert;
- use Scalar::Util;
- use Data::Dumper;
- use Storable;
- use Globals;
- use Utils;
- use Utils::CallbackList;
- use Log qw(message error debug);
- use Misc;
- # Make it so that
- # print $actor;
- # acts the same as
- # print $actor->nameString;
- use overload '""' => &_nameString;
- # The eq operator checks whether two variables refer to compatible objects.
- use overload 'eq' => &_eq;
- use overload 'ne' => &_ne;
- # The == operator is to check whether two variables refer to the
- # exact same object.
- use overload '==' => &_isis;
- use overload '!=' => &_not_is;
- sub _eq {
- return UNIVERSAL::isa($_[0], "Actor")
- && UNIVERSAL::isa($_[1], "Actor")
- && $_[0]->{ID} eq $_[1]->{ID};
- }
- sub _ne {
- return !&_eq;
- }
- # This function is needed to make the operator overload respect inheritance.
- sub _nameString {
- my $self = shift;
- return $self->nameString(@_);
- }
- sub _isis {
- return Scalar::Util::refaddr($_[0]) == Scalar::Util::refaddr($_[1]);
- }
- sub _not_is {
- return !&_isis;
- }
- ### CATEGORY: Class methods
- # protected Actor->new(String actorType)
- # actorType: A type name for this actor, like 'Player', 'Monster', etc.
- # Requires: defined($actorType)
- #
- # A default abstract constructor that subclasses should call. Must not
- # be directly used.
- sub new {
- my ($class, $actorType) = @_;
- my %self = (
- actorType => $actorType,
- onNameChange => new CallbackList('onNameChange'),
- onUpdate => new CallbackList('onUpdate')
- );
- return bless %self, $class;
- }
- ##
- # Actor Actor::get(Bytes ID)
- # ID: an actor ID, in binary format.
- # Returns: the associated Actor object, or a new Actor::Unknown object if not found.
- # Requires: defined($ID)
- # Ensures: defined(result)
- #
- # Returns the Actor object for $ID. This function will look at the various
- # actor lists. If $ID is not in any of the actor lists, it will return
- # a new Actor::Unknown object.
- sub get {
- my ($ID) = @_;
- assert(defined $ID) if DEBUG;
- if ($ID eq $accountID || $ID eq "